cleanup and added comments
This commit is contained in:
@@ -1,19 +0,0 @@
|
||||
{% extends 'benchcoach/detail.html' %}
|
||||
|
||||
{% block navbar %}
|
||||
{% with events_tab="active" %}
|
||||
{{ block.super }}
|
||||
{% endwith %}
|
||||
{% endblock %}
|
||||
|
||||
{% block page_heading %}
|
||||
Event
|
||||
{% endblock %}
|
||||
|
||||
{% block rows %}
|
||||
<tr><th>Date</th><td>{{ event.start.date|date }}</td></tr>
|
||||
<tr><th>Time</th><td>{{ event.start.time|time }}</td></tr>
|
||||
<tr><th>Away</th><td>{{ event.away_team.name }}</td></tr>
|
||||
<tr><th>Home</th><td>{{ event.home_team.name }}</td></tr>
|
||||
<tr><th>Venue</th><td>{{ event.venue }}</td></tr>
|
||||
{% endblock %}
|
||||
@@ -18,7 +18,7 @@ Events
|
||||
<h6>{{ event.away_team|default_if_none:"" }} vs. {{ event.home_team|default_if_none:"" }}</h6>
|
||||
{{ event.start|date:"l, F j, Y g:i A" }} <br>
|
||||
{{ event.venue.name }} <br>
|
||||
<a href="{% url 'edit lineup' event_id=event.id %}">Edit Lineup...</a>
|
||||
<a href="{% url 'event' event_id=event.id %}">Edit Lineup...</a>
|
||||
</li>
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
|
||||
@@ -28,18 +28,18 @@
|
||||
<ul class="nav nav-tabs nav-fill bg-white" role="tablist">
|
||||
{% if previous_event %}
|
||||
<li class="nav-item m-1">
|
||||
<a href="{% url 'edit lineup' event_id=previous_event.id active_tab=active_tab %}">
|
||||
<a href="{% url 'event' event_id=previous_event.id active_tab=active_tab %}">
|
||||
<i class="bi bi-chevron-left"></i>{{ previous_event.start|date:"D" }} {{ previous_event.start|date:"n/j" }}
|
||||
</a>
|
||||
</li>
|
||||
{% endif %}
|
||||
|
||||
<li class="nav-item m-1" role="presentation">
|
||||
<a id="event-details-tab" class="nav-link {% if active_tab == "details" %}active{% endif %} px-2 py-0" href="{% url 'edit lineup' event_id=event.id active_tab='details'%}">Details</a></li>
|
||||
<li class="nav-item m-1" role="presentation"><a id="event-lineup-tab" class="nav-link {% if active_tab == "lineup" %}active{% endif %} px-2 py-0" href="{% url 'edit lineup' event_id=event.id active_tab='lineup'%}">Lineup</a></li>
|
||||
<a id="event-details-tab" class="nav-link {% if active_tab == "details" %}active{% endif %} px-2 py-0" href="{% url 'event' event_id=event.id active_tab='details'%}">Details</a></li>
|
||||
<li class="nav-item m-1" role="presentation"><a id="event-lineup-tab" class="nav-link {% if active_tab == "lineup" %}active{% endif %} px-2 py-0" href="{% url 'event' event_id=event.id active_tab='lineup'%}">Lineup</a></li>
|
||||
{% if next_event %}
|
||||
<li class="nav-item m-1">
|
||||
<a href="{% url 'edit lineup' event_id=next_event.id active_tab=active_tab%}" role="button">
|
||||
<a href="{% url 'event' event_id=next_event.id active_tab=active_tab%}" role="button">
|
||||
{{ next_event.start|date:"D" }} {{ next_event.start|date:"n/j" }}<i class="bi bi-chevron-right"></i>
|
||||
</a>
|
||||
</li>
|
||||
@@ -68,7 +68,7 @@
|
||||
</form>
|
||||
</div>
|
||||
<div id="event-lineup" class="tab-pane {% if active_tab == "lineup" %}show active{% endif %}" role="tabpanel" aria-labelledby="event-lineup-tab">
|
||||
<form action="{% url 'edit lineup' event_id=event.id active_tab=active_tab%}" method="post">
|
||||
<form action="{% url 'event' event_id=event.id active_tab=active_tab%}" method="post">
|
||||
{% csrf_token %}
|
||||
{{ formset.management_form }}
|
||||
<div class="row w-100">
|
||||
@@ -4,14 +4,12 @@ from django.contrib.auth.decorators import login_required
|
||||
from . import views
|
||||
|
||||
urlpatterns = [
|
||||
path('lineup/edit/<int:event_id>/', login_required(views.lineup_edit), name="edit lineup"),
|
||||
path('lineup/edit/<int:event_id>/<str:active_tab>', login_required(views.lineup_edit), name="edit lineup"),
|
||||
path('events/list/', login_required(views.EventListView.as_view()), name="event list"),
|
||||
path('events/<int:pk>/detail', login_required(views.EventDetailView.as_view()), name="event detail"),
|
||||
path('events/<int:pk>/lineup', login_required(views.EventDetailView.as_view()), name="event lineup"),
|
||||
path('events/<int:event_id>/', login_required(views.event), name="event"),
|
||||
path('players/list/', login_required(views.PlayerListView.as_view()), name="player list"),
|
||||
path('teams/list/', login_required(views.TeamListView.as_view()), name="team list"),
|
||||
path('venues/list/', login_required(views.VenueListView.as_view()), name="venue list"),
|
||||
path('events/<int:event_id>/card', login_required(views.lineupcard), name="lineup card"),
|
||||
path('events/<int:event_id>/csv', views.csv_export, name="lineup csv")
|
||||
path('events/<int:event_id>/csv', views.csv_export, name="lineup csv"),
|
||||
path('events/<int:event_id>/<str:active_tab>', login_required(views.event), name="event")
|
||||
]
|
||||
@@ -3,25 +3,30 @@ from abc import ABC, abstractmethod
|
||||
import django.db.models
|
||||
from django.db.models import QuerySet
|
||||
from typing import List, Tuple
|
||||
import benchcoach.models
|
||||
|
||||
class AbstractSyncEngine(ABC):
|
||||
models: List[django.db.models.Model]
|
||||
'''
|
||||
Class used for importing and syncing Bench Coach models.
|
||||
'''
|
||||
models: List[benchcoach.models.BenchcoachModel]
|
||||
|
||||
@abstractmethod
|
||||
def sync(self, qs: django.db.models.QuerySet = None, instance: django.db.models.Model = None, direction='download') -> List[Tuple[django.db.models.Model, bool]]:
|
||||
def sync(self, qs: django.db.models.QuerySet = None, instance: benchcoach.models.BenchcoachModel = None, direction='download') -> List[Tuple[django.db.models.Model, bool]]:
|
||||
'''
|
||||
Syncs the input from/to the service. Either a query set or instance should be provided, but not both.
|
||||
:param qs: the queryset to be updated. If set to 'download', it will be updated from the service, if set to uplad, its contents
|
||||
will be sent to the server
|
||||
:param instance: the instance to be updated. If set to 'download', it will be updated from the service, if set to uplad, its contents
|
||||
will be sent to the server.
|
||||
:param direction: the sync direction, either 'download' or 'upload'.
|
||||
:return: a list of tuples in the form of (created/updated object, true if created/false if not)
|
||||
It does not create Bench Coach objects.
|
||||
:param qs: the queryset to be updated.
|
||||
:param instance: the instance to be updated.
|
||||
:param direction: the sync direction, either 'download' or 'upload'. If set to 'download', it will be updated from the service, if set to upload, its contents
|
||||
will be sent to the service
|
||||
:return: a list of BenchCoach objects that have been iterated (but not necessarily changed) during sync.
|
||||
'''
|
||||
|
||||
@abstractmethod
|
||||
def import_items(self):
|
||||
'''
|
||||
Imports the items from the service.
|
||||
:return: a list of tuples in the form of (created/updated object, true if created/false if not)
|
||||
Imports the items from the service. It imports all models specified in the class property 'model'.
|
||||
It creates BenchCoach objects, but should not create duplicates.
|
||||
:return: a list of BenchCoach objects that have been iterated (but not necessarily changed) during import.
|
||||
'''
|
||||
@@ -50,7 +50,15 @@ class VenueListView(ListView):
|
||||
context['venues_tab_active'] ='active'
|
||||
return context
|
||||
|
||||
def lineup_edit(request, event_id, active_tab='details'):
|
||||
def event(request, event_id, active_tab='details'):
|
||||
'''
|
||||
Event is the main page for showing an event.
|
||||
:param request: django request
|
||||
:param event_id: The Bench Coach event ID to display
|
||||
:param active_tab: The desired active tab, supports "lineup" and "details"
|
||||
:return: 'details' renders a page with event information, 'lineup' with lineup information.
|
||||
Either gives context to the template with the event information and formset for the lineup.
|
||||
'''
|
||||
|
||||
if request.method == "POST":
|
||||
# create a form instance and populate it with data from the request:
|
||||
@@ -123,7 +131,7 @@ def lineup_edit(request, event_id, active_tab='details'):
|
||||
|
||||
return render(
|
||||
request,
|
||||
"benchcoach/lineup.html",
|
||||
"benchcoach/event.html",
|
||||
{
|
||||
"title": "Lineup",
|
||||
"active_tab":active_tab,
|
||||
@@ -139,6 +147,13 @@ def lineup_edit(request, event_id, active_tab='details'):
|
||||
)
|
||||
|
||||
def lineupcard(request, event_id):
|
||||
'''
|
||||
Lineup Card is an first attempt at replicating the "Lineup Card" from Google sheets.
|
||||
It is incomplete.
|
||||
:param request:
|
||||
:param event_id: The Event ID to generate
|
||||
:return: It generates a page layout. The context has info for event, event details, starting players and all players (both as a queryset)
|
||||
'''
|
||||
previous_event = Event.objects.filter(id=event_id - 1).first()
|
||||
|
||||
event = Event.objects.get(id=event_id)
|
||||
@@ -181,6 +196,13 @@ def lineupcard(request, event_id):
|
||||
)
|
||||
|
||||
def csv_export(request, event_id):
|
||||
'''
|
||||
Exports a CSV to interface with the Google Sheet. The idea is to bring lineup info into the sheet for backwards compatibility.
|
||||
The row numbers follow each line as comments.
|
||||
:param request:
|
||||
:param event_id:
|
||||
:return: A CSV file.
|
||||
'''
|
||||
response = HttpResponse(
|
||||
content_type='text/csv',
|
||||
headers={'Content-Disposition': f'attachment; filename=lineup-event-{event_id}.csv'},
|
||||
@@ -201,17 +223,17 @@ def csv_export(request, event_id):
|
||||
)
|
||||
|
||||
rows = []
|
||||
|
||||
rows.append(event.teamsnap_event.csv_event_title) # 2
|
||||
rows.append(event.venue.name) # 3
|
||||
[rows.append('') for i in range(3)] #4-6
|
||||
# Row number (starts at row 2)
|
||||
rows.append(event.teamsnap_event.csv_event_title) # 2
|
||||
rows.append(event.venue.name) # 3
|
||||
[rows.append('') for i in range(3)] # 4-6
|
||||
p = qs.filter(position='P').first()
|
||||
if p:
|
||||
rows.append(f"{p.player.last_name}, {p.player.first_name}") #7
|
||||
rows.append(f"{p.player.last_name}, {p.player.first_name}") # 7
|
||||
else:
|
||||
rows.append('')
|
||||
[rows.append('') for i in range(3)] #8-10
|
||||
for pos in ['C', '1B', '2B', '3B', 'SS', 'LF', 'CF', 'RF', 'DH']: #11-19
|
||||
[rows.append('') for i in range(3)] # 8-10
|
||||
for pos in ['C', '1B', '2B', '3B', 'SS', 'LF', 'CF', 'RF', 'DH']: # 11-19
|
||||
p = qs.filter(position=pos).first()
|
||||
if p:
|
||||
rows.append(f"{p.player.last_name}, {p.player.first_name}")
|
||||
@@ -220,22 +242,22 @@ def csv_export(request, event_id):
|
||||
ehs = qs.filter(position='EH')
|
||||
if len(ehs) > 0:
|
||||
p=qs.filter(position='EH')[0]
|
||||
rows.append(f"{p.player.last_name}, {p.player.first_name}") # 20
|
||||
rows.append(f"{p.player.last_name}, {p.player.first_name}") # 20
|
||||
else:
|
||||
rows.append('')
|
||||
if len(ehs) > 1:
|
||||
p=qs.filter(position='EH')[1]
|
||||
rows.append(f"{p.player.last_name}, {p.player.first_name}") # 21
|
||||
rows.append(f"{p.player.last_name}, {p.player.first_name}") # 21
|
||||
else:
|
||||
rows.append('')
|
||||
rows.append('') #22
|
||||
p=qs.filter(position__isnull=False, order=0).first()
|
||||
if p:
|
||||
rows.append(f"{p.player.last_name}, {p.player.first_name}") # 23
|
||||
rows.append(f"{p.player.last_name}, {p.player.first_name}") # 23
|
||||
else:
|
||||
rows.append('')
|
||||
rows.append('')
|
||||
for p in qs.filter(order__gt=0).order_by('order'):
|
||||
rows.append('') # 24
|
||||
for p in qs.filter(order__gt=0).order_by('order'): # 25-34
|
||||
rows.append(f"{p.player.last_name}, {p.player.first_name}")
|
||||
|
||||
writer = csv.writer(response)
|
||||
|
||||
Reference in New Issue
Block a user