add schedule, view_event
This commit is contained in:
@@ -11,3 +11,7 @@
|
||||
background-color: #f2dede;
|
||||
border-color: #eed3d7;
|
||||
}
|
||||
|
||||
.navbar-brand {
|
||||
text-transform: uppercase;
|
||||
}
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
<!-- Latest compiled and minified Bootstrap CSS -->
|
||||
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap/5.1.3/css/bootstrap.min.css" integrity="sha512-GQGU0fMMi238uA+a/bdWJfpUGKUkBdgfFdgBm72SUQ6BeyWjoY/ton0tEjH+OSH9iP4Dfh+7HM0I9f5eR0L/4w==" crossorigin="anonymous" referrerpolicy="no-referrer" />
|
||||
<!-- Your stuff: Third-party CSS libraries go here -->
|
||||
|
||||
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.8.2/font/bootstrap-icons.css">
|
||||
<!-- This file stores project-specific CSS -->
|
||||
<link href="{% static 'css/project.css' %}" rel="stylesheet">
|
||||
{% endblock %}
|
||||
@@ -37,7 +37,7 @@
|
||||
<body>
|
||||
|
||||
<div class="mb-1">
|
||||
<nav class="navbar navbar-expand-md navbar-light bg-light">
|
||||
<nav class="navbar navbar-expand-md navbar-dark bg-dark">
|
||||
<div class="container-fluid">
|
||||
<button class="navbar-toggler navbar-toggler-right" type="button" data-bs-toggle="collapse" data-bs-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
|
||||
<span class="navbar-toggler-icon"></span>
|
||||
@@ -57,6 +57,9 @@
|
||||
{# URL provided by django-allauth/account/urls.py #}
|
||||
<a class="nav-link" href="{% url 'users:detail' request.user.username %}">{% translate "My Profile" %}</a>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<a class="nav-link" href="{% url 'teamsnap_schedule' %}">{% translate "Schedule" %}</a>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
{# URL provided by django-allauth/account/urls.py #}
|
||||
<a class="nav-link" href="{% url 'account_logout' %}">{% translate "Sign Out" %}</a>
|
||||
@@ -67,12 +70,16 @@
|
||||
{# URL provided by django-allauth/account/urls.py #}
|
||||
<a id="sign-up-link" class="nav-link" href="{% url 'account_signup' %}">{% translate "Sign Up" %}</a>
|
||||
</li>
|
||||
|
||||
{% endif %}
|
||||
<li class="nav-item">
|
||||
{# URL provided by django-allauth/account/urls.py #}
|
||||
<a id="log-in-link" class="nav-link" href="{% url 'account_login' %}">{% translate "Sign In" %}</a>
|
||||
</li>
|
||||
|
||||
|
||||
{% endif %}
|
||||
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -4,12 +4,9 @@ from django.contrib.auth import get_user_model
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
|
||||
from benchcoach.users.forms import UserAdminChangeForm, UserAdminCreationForm
|
||||
from teamsnap.models import Preferences
|
||||
|
||||
User = get_user_model()
|
||||
|
||||
admin.site.register(Preferences)
|
||||
|
||||
|
||||
@admin.register(User)
|
||||
class UserAdmin(auth_admin.UserAdmin):
|
||||
|
||||
@@ -15,7 +15,7 @@ urlpatterns = [
|
||||
# User management
|
||||
path("users/", include("benchcoach.users.urls", namespace="users")),
|
||||
path("accounts/", include("allauth.urls")),
|
||||
path("ts/", include("teamsnap.urls")),
|
||||
path("", include("teamsnap.urls")),
|
||||
] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
|
||||
|
||||
|
||||
|
||||
@@ -1 +1,6 @@
|
||||
from django.contrib import admin
|
||||
|
||||
from .models import Preferences
|
||||
|
||||
# Register your models here.
|
||||
admin.site.register(Preferences)
|
||||
|
||||
76
teamsnap/templates/event/instagen.html
Normal file
76
teamsnap/templates/event/instagen.html
Normal file
@@ -0,0 +1,76 @@
|
||||
<html lang="en">
|
||||
{% extends "base.html" %}{% load static %}
|
||||
{% block title %} {{ event.data.formatted_title }} - Instagenerator{% endblock %}
|
||||
{% block page_heading %}
|
||||
<div class="row d-inline-flex">
|
||||
<div class="col">
|
||||
<img src="{% static 'teamsnap/ig/graphics/hounds-insta.jpg' %}" class="mx-auto d-block img-fluid shadow-sm" style="height:30px;border-radius: 8px;">
|
||||
</div>
|
||||
<div class="col text-nowrap px-0">Hounds Instagenerator</div>
|
||||
</div>
|
||||
{% endblock %}
|
||||
{% block page_subheading %}{{ event.data.formatted_title }}, {{ event.data.start_date }}, {{ event.data.location_name }}{% endblock %}
|
||||
{% block content %}
|
||||
|
||||
<form method="get" action="generate">
|
||||
|
||||
<div class="mb-3">
|
||||
<select hidden class="form-select" name="game_id" id="game_id">
|
||||
<optgroup label="Events">
|
||||
<option value="" disabled="disabled">Select an event...</option>
|
||||
<option selected value="{{event.data.id}}">{{event.data.formatted_title}}</option>
|
||||
</optgroup>
|
||||
</select>
|
||||
</div>
|
||||
|
||||
<div class="mb-3">
|
||||
<legend class="">Background</legend>
|
||||
<div class="form-check">
|
||||
<input class="form-check-input" type="radio" name="background" id="backgroundLocation" checked value="location">
|
||||
<label class="form-check-label" for="backgroundLocation">
|
||||
Location
|
||||
</label>
|
||||
</div>
|
||||
|
||||
<div class="form-check">
|
||||
<input class="form-check-input" type="radio" name="background" id="backgroundTransparent" value="transparent">
|
||||
<label class="form-check-label" for="backgroundTransparent">
|
||||
Transparent
|
||||
</label>
|
||||
</div>
|
||||
<div class="form-check">
|
||||
<input class="form-check-input" type="radio" name="background" id="badge_only" value="badge">
|
||||
<label class="form-check-label" for="badge_only">
|
||||
Badge only
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="mb-3">
|
||||
<legend class="">Layout</legend>
|
||||
<div class="form-check">
|
||||
<input class="form-check-input" type="radio" name="dimensions" id="square" checked value="1080x1080">
|
||||
<label class="form-check-label" for="square">
|
||||
Square
|
||||
</label>
|
||||
</div>
|
||||
<div class="form-check">
|
||||
<input class="form-check-input" type="radio" name="dimensions" id="portrait" value="1080x1920">
|
||||
<label class="form-check-label" for="portrait">
|
||||
Portrait
|
||||
</label>
|
||||
</div>
|
||||
<div class="form-check">
|
||||
<input class="form-check-input" type="radio" name="dimensions" id="portrait" value="1920x1080">
|
||||
<label class="form-check-label" for="portrait">
|
||||
Landscape
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="d-lg-flex justify-content-lg-end align-items-lg-center mb-3">
|
||||
<button type="submit" class="btn btn-primary btn-block">Get Image</button>
|
||||
</div>
|
||||
</form>
|
||||
|
||||
{% endblock %}
|
||||
144
teamsnap/templates/event/view_event.html
Normal file
144
teamsnap/templates/event/view_event.html
Normal file
@@ -0,0 +1,144 @@
|
||||
{% extends "base.html" %}{% load static %}
|
||||
{% block title %} {{ title }}{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
<div class="card mx-auto" style="max-width: 455px">
|
||||
<div class="border-bottom p-2">
|
||||
<h4 class="card-title text-nowrap">{{ event.data.formatted_title }}</h4>
|
||||
<h6 class="text-muted card-subtitle text-nowrap">{{ event.data.start_date|date:"D, F j, Y g:i A" }}</h6>
|
||||
|
||||
<div class="row">
|
||||
<div class="col text-end">
|
||||
{# <form method="get"#}
|
||||
{# action="{% url "teamsnap_image_generator_generate" team_id=request.user.teamsnapsettings.managed_team.id event_id=event.data.id %}">#}
|
||||
{# <select hidden class="form-select" name="game_id" id="game_id">#}
|
||||
{# <optgroup label="Events">#}
|
||||
{# <option value="" disabled="disabled">Select an event...</option>#}
|
||||
{# <option selected#}
|
||||
{# value="{{ event.data.id }}">{{ event.data.formatted_title }}</option>#}
|
||||
{# </optgroup>#}
|
||||
{# </select>#}
|
||||
{# <input hidden class="form-check-input" type="radio" name="background"#}
|
||||
{# id="backgroundLocation" checked value="location">#}
|
||||
{# <input hidden class="form-check-input" type="radio" name="dimensions" id="square" checked#}
|
||||
{# value="1080x1080">#}
|
||||
{# <button type="submit" class="btn btn-primary btn-sm py-0 m-1"><i class="bi bi-instagram"></i>#}
|
||||
{# </button>#}
|
||||
{# </form>#}
|
||||
{# <a class="btn btn-primary btn-sm py-0 m-1"#}
|
||||
{# href="{% url "teamsnap_image_generator" team_id=request.user.teamsnapsettings.managed_team.id event_id=event.data.id %}"#}
|
||||
{# role="button">#}
|
||||
{# <div class="d-inline-block"><i class="bi bi-instagram"></i> <i class="bi bi-three-dots"></i>#}
|
||||
{# </div>#}
|
||||
{# </a>#}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="card-body p-0 m-0">
|
||||
<div>
|
||||
<div class="row m-0">
|
||||
<div class="col border-bottom bg-light">
|
||||
<span class="text-uppercase fw-bold small"></span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="row m-0">
|
||||
<div class="table-responsive p-0">
|
||||
<table class="table table-sm">
|
||||
{# <thead>#}
|
||||
{# </thead>#}
|
||||
<tbody>
|
||||
<tr>
|
||||
<th scope="col">
|
||||
Date
|
||||
</th>
|
||||
<td>
|
||||
{{ event.data.start_date|date:"D, F j, Y g:i A" }}
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th scope="col">
|
||||
Opponent
|
||||
</th>
|
||||
<td>
|
||||
<a href="">{{ event.data.opponent_name }}</a>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th scope="col">
|
||||
Location
|
||||
</th>
|
||||
<td>
|
||||
<a href="">{{ event.data.location_name }}</a>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<div class="row m-0">
|
||||
<div class="col border-bottom border-top bg-light">
|
||||
<span class="text-uppercase fw-bold small">Availabilities</span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="row m-0">
|
||||
<div class="table-responsive p-0">
|
||||
<table class="table table-sm">
|
||||
|
||||
<tbody>
|
||||
<tr>
|
||||
<th scope="col" class="col-1">
|
||||
<i class="bi bi-check-circle-fill text-success"></i>
|
||||
</th>
|
||||
<td>
|
||||
{{ availability_summary.data.player_going_count }}
|
||||
</td>
|
||||
|
||||
<th scope="col" class="col-1">
|
||||
<i class="bi bi-question-circle-fill text-info"></i>
|
||||
</th>
|
||||
<td>
|
||||
{{ availability_summary.data.player_maybe_count }}
|
||||
</td>
|
||||
|
||||
<th scope="col" class="col-1">
|
||||
<i class="bi bi-x-circle-fill text-danger"></i>
|
||||
</th>
|
||||
<td>
|
||||
{{ availability_summary.data.player_not_going_count }}
|
||||
</td>
|
||||
|
||||
<th scope="col" class="col-1">
|
||||
<i class="bi bi-question-circle"></i>
|
||||
</th>
|
||||
<td>
|
||||
{{ availability_summary.data.player_unknown_count }}
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<div class="row m-0">
|
||||
<div class="col border-bottom border-top bg-light">
|
||||
<span class="text-uppercase fw-bold small">Lineup</span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="row m-0">
|
||||
<div class="flex-column m-2">
|
||||
<a class="btn btn-primary btn-sm"
|
||||
href=""
|
||||
role="button">Edit</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{% endblock %}
|
||||
@@ -35,7 +35,7 @@
|
||||
{{ event.data.location_name }}
|
||||
</td>
|
||||
<td>
|
||||
<a class="btn btn-outline-secondary btn-sm" href=""><i class="bi bi-three-dots"></i></a>
|
||||
<a class="btn btn-outline-secondary btn-sm" href="{% url 'teamsnap_view_event' team_id=event.data.team_id event_id=event.data.id %}"><i class="bi bi-three-dots"></i></a>
|
||||
</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
|
||||
@@ -2,8 +2,17 @@ from allauth.socialaccount.providers.oauth2.urls import default_urlpatterns
|
||||
from django.urls import path
|
||||
|
||||
from .provider import TeamsnapProvider
|
||||
from .views import PreferencesFormView
|
||||
from .views import PreferencesFormView, schedule_view, view_event
|
||||
|
||||
urlpatterns = default_urlpatterns(TeamsnapProvider)
|
||||
|
||||
urlpatterns += [path("preferences", PreferencesFormView.as_view(), name="preferences")]
|
||||
urlpatterns += [
|
||||
path("preferences/", PreferencesFormView.as_view(), name="preferences"),
|
||||
path("<int:team_id>/schedule/", schedule_view, name="teamsnap_schedule"),
|
||||
path("schedule/", schedule_view, name="teamsnap_schedule"),
|
||||
path(
|
||||
"<int:team_id>/schedule/view_event/<int:event_id>",
|
||||
view_event,
|
||||
name="teamsnap_view_event",
|
||||
),
|
||||
]
|
||||
|
||||
@@ -1,9 +1,12 @@
|
||||
import datetime
|
||||
|
||||
import requests
|
||||
from allauth.socialaccount.providers.oauth2.views import (
|
||||
OAuth2Adapter,
|
||||
OAuth2CallbackView,
|
||||
OAuth2LoginView,
|
||||
)
|
||||
from django.shortcuts import redirect, render
|
||||
from django.views.generic.edit import FormView
|
||||
|
||||
from .forms import PreferencesForm
|
||||
@@ -103,3 +106,93 @@ class PreferencesFormView(FormView):
|
||||
form.fields["managed_team_id"].widget.choices = choices
|
||||
|
||||
return form
|
||||
|
||||
|
||||
def schedule_view(request, team_id=None):
|
||||
if not team_id:
|
||||
return redirect(
|
||||
"teamsnap_schedule", team_id=request.user.preferences.managed_team_id
|
||||
)
|
||||
request.user.socialaccount_set.filter(provider="teamsnap").first()
|
||||
current_teamsnap_user = request.user.socialaccount_set.filter(
|
||||
provider="teamsnap"
|
||||
).first()
|
||||
|
||||
ts_token = (
|
||||
current_teamsnap_user.socialtoken_set.order_by("-expires_at").first().token
|
||||
)
|
||||
no_past = bool(request.GET.get("no_past", 0))
|
||||
games_only = bool(request.GET.get("games_only", 0))
|
||||
from pyteamsnap.api import Event, TeamSnap
|
||||
|
||||
client = TeamSnap(token=ts_token)
|
||||
ts_events = Event.search(client, team_id=team_id)
|
||||
if no_past:
|
||||
ts_events = [
|
||||
e
|
||||
for e in ts_events
|
||||
if e.data["start_date"] > datetime.datetime.now(datetime.timezone.utc)
|
||||
]
|
||||
if games_only:
|
||||
ts_events = [e for e in ts_events if e.data["is_game"]]
|
||||
ts_events = {e.data["id"]: e for e in ts_events}
|
||||
|
||||
pass
|
||||
return render(
|
||||
request,
|
||||
"schedule.html",
|
||||
context={"events": ts_events.values(), "team_id": team_id},
|
||||
)
|
||||
|
||||
|
||||
def view_event(request, event_id, team_id=None):
|
||||
if not team_id:
|
||||
return redirect(
|
||||
"teamsnap_event", team_id=request.user.preferences.managed_team_id
|
||||
)
|
||||
request.user.socialaccount_set.filter(provider="teamsnap").first()
|
||||
current_teamsnap_user = request.user.socialaccount_set.filter(
|
||||
provider="teamsnap"
|
||||
).first()
|
||||
|
||||
ts_token = (
|
||||
current_teamsnap_user.socialtoken_set.order_by("-expires_at").first().token
|
||||
)
|
||||
|
||||
from pyteamsnap.api import (
|
||||
AvailabilitySummary,
|
||||
Event,
|
||||
EventLineup,
|
||||
EventLineupEntry,
|
||||
Member,
|
||||
TeamSnap,
|
||||
)
|
||||
|
||||
client = TeamSnap(token=ts_token)
|
||||
ts_bulkload = client.bulk_load(
|
||||
team_id=team_id,
|
||||
types=[Event, EventLineup, EventLineupEntry, AvailabilitySummary, Member],
|
||||
event__id=event_id,
|
||||
)
|
||||
ts_event = [i for i in ts_bulkload if isinstance(i, Event)][0]
|
||||
ts_availability_summary = [
|
||||
i
|
||||
for i in ts_bulkload
|
||||
if isinstance(i, AvailabilitySummary) and i.data["event_id"] == event_id
|
||||
][0]
|
||||
ts_lineup_entries = [
|
||||
i
|
||||
for i in ts_bulkload
|
||||
if isinstance(i, EventLineupEntry) and i.data["event_id"] == event_id
|
||||
]
|
||||
|
||||
return render(
|
||||
request,
|
||||
"event/view_event.html",
|
||||
context={
|
||||
"availability_summary": ts_availability_summary,
|
||||
"event": ts_event,
|
||||
"availablities": [],
|
||||
"lineup_entries": ts_lineup_entries,
|
||||
},
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user