Skip to content

Commit

Permalink
[OpenDataServices/cove#130] Add delete button
Browse files Browse the repository at this point in the history
  • Loading branch information
Bjwebb committed Nov 19, 2015
1 parent 3cb62c5 commit 56856b5
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
31 changes: 31 additions & 0 deletions modules/cove_resourceprojects.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import subprocess
import os
import json
import shutil
import urllib.parse


Expand Down Expand Up @@ -113,13 +114,36 @@ def outputted_ttl(dataset):
return dataset.supplied_data.upload_url() + 'output.ttl'


def delete(dataset):
# Don't allow deletion if the datsets still loaded on live or staging
for process_id in ['staging', 'live']:
process = PROCESSES[process_id]
last_run = dataset.processrun_set.filter(process=process_id).order_by('-datetime').first()

# If the reverse of the process has been run more recently, undo it
if last_run and 'reverse_id' in process:
reverse_last_run = dataset.processrun_set.filter(process=process['reverse_id'], successful=True).order_by('-datetime').first()
if reverse_last_run and last_run.datetime < reverse_last_run.datetime:
last_run = None

if last_run:
raise Exception('Can not delete until it\'s removed from live and staging.')

# Delete the files
shutil.rmtree(dataset.supplied_data.upload_dir())
# Mark the dataset as deleted in the database
# (We keep the object around so we could pull out logs later).
dataset.deleted = True
dataset.save()


PROCESSES = OrderedDict([
('fetch', {
'name': 'Fetched',
'action_name': 'Fetch',
'depends': None,
'function': fetch,
'reverse_id': 'delete',
'main': True,
}),
('convert', {
Expand Down Expand Up @@ -165,4 +189,11 @@ def outputted_ttl(dataset):
'function': partial(delete_from_virtuoso, staging=False),
'main': False
}),
('delete', {
'name': 'Deleted',
'action_name': 'Delete',
'depends': 'live',
'function': delete,
'main': False
}),
])
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
-e git+https://github.com/OpenDataServices/cove.git@38a277475d9ef7ab3f690780de5d675db17b0f4a#egg=cove
-e git+https://github.com/OpenDataServices/cove.git@982d176bc290e504f4f6e2d0b18120140c579c9b#egg=cove
-e git+https://github.com/OpenDataServices/flatten-tool.git@61d8404b444f10384363cde1cad542a0d04af004#egg=flattentool
-r requirements_taglifter.txt
gunicorn==19.3.0
Expand Down

0 comments on commit 56856b5

Please sign in to comment.