def ownerUpdate_ajax(request, pid): """ Handles the ajax request to update the case owner """ owner = request.GET.get('owner') recursion = {'true':True,'false':False}[str(request.GET.get('recursion'))] try: c = Case.objects.get(id=pid) old_owner = c.owner c.owner = owner c.save() # Update all of the planned executions as well if specified on the form if recursion: testplan = Planned_Exec.active.filter(case=c) for test in testplan: test.owner = c.owner test.save() # Log the changes if owner != old_owner: utils_protocol.logProtocol(request.user, c.protocol, "COC", case_name=c.name, owner=owner, old_owner=old_owner) # Reply back with the link to the protocol owner msg = convert_gnumber_link(c.owner) except: msg = "Failure" return HttpResponse(msg)
def updateActivityLog(self): utils_protocol.logProtocol("Parseus", Protocol.objects.get(id=self.logData.plannedExec.protocol_id), "TLS", # Test Log Successfully Parsed protocol_name=self.logData.protocolName, case=self.logData.caseName, test=self.logData.testName, pg=self.logData.implantable, release=self.logData.external, browser=self.logData.dbBrows, testplan_id=self.logData.plannedExec.id)
def deletePlannedExecution(request, pe): # Log the deletion logProtocol(request.user, pe.case.protocol, LOG_MSG_TYPES[26][0], case=pe.case, region=pe.plm.geography, pg_model=pe.plm.pg_model, comm_model=pe.plm.comm_model, browser=pe.get_browser_display()) pe.delete()
def endDatePlannedExecution(request, pe): pe.enddater = request.user.username pe.end_date = datetime.datetime.now() pe.save() # Log the deactivation logProtocol(request.user, pe.case.protocol, LOG_MSG_TYPES[27][0], case=pe.case, region=pe.plm.geography, pg_model=pe.plm.pg_model, comm_model=pe.plm.comm_model, browser=pe.get_browser_display())
def save(self, request=None): """ Custom save method to check if we are end_dating, to enddate any CommandLineArgs table as well (Planned_Exec is OneToOne with CommandLineArgs). We also end date any Issues assocated with it. """ # Determine if model has just been end dated try: orig = Planned_Exec.objects.get(id=self.id) enddated = (not orig.end_date) and self.end_date is not None except: enddated = False super(Planned_Exec, self).save() if enddated: # Create Protocol Activity Log entry if request: log = logProtocol(request.user, self.protocol, 'PDD', case=self.case, region= self.plm.geography, pg_model=self.plm.pg_model, comm_model=self.plm.comm_model, browser=self.get_browser_display()) log.save() # End date command line args cla = CommandLineArgs.objects.filter(planned_exec=self) if cla: for c in cla: c.end_date = self.end_date c.enddater = self.enddater c.save() # End date any issues from assets.models import Issue issues = Issue.active.filter(testlog__testplan=self) for issue in issues: issue.end_date = self.end_date issue.enddater = self.enddater issue.save()
def updateCaseDetail_ajax(request): """ Given a field that has been changed for a case option via ajax, set it and return status. """ respDict = {'error':False} cid = request.POST.get('cid') try: thisCase = Case.objects.get(id=cid) except: respDict['error'] = True return HttpResponse("Error setting parameter", status=500) # Get the id of the field that was changed (only one can be changed at a time field_id = request.POST.get('id') value = request.POST.get('value') # Get the (*) part of id_* from the edited field field_name = field_id.split('id_')[1] if str(field_name) == "auto_state": if value != thisCase.auto_state: thisCase.auto_state = value thisCase.save() utils_protocol.logProtocol(request.user, thisCase.protocol, LOG_MSG_TYPES[16][0], case_name=thisCase.name, auto_state=thisCase.get_auto_state_display()) return HttpResponse(thisCase.get_auto_state_display()) elif str(field_name) == "prebaselined": true = True false = False options = {true: 'True', false: 'False'} old_state = request.POST.get('state', None) msg = options[eval(value)] respDict['pb'] = options[thisCase.prebaselined] respDict['state'] = old_state respDict['msg'] = '' try: old = eval(value) if old != thisCase.prebaselined: thisCase.prebaselined = old thisCase.save() respDict['pb'] = options[old] respDict['state'] = Case.objects.get(id=cid).get_auto_state_display() except Exception as e: respDict['msg'] = "Failure: %s" % e.args[0] respDict['error'] = True return JSONHttpResponse(respDict) elif str(field_name) == "exec_type": if value != thisCase.exec_type: thisCase.exec_type = value if setupFlagIfAllRequiredParamsAreSet(thisCase): thisCase.setup = True thisCase.save() utils_protocol.logProtocol(request.user, thisCase.protocol, LOG_MSG_TYPES[15][0], case_name=thisCase.name, exec_type=thisCase.get_exec_type_display()) return HttpResponse(thisCase.get_exec_type_display()) elif str(field_name) == "comm_connect_type": if value != thisCase.comm_connect_type: thisCase.comm_connect_type = value thisCase.save() utils_protocol.logProtocol(request.user, thisCase.protocol, LOG_MSG_TYPES[22][0], case_name=thisCase.name, comm_connect_type=thisCase.get_comm_connect_type_display()) return HttpResponse(thisCase.get_comm_connect_type_display()) elif str(field_name) == "comm_mode": if value != thisCase.comm_mode: thisCase.comm_mode = value thisCase.save() utils_protocol.logProtocol(request.user, thisCase.protocol, LOG_MSG_TYPES[30][0], case_name=thisCase.name, comm_mode=thisCase.get_comm_mode_display()) return HttpResponse(thisCase.get_comm_mode_display()) elif str(field_name) == "pg_type": if value != thisCase.pg_type: thisCase.pg_type = value if setupFlagIfAllRequiredParamsAreSet(thisCase): thisCase.setup = True thisCase.save() utils_protocol.logProtocol(request.user, thisCase.protocol, LOG_MSG_TYPES[12][0], case_name=thisCase.name, pg_type=thisCase.get_pg_type_display()) # If there are command line options for any already existing planned # executions, make sure to update those as well pes = Planned_Exec.objects.filter(case=thisCase) if pes.exists(): for pe in pes: cla = CommandLineArgs.objects.filter(planned_exec=pe) if cla.exists(): for c in cla: if thisCase.pg_type == "SI": c.komodo_pgsim = True else: c.komodo_pgsim = False c.save() return HttpResponse(thisCase.get_pg_type_display()) elif str(field_name) == "sensor_type": if value != thisCase.sensor_type: thisCase.sensor_type = value thisCase.save() utils_protocol.logProtocol(request.user, thisCase.protocol, LOG_MSG_TYPES[13][0], case_name=thisCase.name, sensor_type=thisCase.get_sensor_type_display()) return HttpResponse(thisCase.get_sensor_type_display()) elif str(field_name) == "usbrelay_type": if value != thisCase.usbrelay_type: thisCase.usbrelay_type = value thisCase.save() utils_protocol.logProtocol(request.user, thisCase.protocol, LOG_MSG_TYPES[28][0], ################ case_name=thisCase.name, usbrelay_type=thisCase.get_usbrelay_type_display()) return HttpResponse(thisCase.get_usbrelay_type_display()) elif str(field_name) == "comm_cellular_type": if value != thisCase.comm_cellular_type: thisCase.comm_cellular_type = value thisCase.save() utils_protocol.logProtocol(request.user, thisCase.protocol, LOG_MSG_TYPES[29][0], ################### case_name=thisCase.name, comm_cellular_type=thisCase.get_comm_cellular_type_display()) return HttpResponse(thisCase.get_comm_cellular_type_display()) elif str(field_name) == "centricity": if value != thisCase.centricity: thisCase.centricity = value thisCase.save() utils_protocol.logProtocol(request.user, thisCase.protocol, LOG_MSG_TYPES[21][0], case_name=thisCase.name, centricity=thisCase.get_centricity_display()) return HttpResponse(thisCase.get_centricity_display()) elif str(field_name) == "env_type": if value != thisCase.env_type: thisCase.env_type = value if setupFlagIfAllRequiredParamsAreSet(thisCase): thisCase.setup = True thisCase.save() utils_protocol.logProtocol(request.user, thisCase.protocol, LOG_MSG_TYPES[14][0], case_name=thisCase.name, env_type=thisCase.get_env_type_display()) return HttpResponse(thisCase.get_env_type_display()) elif str(field_name) == "auto_owner": if value != thisCase.automation_owner: thisCase.automation_owner = value if setupFlagIfAllRequiredParamsAreSet(thisCase): thisCase.setup = True thisCase.save() utils_protocol.logProtocol(request.user, thisCase.protocol, LOG_MSG_TYPES[24][0], case_name=thisCase.name, auto_owner=thisCase.automation_owner) return HttpResponse(convert_gnumber(thisCase.automation_owner)) # For boolean fields, Use the id_(***) portion of the field id to update the # case value instead of accessing the member directly else: currentValue = str(thisCase.__dict__[field_name]) # Don't hit the database or log this change if the values are the same if value != currentValue: thisCase.__dict__[field_name] = {'True':1,'False':0}[value] thisCase.save() # Log the change to the protocol activity log if str(field_name) == "prm": utils_protocol.logProtocol(request.user, thisCase.protocol, LOG_MSG_TYPES[9][0], case_name=thisCase.name, prm=boolean_convert(value)) elif str(field_name) == "machsim": utils_protocol.logProtocol(request.user, thisCase.protocol, LOG_MSG_TYPES[10][0], case_name=thisCase.name, machsim=boolean_convert(value)) elif str(field_name) == "shield_box": utils_protocol.logProtocol(request.user, thisCase.protocol, LOG_MSG_TYPES[11][0], case_name=thisCase.name, shield_box=boolean_convert(value)) elif str(field_name) == "svmachsim": utils_protocol.logProtocol(request.user, thisCase.protocol, LOG_MSG_TYPES[17][0], case_name=thisCase.name, svmachsim=boolean_convert(value)) elif str(field_name) == "teltone": utils_protocol.logProtocol(request.user, thisCase.protocol, LOG_MSG_TYPES[18][0], case_name=thisCase.name, teltone=boolean_convert(value)) elif str(field_name) == "telephone": utils_protocol.logProtocol(request.user, thisCase.protocol, LOG_MSG_TYPES[19][0], case_name=thisCase.name, telephone=boolean_convert(value)) return HttpResponse(boolean_convert(thisCase.__dict__[field_name]))
def createPlannedExecObject(request, case, plm, country3, country_ignore): """ Create the planned execution from the request, case, and plm chosen """ # Planned Execution Params browser = request.POST.get('browser','') regression = request.POST.get('regression','NA') test_script = request.POST.get('test_script','') regression_enabled = request.POST.get('regression_enabled','off') regression_setup = request.POST.get('regression_setup','on') owner = request.POST.get('owner','') planned_for = request.POST.get('planned_for', '') newTest = Planned_Exec() if not country_ignore: country = Country.objects.get(iso3code=country3) newTest.country = country else: newTest.country = None newTest.case = case newTest.protocol = case.protocol newTest.plm = plm newTest.browser = browser newTest.owner = owner newTest.creator = request.user.username newTest.updater = request.user.username newTest.team = case.protocol.team newTest.release = case.protocol.release newTest.planned_for = ProjectSchedule.objects.get(id=planned_for) if regression_enabled == 'on' and case.exec_type == "FA": newTest.regression = regression if regression_setup == 'on': newTest.regression_setup = True else: newTest.regression_setup = False else: newTest.regression = REGRESSION_OPTIONS[0][0] newTest.test_script = test_script # Command Line Arguments clpfields = {} if request.POST.get('debug'): clpfields['debug'] = 'on' else: clpfields['debug'] = 'off' if request.POST.get('quiet'): clpfields['quiet'] = 'on' else: clpfields['quiet'] = 'off' if request.POST.get('komodo_enroll') == "True": clpfields['komodo_enroll'] = 'True' elif request.POST.get('komodo_enroll') == "False": clpfields['komodo_enroll'] = 'False' if request.POST.get('komodo_pgsim') == "True": clpfields['komodo_pgsim'] = 'True' elif request.POST.get('komodo_pgsim') == "False": clpfields['komodo_pgsim'] = 'False' if request.POST.get('user_params'): clpfields['user_params'] = request.POST.get('user_params') # Save the planned execution newTest.save() # Save the command line args object cla = getOrCreateCommandLineArgsFromPlannedExecution(request.user.username, newTest, clpfields, False) # Update the protocol log if newTest.country: cname = newTest.country.name else: cname = "No Country" try: utils_protocol.logProtocol(request.user, case.protocol, LOG_MSG_TYPES[20][0], case=case, region=plm.geography, pg_model=plm.pg_model, comm_model=plm.comm_model, browser=newTest.get_browser_display(), country=cname) # Could not log it, so delete it and error out except: newTest.delete() raise Exception('Error: The planned execution could not be added to the database. The computer thingy had trouble creating the record of the creation.') return newTest