Commits

Greg Newman  committed 50d9ad4

adding delete methods

  • Participants
  • Parent commits d091deb

Comments (0)

Files changed (2)

File loupe/urls.py

         name='corkboard_detail',
     ),
 
+    url(r'^corkboard/destroy/(\d+)/$',
+        view='corkboard_destroy',
+        name='corkboard_destroy'
+    ),
+
+    url(r'^image/destroy/(\d+)/$',
+        view='image_destroy',
+        name='image_destroy'
+    ),
+                       
     (r'^comments/', include('django.contrib.comments.urls')),
 )

File loupe/views.py

         "notes_count": notes_count,
         "form": form,
     }, context_instance=RequestContext(request))
+
+
+@require_POST
+@login_required
+def corkboard_destroy(request, id):
+    """
+    Deletes the corkboard passed in from the form
+    """
+    corkboard = get_object_or_404(Corkboard, pk=id)
+    title = corkboard.title
+    if not request.user.is_staff:
+        return HttpResponseRedirect(reverse('dashboard'))
+
+    corkboard.delete()
+    request.user.message_set.create(message=_("Successfully deleted corkboard '%s'") % title)
+    return HttpResponseRedirect(reverse('dashboard'))
+
+@require_POST
+@login_required
+def image_destroy(request, id):
+    """
+    Deletes the corkboard passed in from the form
+    """
+    image = get_object_or_404(Image, pk=id)
+    corkboard = image.corkboard
+    title = image.title
+    
+    if not request.user.is_staff:
+        return HttpResponseRedirect(reverse('dashboard'))
+
+    image.delete()
+    request.user.message_set.create(message=_("Successfully deleted image '%s'") % title)
+    return HttpResponseRedirect(request.POST['next'])