def test_get_edit_report_list(self): """ Testing the function that returns a list representing the report.attributes status. The function returns a dict, which has status on for each active attribute and off otherwise """ report_dict = get_edit_report_list(self.report) count = 0 for item in report_dict: if item['status'] == 'on': count += 1 self.assertEqual(count, 2) # Testing that the report list is detecting 2 attributes in the report.
def edit_report(request, report_id): """ View to edit a report given, a report id as an parameter """ context_dict = {} report = Report.objects.filter(id=report_id).first() attribute_list = [] if request.method == 'POST': for key, value in request.POST.items(): if value == 'on': attribute_list.append(demjson.decode(key)) report.attributes = attribute_list report.duration = request.POST['duration'] report.save() return redirect(reverse('manage_reports', args=[report.site.id])) context_dict['attributes'] = get_edit_report_list(report) context_dict['report'] = report context_dict['duration_choices'] = report.get_duration_choices() return render(request, 'seshdash/settings/edit_report.html', context_dict)