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 %}
{% for i in user.slots.filter(start_date__gte=timezone.now().replace(tzinfo=None)).all() %}
- - {{ i.get_type_display() }} - {{i.machine.launderette }}, {{ i.start_date|date("l j") }} : {{ i.start_date|time(DATETIME_FORMAT) }}
+ - {{ i.get_type_display() }} - {{i.machine.launderette }}, {{ i.start_date|date("l j") }} :
+ {{ i.start_date|time(DATETIME_FORMAT) }} |
+ {% trans %}Delete{% endtrans %}
{% endfor %}
{% 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):