Update draft deletion logic for new field

And comment the delete-files-only-in-drafts logic.
This commit is contained in:
Anna Sidwell 2018-06-27 19:50:24 +01:00 committed by Naomi
parent a900a146e2
commit f5fac0b6a0

View File

@ -161,9 +161,11 @@ class Drafts(LoginRequiredMixin, View):
data = json.loads(draft.data)
for k in ['official_project_documents', 'other_documents',
'shapefiles']:
'shapefiles', 'images' ]:
try:
# Filter the dictionary of form fields in the draft
# down to just the ones right the right name `k`
items = list(filter(
lambda x: (
x['name'] == '{0}_files'.format(k)
@ -172,12 +174,14 @@ class Drafts(LoginRequiredMixin, View):
))
except KeyError:
continue
# Split the comma-separated list of IDs into a list
try:
items = items[0]['value'].split(',')
except IndexError:
continue
# Delete those items
for item in items:
try:
f = File.objects.get(id=item)