Reports can now be 'submitted', and you cannot modify submitted reports.

This commit is contained in:
kououken 2019-02-19 12:45:39 -08:00
parent 744505346f
commit deabfa8dd1
2 changed files with 14 additions and 1 deletions

View file

@ -198,10 +198,20 @@ def report_detail(request, report_pk):
# and marks it as "submitted", after which changes may # and marks it as "submitted", after which changes may
# not be made. # not be made.
elif request.method == 'PUT': elif request.method == 'PUT':
rep = Report.objects.get(id=report_pk)
if rep.submitted == True:
return JsonResponse({"message": "Cannot submit a report that has already been submitted."}, status=400)
rep.submitted = True;
rep.save()
# Send email here
#################
return JsonResponse({"message": "Report submitted."}) return JsonResponse({"message": "Report submitted."})
# DELETE: Deletes a report from the user's account. # DELETE: Deletes a report from the user's account.
elif request.method == 'DELETE': elif request.method == 'DELETE':
r = Report.objects.get(id=report_pk)
if r.submitted == True:
return JsonResponse({"message": "Cannot delete a report that has been submitted."}, status=400)
# get corresponding sections # get corresponding sections
section_set = Section.objects.filter(report_id=report_pk) section_set = Section.objects.filter(report_id=report_pk)
for i in section_set: for i in section_set:
@ -213,7 +223,6 @@ def report_detail(request, report_pk):
path_name = str(j.data_file) path_name = str(j.data_file)
os.remove(path_name) os.remove(path_name)
# delete the full report and catch the title # delete the full report and catch the title
r = Report.objects.get(id=report_pk)
title = r.title title = r.title
r.delete() r.delete()
return JsonResponse({"message": "Deleted report: {0}.".format(title)}) return JsonResponse({"message": "Deleted report: {0}.".format(title)})
@ -241,6 +250,10 @@ def section(request, report_pk, section_pk):
if not user_owns_section(user=request.user, section=section_pk): if not user_owns_section(user=request.user, section=section_pk):
return JsonResponse({"message": "Current user does not own the specified section."}, status=401) return JsonResponse({"message": "Current user does not own the specified section."}, status=401)
# Check that the report isn't submitted
if Section.objects.get(id=section_pk).report_id.submitted:
return JsonResponse({"message": "Cannot update a report that has been submitted."}, status=400)
for key in request.data: for key in request.data:
# get the matching field object # get the matching field object
update = Field.objects.get(section_id=section_pk, field_name=key) update = Field.objects.get(section_id=section_pk, field_name=key)

Binary file not shown.