Add link to edit machine + refactor equipment quick action
This commit is contained in:
parent
0dc4504d48
commit
784d64abff
2 changed files with 45 additions and 39 deletions
|
@ -4,44 +4,6 @@
|
||||||
{% block title %}{{ equipment.name }} ({{ equipment.room.name }}){% endblock %}
|
{% block title %}{{ equipment.name }} ({{ equipment.room.name }}){% endblock %}
|
||||||
{% block h1 %}{{ equipment.name }} <small class="text-muted">({{ equipment.room.name }})</small>{% endblock %}
|
{% block h1 %}{{ equipment.name }} <small class="text-muted">({{ equipment.room.name }})</small>{% endblock %}
|
||||||
|
|
||||||
{% block quick_actions %}
|
|
||||||
<div class="row">
|
|
||||||
<div class="col-12 d-none d-md-block">
|
|
||||||
{% if session %}
|
|
||||||
<a href="{% url 'session-detail' session %}"
|
|
||||||
class="btn btn-secondary">Retour à la séance</a>
|
|
||||||
{% else %}
|
|
||||||
<a href="{% url 'room-detail' equipment.room.pk %}"
|
|
||||||
class="btn btn-secondary">Retourner à la salle</a>
|
|
||||||
{% endif %}
|
|
||||||
<a href="{% url 'setting-create' %}?equipment={{ equipment.pk }}"
|
|
||||||
class="btn btn-success">Ajouter un réglage</a>
|
|
||||||
<a href="{% url 'theoretical-max-create' %}?equipment={{ equipment.pk }}"
|
|
||||||
class="btn btn-success">Ajouter un max théorique</a>
|
|
||||||
{% if session %}
|
|
||||||
<a href="{% url 'round-create' %}?equipment={{ equipment.pk }}"
|
|
||||||
class="btn btn-primary">Commencer une série</a>
|
|
||||||
{% endif %}
|
|
||||||
</div>
|
|
||||||
<div class="col-12 d-md-none"> {# Visible only on small screens #}
|
|
||||||
{% if session %}
|
|
||||||
<a href="{% url 'session-detail' session %}"
|
|
||||||
class="btn btn-secondary btn-block">Retour à la séance</a>
|
|
||||||
{% else %}
|
|
||||||
<a href="{% url 'room-detail' equipment.room.pk %}"
|
|
||||||
class="btn btn-secondary btn-block">Retourner à la salle</a>
|
|
||||||
{% endif %}
|
|
||||||
<a href="{% url 'setting-create' %}?equipment={{ equipment.pk }}"
|
|
||||||
class="btn btn-success btn-block">Ajouter un réglage</a>
|
|
||||||
<a href="{% url 'theoretical-max-create' %}?equipment={{ equipment.pk }}"
|
|
||||||
class="btn btn-success btn-block">Ajouter un max théorique</a>
|
|
||||||
{% if session %}
|
|
||||||
<a href="{% url 'round-create' %}?equipment={{ equipment.pk }}"
|
|
||||||
class="btn btn-primary btn-block">Commencer une série</a>
|
|
||||||
{% endif %}
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
{% endblock %}
|
|
||||||
|
|
||||||
{% block content %}
|
{% block content %}
|
||||||
<div class="row">
|
<div class="row">
|
||||||
|
|
46
gym/views.py
46
gym/views.py
|
@ -45,12 +45,56 @@ class RoomDetailView(LoginRequiredMixin, QuickActionsMixin, SessionResetMixin, g
|
||||||
return context
|
return context
|
||||||
|
|
||||||
|
|
||||||
class EquipmentDetailView(LoginRequiredMixin, generic.DetailView):
|
class EquipmentDetailView(LoginRequiredMixin, QuickActionsMixin, generic.DetailView):
|
||||||
model = Equipment
|
model = Equipment
|
||||||
context_object_name = 'equipment'
|
context_object_name = 'equipment'
|
||||||
template_name = 'gym/equipment.html'
|
template_name = 'gym/equipment.html'
|
||||||
session = None
|
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):
|
def dispatch(self, request, *args, **kwargs):
|
||||||
session_pk = self.request.session.get('session_pk')
|
session_pk = self.request.session.get('session_pk')
|
||||||
if session_pk:
|
if session_pk:
|
||||||
|
|
Loading…
Reference in a new issue