Highlight equipments used in session + number of rounds

This commit is contained in:
Gabriel Augendre 2019-06-19 21:51:23 +02:00
parent daa8a23bd0
commit 2f83234230
4 changed files with 27 additions and 2 deletions

View file

@ -1,5 +1,6 @@
{% extends 'gym/base.html' %} {% extends 'gym/base.html' %}
{% load bootstrap4 %} {% load bootstrap4 %}
{% load custom_filters %}
{% block title %}Séance en cours{% endblock %} {% block title %}Séance en cours{% endblock %}
{% block h1 %}Séance en cours{% endblock %} {% block h1 %}Séance en cours{% endblock %}
@ -28,7 +29,15 @@
<ul class="list-group"> <ul class="list-group">
{% for equipment in session.room.equipments.all %} {% for equipment in session.room.equipments.all %}
<a href="{% url 'equipment-detail' equipment.pk %}" <a href="{% url 'equipment-detail' equipment.pk %}"
class="list-group-item list-group-item-action">{{ equipment.name }}</a> class="list-group-item
list-group-item-action
{% if equipment in used_equipments %}list-group-item-success{% endif %}
d-flex justify-content-between align-items-center">
{{ equipment.name }}
{% if equipment in used_equipments %}
<span class="badge badge-success badge-pill">{{ used_equipments|get_item:equipment }}</span>
{% endif %}
</a>
{% endfor %} {% endfor %}
</ul> </ul>
</div> </div>
@ -41,7 +50,8 @@
{% for round in session.rounds.all %} {% for round in session.rounds.all %}
<a href="{% url 'round-edit' round.pk %}" <a href="{% url 'round-edit' round.pk %}"
class="list-group-item list-group-item-action">{{ round.equipment.name }} class="list-group-item list-group-item-action">{{ round.equipment.name }}
&ndash; {{ round.repetition_number }} répétitions &times; {{ round.chosen_weight }} {{ round.equipment.unit }}</a> &ndash; {{ round.repetition_number }} répétitions
&times; {{ round.chosen_weight }} {{ round.equipment.unit }}</a>
{% endfor %} {% endfor %}
</ul> </ul>
{% else %} {% else %}

View file

View file

@ -0,0 +1,6 @@
from django.template.defaulttags import register
@register.filter
def get_item(dictionary, key):
return dictionary.get(key)

View file

@ -389,6 +389,15 @@ class SessionDetailView(LoginRequiredMixin, QuickActionsMixin, generic.DetailVie
context_object_name = 'session' context_object_name = 'session'
template_name = 'gym/session_detail.html' template_name = 'gym/session_detail.html'
def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
session = self.get_object()
context['used_equipments'] = {k: Round.objects.filter(equipment=k, session=session).count()
for k in Equipment.objects.filter(rounds__session=self.get_object())}
return context
def get_quick_actions(self): def get_quick_actions(self):
room_pk = self.get_object().room.pk room_pk = self.get_object().room.pk
return [ return [