Merge pull request #117 from danieldupriest/review_error_msg

Review error msg
This commit is contained in:
ppdom 2019-03-07 12:41:17 -08:00 committed by GitHub
commit 59f7ca655b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 6 deletions

View file

@ -204,6 +204,9 @@ def report_detail(request, report_pk):
# PUT: Submits a report to the administrator for review, # PUT: Submits a report to the administrator for review,
# but is still allowed to make further changes # but is still allowed to make further changes
elif request.method == 'PUT': elif request.method == 'PUT':
r = Report.objects.get(id=report_pk)
if r.submitted:
return JsonResponse({"message": "Cannot review a report that has already been submitted."}, status=409)
# Send email # Send email
send_report_to_admin(request, report_pk, status="REVIEW") send_report_to_admin(request, report_pk, status="REVIEW")
return JsonResponse({"message": "Request for review is submitted."}) return JsonResponse({"message": "Request for review is submitted."})
@ -211,8 +214,8 @@ def report_detail(request, report_pk):
# 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) r = Report.objects.get(id=report_pk)
if r.submitted == True: if r.submitted:
return JsonResponse({"message": "Cannot delete a report that has been submitted."}, status=409) return JsonResponse({"message": "Cannot delete a report that has already been submitted."}, status=409)
# 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:
@ -248,13 +251,13 @@ def finalize_report(request, report_pk):
return JsonResponse({"message": "Final report submitted."}) return JsonResponse({"message": "Final report submitted."})
def user_owns_section(user, section): def user_owns_section(user, section_id):
""" """
Returns true if the specified user is owner of the section. Returns true if the specified user is owner of the section.
section -- ID of the section to check. section -- ID of the section to check.
""" """
section_to_check = Section.objects.filter(id=section) section_to_check = Section.objects.filter(id=section_id)
if len(section_to_check) < 1: if len(section_to_check) < 1:
return False return False
report_to_check = section_to_check[0].report_id report_to_check = section_to_check[0].report_id
@ -268,7 +271,7 @@ def section(request, report_pk, section_pk):
section_pk -- Section for which the data should be updated. section_pk -- Section for which the data should be updated.
""" """
# Check that the user owns the report # Check that the user owns the report
if not user_owns_section(user=request.user, section=section_pk): if not user_owns_section(user=request.user, section_id=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 # Check that the report isn't submitted
@ -411,7 +414,7 @@ def send_report_to_admin(request, report_pk, status):
message = None message = None
if params['reference_number'] == '': if params['reference_number'] == '':
message = EmailMultiAlternatives( message = EmailMultiAlternatives(
"{} ({})".format(params['title'], status), "[Reimbursinator {}] ({})".format(params['title'], status),
msg_plain, msg_plain,
from_email, from_email,
[to_email], [to_email],

Binary file not shown.