Skip to content

Commit

Permalink
delete revision when deleting resources (fix #172)
Browse files Browse the repository at this point in the history
  • Loading branch information
yomguy committed Nov 28, 2014
1 parent 09520cd commit 4596e92
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 0 deletions.
3 changes: 3 additions & 0 deletions telemeta/views/collection.py
Expand Up @@ -135,6 +135,9 @@ def collection_playlist(self, request, public_id, template, mimetype):
def collection_delete(self, request, public_id):
"""Delete a given collection"""
collection = MediaCollection.objects.get(public_id=public_id)
revisions = Revision.objects.filter(element_type='collection', element_id=collection.id)
for revision in revisions:
revision.delete()
collection.delete()
return redirect('telemeta-collections')

Expand Down
3 changes: 3 additions & 0 deletions telemeta/views/item.py
Expand Up @@ -352,6 +352,9 @@ def item_copy(self, request, public_id, template='telemeta/mediaitem_copy.html')
def item_delete(self, request, public_id):
"""Delete a given item"""
item = MediaItem.objects.get(public_id=public_id)
revisions = Revision.objects.filter(element_type='item', element_id=item.id)
for revision in revisions:
revision.delete()
collection = item.collection
item.delete()
return redirect('telemeta-collection-detail', collection.code)
Expand Down
3 changes: 3 additions & 0 deletions telemeta/views/resource.py
Expand Up @@ -147,6 +147,9 @@ def playlist(self, request, type, public_id, template, mimetype):
def delete(self, request, type, public_id):
self.setup(type)
resource = self.model.objects.get(code=public_id)
revisions = Revision.objects.filter(element_type='resource', element_id=resource.id)
for revision in revisions:
revision.delete()
resource.delete()
return HttpResponseRedirect('/archives/'+self.type+'/')

Expand Down

0 comments on commit 4596e92

Please sign in to comment.