diff --git a/back/backend/models.py b/back/backend/models.py index 032ed0c..557020f 100644 --- a/back/backend/models.py +++ b/back/backend/models.py @@ -82,6 +82,5 @@ class Field(models.Model): # function that accommodates if # path has slash at end def path_leaf(self, path): - head, tail = ntpath.split(path) - return tail or ntpath.basename(head) - + dir_path, name = ntpath.split(path) + return name or ntpath.basename(dir_path) diff --git a/back/backend/views.py b/back/backend/views.py index b3efb87..fa17a1b 100644 --- a/back/backend/views.py +++ b/back/backend/views.py @@ -2,6 +2,7 @@ from rest_framework.decorators import api_view from django.http import JsonResponse from .models import * from .policy import pol +import os # function that prints all the reports @@ -133,8 +134,21 @@ def report_detail(request, report_pk): # Delete the report elif request.method == 'DELETE': - Report.objects.filter(id=report_pk).delete() - return JsonResponse({"message": "Deleted report {0}.".format(report_pk)}) + # get corresponding sections + section_set = Section.objects.filter(report_id=report_pk) + for i in section_set: + # gets the fields that only have a data file in them + field_set = Field.objects.filter(section_id=i.id).exclude(data_file__exact='') + if field_set.exists(): + for j in field_set: + # delete the file if exists + path_name = str(j.data_file) + os.remove(path_name) + # delete the full report and catch the title + r = Report.objects.get(id=report_pk) + title = r.title + r.delete() + return JsonResponse({"message": "Deleted report: {0}.".format(title)}) # update a section with new data diff --git a/back/db.sqlite3 b/back/db.sqlite3 index 5915594..894a6e7 100644 Binary files a/back/db.sqlite3 and b/back/db.sqlite3 differ