def populateTestListTable_ajax(request,cid): """ Send back the planned_exec fields for the test list table in the case detail/test list tab Inputs: cid - case_id for the requested case """ try: test_list = Planned_Exec.objects.filter(case=cid).select_related('planned_for','case','plm') except Planned_Exec.DoesNotExist: msg = 'Test List does not exist for this case' except: msg = 'Unknown Error' # Get count of logs for each planned execution logCount = Counter() for log in TestLog.objects.filter(case=cid): logCount[log.testplan_id] += 1 # Get latest testlogs for this case latestLogs = {log.planned_exec_id : log.testlog for log in LatestTestLog.objects.filter(planned_exec__case=cid).select_related('testlog')} release = Case.objects.get(id=cid).protocol.release_id schedule = ProjectSchedule.getProjScheduleDict(release) # dataTables plugin requires only a JSON-formatted list named "aaData" - http://www.datatables.net/examples/data_sources/ajax.html dataTables = {'aaData': [], 'status': False} # Iterate through the test list to supply the rows for test in test_list: # Create the checkbox tlbox = '''<input type="checkbox" name="delete_select_%s" id="id_delete_select" />''' % str(test.id) if test.planned_for: planned_for = test.planned_for.name else: planned_for = "None" # Create the regression options/edit link if fully automated # TODO: This does not reflect the database values if a user has switched from FA to something else after setting regression options. # Originally found in RTC 60655 if test.case.exec_type == 'FA': regression_column = test.get_regression_display() else: regression_column = "N/A" # Handle the deactivated planned executions a little differently if test.end_date: dataTables['aaData'].append([tlbox, regression_column, test.getDataTablesPLMBrowserStr(browser=True), planned_for, convert_gnumber_link(test.owner), "Deactivated", "N/A", "N/A", "N/A", convert_planned_exec_link(test.id), ""]) elif test.exec_state == "NR": dataTables['aaData'].append([tlbox, regression_column, test.getDataTablesPLMBrowserStr(browser=True), planned_for, convert_gnumber_link(test.owner), test.get_exec_state_display(), "N/A", "N/A", "N/A", convert_planned_exec_link(test.id), "zActivePE"]) else: # Get the build and phase strings build = str(latestLogs[test.id].build) testDate = latestLogs[test.id].test_starttime.date() phase_str = schedule.get(testDate.toordinal(), 'None') dataTables['aaData'].append([tlbox, regression_column, test.getDataTablesPLMBrowserStr(browser=True), planned_for, convert_gnumber_link(test.owner), test.get_exec_state_display(), logCount[test.id], latestLogs[test.id].test_starttime.strftime("%m/%d/%y %H:%M:%S"), build+" / "+phase_str, convert_planned_exec_link(test.id), "zActivePE"]) dataTables['status'] = True return JSONHttpResponse(dataTables)