From 784d64abffbbf0f543f4c065456f5fbe86655216 Mon Sep 17 00:00:00 2001 From: Gabriel Augendre Date: Tue, 13 Mar 2018 09:42:02 +0100 Subject: [PATCH] Add link to edit machine + refactor equipment quick action --- gym/templates/gym/equipment.html | 38 -------------------------- gym/views.py | 46 +++++++++++++++++++++++++++++++- 2 files changed, 45 insertions(+), 39 deletions(-) diff --git a/gym/templates/gym/equipment.html b/gym/templates/gym/equipment.html index 73bffa0..0bf3d55 100644 --- a/gym/templates/gym/equipment.html +++ b/gym/templates/gym/equipment.html @@ -4,44 +4,6 @@ {% block title %}{{ equipment.name }} ({{ equipment.room.name }}){% endblock %} {% block h1 %}{{ equipment.name }} ({{ equipment.room.name }}){% endblock %} -{% block quick_actions %} -
-
- {% if session %} - Retour à la séance - {% else %} - Retourner à la salle - {% endif %} - Ajouter un réglage - Ajouter un max théorique - {% if session %} - Commencer une série - {% endif %} -
-
{# Visible only on small screens #} - {% if session %} - Retour à la séance - {% else %} - Retourner à la salle - {% endif %} - Ajouter un réglage - Ajouter un max théorique - {% if session %} - Commencer une série - {% endif %} -
-
-{% endblock %} {% block content %}
diff --git a/gym/views.py b/gym/views.py index e8e139a..2082c20 100644 --- a/gym/views.py +++ b/gym/views.py @@ -45,12 +45,56 @@ class RoomDetailView(LoginRequiredMixin, QuickActionsMixin, SessionResetMixin, g return context -class EquipmentDetailView(LoginRequiredMixin, generic.DetailView): +class EquipmentDetailView(LoginRequiredMixin, QuickActionsMixin, generic.DetailView): model = Equipment context_object_name = 'equipment' template_name = 'gym/equipment.html' session = None + def get_quick_actions(self): + lst = [] + + if self.session: + lst.extend([ + { + 'url': reverse('session-detail', args=(self.session.pk,)), + 'category': 'secondary', + 'display': 'Retourner à la séance' + }, + { + 'url': '{}?equipment={}'.format(reverse('round-create'), self.object.pk), + 'category': 'primary', + 'display': 'Commencer une série' + } + ]) + else: + lst.append({ + 'url': reverse('room-detail', args=(self.object.room.pk,)), + 'category': 'secondary', + 'display': 'Retourner à la salle' + }) + lst.extend([ + { + 'url': '{}?equipment={}'.format(reverse('setting-create'), self.object.pk), + 'category': 'success', + 'display': 'Ajouter un réglage' + }, + { + 'url': '{}?equipment={}'.format(reverse('theoretical-max-create'), self.object.pk), + 'category': 'success', + 'display': 'Ajouter un max théorique' + } + ]) + + if self.request.user.is_staff: + lst.append({ + 'url': reverse('admin:gym_equipment_change', args=(self.object.pk,)), + 'category': 'warning', + 'display': 'Éditer la machine' + }) + + return lst + def dispatch(self, request, *args, **kwargs): session_pk = self.request.session.get('session_pk') if session_pk: