模板:
from datetime import datetime
from django.http import HttpResponse
from django.db import IntegrityError
from django.db.models import Min
from testing.models import (
BugsPostTesting,
BugsPreTesting,
BugsScript,
ResultOptions,
ResultsStbs,
ResultsTests,
)
from testing.views import calculate_health_score
def save_shelf(request):
"""Saves the general result information for each shelf"""
if request.is_ajax:
results_stb_id = int(request.POST.get('test_id'))
shelf_no = int(request.POST.get('shelf_no'))
connection = int(request.POST.get('connection'))
if request.POST.get('test_case') != '':
test_case = int(request.POST.get('test_case'))
else:
test_case = None
pre_planner = request.POST.get('pre_planner')
pre_details = request.POST.get('pre_details')
pre_affirm = request.POST.get('pre_affirm')
pre_parser = request.POST.get('pre_parser')
pre_log = request.POST.get('pre_log')
pre_campaigns = request.POST.get('pre_campaigns')
pre_assets = request.POST.get('pre_assets')
pre_total_assets = request.POST.get('pre_total_assets')
time_of_failure = request.POST.get('time_of_failure')
script_details = request.POST.get('script_details')
post_planner = request.POST.get('post_planner')
post_details = request.POST.get('post_details')
uptime_days = request.POST.get('uptime_days')
uptime_hours = request.POST.get('uptime_hours')
uptime_mins = request.POST.get('uptime_mins')
post_affirm = request.POST.get('post_affirm')
post_parser = request.POST.get('post_parser')
post_log = request.POST.get('post_log')
post_log_one = request.POST.get('post_log_one')
post_campaigns = request.POST.get('post_campaigns')
post_assets = request.POST.get('post_assets')
post_total_assets = request.POST.get('post_total_assets')
pre_result = int(request.POST.get('pre_result'))
script_result = int(request.POST.get('script_result'))
post_result = int(request.POST.get('post_result'))
shelf_record = ResultsStbs.objects.select_related(
'pre_testing_result',
'script_result',
'post_result',
).get(
results_test_id=results_stb_id,
shelf_no=shelf_no,
)
if pre_planner:
shelf_record.pre_planner_percentage = int(pre_planner)
else:
shelf_record.pre_planner_percentage = None
if time_of_failure:
shelf_record.script_time_of_failure = time_of_failure
else:
shelf_record.script_time_of_failure = None
if post_planner:
shelf_record.post_planner_percentage = int(post_planner)
else:
shelf_record.post_planner_percentage = None
if uptime_days:
shelf_record.system_days = uptime_days
else:
shelf_record.system_days = None
if uptime_hours:
shelf_record.system_hours = uptime_hours
else:
shelf_record.system_hours = None
if uptime_mins:
shelf_record.system_mins = uptime_mins
else:
shelf_record.system_mins = None
# AdSmart
if pre_campaigns:
shelf_record.pre_ads_campaigns = int(pre_campaigns)
else:
shelf_record.pre_ads_campaigns = None
if pre_assets:
shelf_record.pre_ads_assets = int(pre_assets)
else:
shelf_record.pre_ads_assets = None
if pre_total_assets:
shelf_record.pre_ads_total_assets = int(pre_total_assets)
else:
shelf_record.pre_ads_total_assets = None
if post_campaigns:
shelf_record.ads_campaigns = int(post_campaigns)
else:
shelf_record.ads_campaigns = None
if post_assets:
shelf_record.ads_assets = int(post_assets)
else:
shelf_record.ads_assets = None
if post_total_assets:
shelf_record.ads_total_assets = int(post_total_assets)
else:
shelf_record.ads_total_assets = None
results_stb_id = shelf_record.results_stb_id
shelf_record.network_connection_id = connection
shelf_record.tr_test_case_id = test_case
shelf_record.pre_testing = pre_details
shelf_record.pre_affirm = pre_affirm
shelf_record.pre_parser_output = pre_parser
shelf_record.pre_log_url = pre_log
shelf_record.script = script_details
shelf_record.post_testing = post_details
shelf_record.affirm = post_affirm
shelf_record.parser_output = post_parser
shelf_record.log_url = post_log
shelf_record.log_url_one = post_log_one
pre_option = ResultOptions.objects.get(result_option_id=pre_result)
script_option = ResultOptions.objects.get(
result_option_id=script_result
)
post_option = ResultOptions.objects.get(result_option_id=post_result)
shelf_record.pre_testing_result = pre_option
shelf_record.script_result = script_option
shelf_record.post_result = post_option
try:
shelf_record.save()
try:
results_test_id = shelf_record.results_test_id
calculate_health_score(results_test_id, results_stb_id)
except IntegrityError as e:
message = e.__cause__
message = 'Saved.'
except IntegrityError as e:
message = e.__cause__
else:
message = 'No request recieved.'
return HttpResponse(message)
shareeditdeleteflag
型号:
function saveShelf(shelfNo){
// Saves the information for each shelf.
var releaseName = '{{ test_details.test_release_name }}';
// Set element IDs
var connectionId='network_connection_'+shelfNo;
var testCaseId='test_case_'+shelfNo;
var prePlannerId='pre_planner_'+shelfNo;
var preDetailsId='pre_details_'+shelfNo;
var preAffirmId='pre_affirm_'+shelfNo;
var preParserId='pre_parser_output_'+shelfNo;
var preLogId='pre_log_url_'+shelfNo;
var scriptDetailsId='script_details_'+shelfNo;
var timeOfFailureId='time_of_failure_'+shelfNo;
var postPlannerId='post_planner_'+shelfNo;
var postDetailsId='post_details_'+shelfNo;
var uptimeDaysId='uptime_days_'+shelfNo;
var uptimeHoursId='uptime_hours_'+shelfNo;
var uptimeMinsId='uptime_mins_'+shelfNo;
var postAffirmId='post_affirm_'+shelfNo;
var postParserId='post_parser_output_'+shelfNo;
var postLogId='post_log_url_'+shelfNo;
var postLogOneId='post_log_url_one_'+shelfNo;
var preResultName='pre_result_'+shelfNo;
var scriptResultName='script_result_'+shelfNo;
var postResultName='post_result_'+shelfNo;
// Shelf results
var preResult=radioCheck(preResultName);
var scriptResult=radioCheck(scriptResultName);
var postResult=radioCheck(postResultName);
// Retrieve values to be saved
var connection=document.getElementById(connectionId).value;
var testCase=document.getElementById(testCaseId).value;
var preDetails=document.getElementById(preDetailsId).value;
var scriptDetails=document.getElementById(scriptDetailsId).value;
var timeOfFailure=document.getElementById(timeOfFailureId).value;
var postDetails=document.getElementById(postDetailsId).value;
var uptimeDays=document.getElementById(uptimeDaysId).value;
var uptimeHours=document.getElementById(uptimeHoursId).value;
var uptimeMins=document.getElementById(uptimeMinsId).value;
if (releaseName != 'Now TV') {
var prePlanner=document.getElementById(prePlannerId).value;
var preAffirm=document.getElementById(preAffirmId).value;
var preParser=document.getElementById(preParserId).value;
var preLog=document.getElementById(preLogId).value;
var postPlanner=document.getElementById(postPlannerId).value;
var postAffirm=document.getElementById(postAffirmId).value;
var postParser=document.getElementById(postParserId).value;
var postLog=document.getElementById(postLogId).value;
var postLogOne=document.getElementById(postLogOneId).value;
}
else {
var prePlanner='';
var preAffirm='';
var preParser='';
var preLog='';
var postPlanner='';
var postAffirm='';
var postParser='';
var postLog='';
var postLogOne='';
}
// AdSmart values
var adsmart={{ test_details.adsmart }}
var preCampaigns="";
var preAssets="";
var preTotalAssets="";
var postCampaigns="";
var postAssets="";
var postTotalAssets="";
if (adsmart==1) {
var preCampaignsId='pre_campaigns_'+shelfNo;
var preCampaigns=document.getElementById(preCampaignsId).value;
var preAssetsId='pre_assets_'+shelfNo;
var preAssets=document.getElementById(preAssetsId).value;
var preTotalAssetsId='pre_total_assets_'+shelfNo;
var preTotalAssets=document.getElementById(preTotalAssetsId).value;
var postCampaignsId='post_campaigns_'+shelfNo;
var postCampaigns=document.getElementById(postCampaignsId).value;
var postAssetsId='post_assets_'+shelfNo;
var postAssets=document.getElementById(postAssetsId).value;
var postTotalAssetsId='post_total_assets_'+shelfNo;
var postTotalAssets=document.getElementById(postTotalAssetsId).value;
}
var postUrl = "{% url 'testing:save_shelf' %}";
var testId = "{{ test_details.pk }}";
var notificationId = 'notification_shelf_' + shelfNo;
var notification = document.getElementById(notificationId);
notification.innerHTML = 'Saving...';
$.ajax( {
url: postUrl,
type: "POST",
data: {'test_id':testId,
'shelf_no':shelfNo,
'connection':connection,
'test_case':testCase,
'pre_result':preResult,
'pre_planner':prePlanner,
'pre_details':preDetails,
'pre_affirm':preAffirm,
'pre_parser':preParser,
'pre_log':preLog,
'pre_campaigns':preCampaigns,
'pre_assets':preAssets,
'pre_total_assets':preTotalAssets,
'script_result':scriptResult,
'script_details':scriptDetails,
'time_of_failure':timeOfFailure,
'post_result':postResult,
'post_planner':postPlanner,
'post_details':postDetails,
'uptime_days':uptimeDays,
'uptime_hours':uptimeHours,
'uptime_mins':uptimeMins,
'post_affirm':postAffirm,
'post_parser':postParser,
'post_log':postLog,
'post_log_one':postLogOne,
'post_campaigns':postCampaigns,
'post_assets':postAssets,
'post_total_assets':postTotalAssets,
},
error:function (xhr, textStatus, thrownError){
alert(thrownError);},
success:function ( returnedData, textStatus, jqXHR ){
notification.innerHTML = returnedData;
},
complete: function(data) {
window.setTimeout(function() { notification.innerHTML = ' '; }, 3000);
zeroSymptomCheck(testId, shelfNo);
defectInformation();
},
})
}
的js
{{1}}
我运行一个脚本来获取设备使用百分比。我正在将此数据写入mysql db。我们有一个django门户网站从那里读取数据。
输入保存(1-100)的所有数据。当百分比为0时,它不会保存。当我刷新页面时,它会留空。有什么建议 ?感谢