Merge pull request #70 from danieldupriest/delete_file_db

Delete file db
This commit is contained in:
ppdom 2019-02-11 13:59:07 -08:00 committed by GitHub
commit 60eddf7ca4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 18 additions and 5 deletions

View file

@ -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)

View file

@ -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

Binary file not shown.