Display rounds for current machine if session in progress

This commit is contained in:
Gabriel Augendre 2018-03-04 09:57:25 +01:00
parent 84e8f76c67
commit 89af0e40c0
No known key found for this signature in database
GPG key ID: F360212F958357D4
2 changed files with 27 additions and 1 deletions

View file

@ -56,4 +56,21 @@
{% endif %} {% endif %}
</div> </div>
</div> </div>
{% if session %}
<div class="row">
<div class="col-12">
<h2>Séries de la séance en cours</h2>
{% if rounds %}
<ul class="list-group">
{% for round in rounds %}
<a href="#" class="list-group-item">{{ round.repetition_number }} répétitions
&times; {{ round.chosen_weight }}</a>
{% endfor %}
</ul>
{% else %}
<p>Pas de série pour cette machine aujourd'hui.</p>
{% endif %}
</div>
</div>
{% endif %}
{% endblock %} {% endblock %}

View file

@ -40,10 +40,19 @@ class EquipmentDetailView(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
def dispatch(self, request, *args, **kwargs):
session_pk = self.request.session.get('session_pk')
if session_pk:
self.session = Session.objects.get(pk=session_pk)
return super().dispatch(request, *args, **kwargs)
def get_context_data(self, **kwargs): def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs) context = super().get_context_data(**kwargs)
context['session'] = self.request.session.get('session_pk') if self.session:
context['session'] = self.session.pk
context['rounds'] = Round.objects.filter(session=self.session, equipment=self.get_object())
return context return context