If there are no track names for today, don't show the row

If there are track names today, show the row for track names. If there aren't, don't show an empty row.
This commit is contained in:
James Polley 2017-12-03 15:23:46 +11:00
parent bc3edb80d9
commit cfc19f309f
2 changed files with 20 additions and 8 deletions

View file

@ -7,14 +7,18 @@
<th>{{ room.name }}</th>
{% endfor %}
</tr>
<tr>
<th class="time">&nbsp;</th>
{% for room in timetable.rooms %}
{% with room|trackname:timetable.day as track_name %}
<th class="track-name">{% if track_name %}<p>{{ track_name }}{% endif %}</th>
{% endwith %}
{% endfor %}
</tr>
{% with timetable|day_has_tracks:timetable.day as has_tracks %}
{% if has_tracks %}
<tr>
<th class="time">&nbsp;</th>
{% for room in timetable.rooms %}
{% with room|trackname:timetable.day as track_name %}
<th class="track-name">{% if track_name %}<p>{{ track_name }}{% endif %}</th>
{% endwith %}
{% endfor %}
</tr>
{% endif %}
{% endwith %}
</thead>
<tbody>
{% for row in timetable %}

View file

@ -78,6 +78,14 @@ def gst(amount):
def conference_name():
return conference_models.Conference.objects.get(id=CONFERENCE_ID).title
@register.filter()
def day_has_tracks(timetable, day):
try:
track_names = day.track_set.all()
has_tracks = True
except Track.DoesNotExist:
has_tracks = False
return len(track_names)
@register.filter()
def trackname(room, day):