From 8de0d549400e11e5efbb9d1177f26a71ef5ffa34 Mon Sep 17 00:00:00 2001 From: Skia Date: Thu, 15 Dec 2016 16:11:43 +0100 Subject: [PATCH] Allow to delete a launderette slot --- core/templates/core/macros.jinja | 4 +++- launderette/models.py | 3 +++ launderette/urls.py | 1 + launderette/views.py | 10 ++++++++++ 4 files changed, 17 insertions(+), 1 deletion(-) diff --git a/core/templates/core/macros.jinja b/core/templates/core/macros.jinja index a1341a4c..6239c695 100644 --- a/core/templates/core/macros.jinja +++ b/core/templates/core/macros.jinja @@ -44,7 +44,9 @@
{% trans %}Slot{% endtrans %}
{% endif %} diff --git a/launderette/models.py b/launderette/models.py index c1105211..75aa5610 100644 --- a/launderette/models.py +++ b/launderette/models.py @@ -127,6 +127,9 @@ class Slot(models.Model): verbose_name = _('Slot') ordering = ['start_date'] + def is_owned_by(self, user): + return user == self.user + def __str__(self): return "User: %s - Date: %s - Type: %s - Machine: %s - Token: %s" % (self.user, self.start_date, self.get_type_display(), self.machine.name, self.token) diff --git a/launderette/urls.py b/launderette/urls.py index b231dd3d..2ee14e9d 100644 --- a/launderette/urls.py +++ b/launderette/urls.py @@ -5,6 +5,7 @@ from launderette.views import * urlpatterns = [ # views url(r'^$', LaunderetteMainView.as_view(), name='launderette_main'), + url(r'^slot/(?P[0-9]+)/delete$', SlotDeleteView.as_view(), name='delete_slot'), url(r'^book$', LaunderetteBookMainView.as_view(), name='book_main'), url(r'^book/(?P[0-9]+)$', LaunderetteBookView.as_view(), name='book_slot'), url(r'^(?P[0-9]+)/click$', LaunderetteMainClickView.as_view(), name='main_click'), diff --git a/launderette/views.py b/launderette/views.py index 8432d0a9..4c4b7102 100644 --- a/launderette/views.py +++ b/launderette/views.py @@ -113,6 +113,16 @@ class LaunderetteBookView(CanViewMixin, DetailView): kwargs['planning'][date].append(None) return kwargs +class SlotDeleteView(CanEditPropMixin, DeleteView): + """Delete a slot""" + model = Slot + pk_url_kwarg = "slot_id" + template_name = 'core/delete_confirm.jinja' + + def get_success_url(self): + return self.request.user.get_absolute_url() + + # For admins class LaunderetteListView(CanEditPropMixin, ListView):