Merge pull request #70 from danieldupriest/delete_file_db
Delete file db
This commit is contained in:
commit
60eddf7ca4
3 changed files with 18 additions and 5 deletions
|
@ -82,6 +82,5 @@ class Field(models.Model):
|
||||||
# function that accommodates if
|
# function that accommodates if
|
||||||
# path has slash at end
|
# path has slash at end
|
||||||
def path_leaf(self, path):
|
def path_leaf(self, path):
|
||||||
head, tail = ntpath.split(path)
|
dir_path, name = ntpath.split(path)
|
||||||
return tail or ntpath.basename(head)
|
return name or ntpath.basename(dir_path)
|
||||||
|
|
||||||
|
|
|
@ -2,6 +2,7 @@ from rest_framework.decorators import api_view
|
||||||
from django.http import JsonResponse
|
from django.http import JsonResponse
|
||||||
from .models import *
|
from .models import *
|
||||||
from .policy import pol
|
from .policy import pol
|
||||||
|
import os
|
||||||
|
|
||||||
|
|
||||||
# function that prints all the reports
|
# function that prints all the reports
|
||||||
|
@ -133,8 +134,21 @@ def report_detail(request, report_pk):
|
||||||
|
|
||||||
# Delete the report
|
# Delete the report
|
||||||
elif request.method == 'DELETE':
|
elif request.method == 'DELETE':
|
||||||
Report.objects.filter(id=report_pk).delete()
|
# get corresponding sections
|
||||||
return JsonResponse({"message": "Deleted report {0}.".format(report_pk)})
|
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
|
# update a section with new data
|
||||||
|
|
BIN
back/db.sqlite3
BIN
back/db.sqlite3
Binary file not shown.
Loading…
Reference in a new issue