Allow to delete a launderette slot

This commit is contained in:
Skia 2016-12-15 16:11:43 +01:00
parent 57d8926a3f
commit 8de0d54940
4 changed files with 17 additions and 1 deletions

View File

@ -44,7 +44,9 @@
<h5>{% trans %}Slot{% endtrans %}</h5> <h5>{% trans %}Slot{% endtrans %}</h5>
<ul> <ul>
{% for i in user.slots.filter(start_date__gte=timezone.now().replace(tzinfo=None)).all() %} {% for i in user.slots.filter(start_date__gte=timezone.now().replace(tzinfo=None)).all() %}
<li>{{ i.get_type_display() }} - {{i.machine.launderette }}, {{ i.start_date|date("l j") }} : {{ i.start_date|time(DATETIME_FORMAT) }}</li> <li>{{ i.get_type_display() }} - {{i.machine.launderette }}, {{ i.start_date|date("l j") }} :
{{ i.start_date|time(DATETIME_FORMAT) }} |
<a href="{{ url('launderette:delete_slot', slot_id=i.id) }}">{% trans %}Delete{% endtrans %}</a></li>
{% endfor %} {% endfor %}
</ul> </ul>
{% endif %} {% endif %}

View File

@ -127,6 +127,9 @@ class Slot(models.Model):
verbose_name = _('Slot') verbose_name = _('Slot')
ordering = ['start_date'] ordering = ['start_date']
def is_owned_by(self, user):
return user == self.user
def __str__(self): def __str__(self):
return "User: %s - Date: %s - Type: %s - Machine: %s - Token: %s" % (self.user, self.start_date, self.get_type_display(), 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) self.machine.name, self.token)

View File

@ -5,6 +5,7 @@ from launderette.views import *
urlpatterns = [ urlpatterns = [
# views # views
url(r'^$', LaunderetteMainView.as_view(), name='launderette_main'), url(r'^$', LaunderetteMainView.as_view(), name='launderette_main'),
url(r'^slot/(?P<slot_id>[0-9]+)/delete$', SlotDeleteView.as_view(), name='delete_slot'),
url(r'^book$', LaunderetteBookMainView.as_view(), name='book_main'), url(r'^book$', LaunderetteBookMainView.as_view(), name='book_main'),
url(r'^book/(?P<launderette_id>[0-9]+)$', LaunderetteBookView.as_view(), name='book_slot'), url(r'^book/(?P<launderette_id>[0-9]+)$', LaunderetteBookView.as_view(), name='book_slot'),
url(r'^(?P<launderette_id>[0-9]+)/click$', LaunderetteMainClickView.as_view(), name='main_click'), url(r'^(?P<launderette_id>[0-9]+)/click$', LaunderetteMainClickView.as_view(), name='main_click'),

View File

@ -113,6 +113,16 @@ class LaunderetteBookView(CanViewMixin, DetailView):
kwargs['planning'][date].append(None) kwargs['planning'][date].append(None)
return kwargs 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 # For admins
class LaunderetteListView(CanEditPropMixin, ListView): class LaunderetteListView(CanEditPropMixin, ListView):