fix next_event and previous_event if there isn't one

This commit is contained in:
2021-12-11 10:27:50 -06:00
parent 5bd6bad1a7
commit ecb25abd71
2 changed files with 74 additions and 69 deletions

View File

@@ -1,18 +1,22 @@
{% extends 'base.html' %}{% block title %} {{ title }} {% endblock %}{% load crispy_forms_tags %}{% load static %}
{% with events_active="active" %}
{% block precontent %}
{% block precontent %}
<div class="d-flex justify-content-center justify-content-md-center border-bottom bg-white">
{% if previous_event %}
<a class="btn btn-outline-secondary btn-sm d-md-flex my-auto align-items-md-center my-3 mx-3" href="{% url 'edit lineup' event_id=previous_event.id %}" role="button">
<i class="bi bi-chevron-left"></i>{{ previous_event.start|date:"D" }}&nbsp;{{ previous_event.start|date:"n/j" }}
</a>
{% endif %}
<div>
<h5 class="text-center m-1">{{ event.away_team.name }} vs. {{ event.home_team.name }}</h5>
<p class="text-center text-muted m-1">{{ event.start|date:"l, F j, Y g:i A" }}<br>{{ event.venue.name }}</p>
<h6 class="text-muted m-1"></h6>
</div>
{% if next_event %}
<a class="btn btn-outline-secondary btn-sm align-items-center my-auto my-3 mx-3" href="{% url 'edit lineup' event_id=next_event.id %}" role="button">
{{ next_event.start|date:"D" }}&nbsp;{{ next_event.start|date:"n/j" }}<i class="bi bi-chevron-right"></i>
</a>
{% endif %}
</div>
<ul class="nav nav-pills nav-fill bg-white" role="tablist">
@@ -20,7 +24,7 @@
<li class="nav-item m-1" role="presentation"><a id="event-lineup-tab" class="nav-link px-2 py-0" data-bs-toggle="pill" data-bs-target="#event-lineup" role="tab" aria-controls="event-lineup" aria-selected="false">Lineup</a></li>
</ul>
{% endblock %}{% endwith %}
{% endblock %}{% endwith %}
{% block content %}
<div id="pills-tabContent" class="container-fluid tab-content my-1" data-toggle="tab">
<div id="event-details" class="tab-pane show active" role="tabpanel" aria-labelledby="event-details-tab">

View File

@@ -35,7 +35,7 @@ def edit(request, event_id):
else:
pass
return render(request, 'success.html', {'call_back':'edit lineup','id':event_id, 'errors':[error for error in formset.errors if error]}, status=200)
previous_event = Event.objects.get(id=event_id-1)
previous_event = Event.objects.filter(id=event_id-1).first()
event = Event.objects.get(id=event_id)
next_event = Event.objects.get(id=event_id+1)
@@ -86,7 +86,8 @@ def edit(request, event_id):
}
return render(request, 'lineups/lineup.html', {'title': 'Lineup',
'event': event, 'details':details,
'event': event,
'details':details,
'previous_event': previous_event,
'next_event': next_event,
'formset': formset,