From 9b1d9e7e04cf1184bc9a4241c9cd636f2b6f6ba4 Mon Sep 17 00:00:00 2001 From: Anna Sidwell Date: Wed, 27 Jun 2018 19:50:24 +0100 Subject: [PATCH] Update draft deletion logic for new field And comment the delete-files-only-in-drafts logic. --- apps/map/views.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/apps/map/views.py b/apps/map/views.py index d91bd03..808235b 100644 --- a/apps/map/views.py +++ b/apps/map/views.py @@ -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)