Merge branch 'v2-gamecard' into v2

# Conflicts:
#	config/settings/base.py
This commit is contained in:
2022-06-09 18:46:30 -05:00
100 changed files with 1003 additions and 54 deletions

View File

@@ -1,6 +1,8 @@
from django.contrib import admin
from .models import Preferences
from .models import Opponent, Preferences, Team
# Register your models here.
admin.site.register(Preferences)
admin.site.register(Team)
admin.site.register(Opponent)

View File

@@ -34,7 +34,12 @@
<h6 class="text-muted mb-2">{{ event.data.location_name }}</h6>
</div>
<div class="d-flex">
<a class="btn btn-primary btn-sm mx-1" role="button" href="{% url 'teamsnap_edit_lineup' event_ids=event.data.id team_id=event.data.team_id %}">Go to Lineup</a>
<a class="btn btn-primary btn-sm mx-1" role="button" href="{% url 'teamsnap_edit_lineup' event_ids=event.data.id team_id=event.data.team_id %}">
Go to Lineup
</a>
<a class="btn btn-primary btn-sm mx-1" role="button" href="{% url 'gamecard' event_id=event.data.id team_id=event.data.team_id %}">
<i class="bi bi-book"></i>
</a>
<form method="get"
action="{% url 'instagen_generate' team_id=event.data.team_id event_id=event.data.id %}">
<select hidden class="form-select" name="game_id" id="game_id">
@@ -109,40 +114,40 @@
{% endblock %}
{% block inline_javascript %}
<script>
function donut(ctx, yes_count, maybe_count, no_count, unknown_count) {
var style = getComputedStyle(document.body);
const myChart = new Chart(ctx, {
type: 'doughnut',
responsive: 'true',
data: {
datasets: [{
label: 'Availability',
labels: [
'Yes',
'Maybe',
'No',
'Unknown'
],
data: [yes_count, maybe_count, no_count, unknown_count],
backgroundColor: [
style.getPropertyValue('--bs-success'),
style.getPropertyValue('--bs-info'),
style.getPropertyValue('--bs-danger'),
style.getPropertyValue('--bs-secondary')
],
hoverOffset: 4
}]
},
});
function donut(ctx, yes_count, maybe_count, no_count, unknown_count) {
var style = getComputedStyle(document.body);
const myChart = new Chart(ctx, {
type: 'doughnut',
responsive: 'true',
data: {
datasets: [{
label: 'Availability',
labels: [
'Yes',
'Maybe',
'No',
'Unknown'
],
data: [yes_count, maybe_count, no_count, unknown_count],
backgroundColor: [
style.getPropertyValue('--bs-success'),
style.getPropertyValue('--bs-info'),
style.getPropertyValue('--bs-danger'),
style.getPropertyValue('--bs-secondary')
],
hoverOffset: 4
}]
},
});
}
for (ctx of document.querySelectorAll('.availability-donut')){
donut(ctx,
ctx.dataset.availableYes,
ctx.dataset.availableMaybe,
ctx.dataset.availableNo,
ctx.dataset.availableUnknown,
)
}
</script>
}
for (ctx of document.querySelectorAll('.availability-donut')){
donut(ctx,
ctx.dataset.availableYes,
ctx.dataset.availableMaybe,
ctx.dataset.availableNo,
ctx.dataset.availableUnknown,
)
}
</script>
{% endblock %}

View File

@@ -1,4 +1,4 @@
# Generated by Django 3.2.13 on 2022-06-02 13:20
# Generated by Django 3.2.13 on 2022-06-09 12:09
from django.conf import settings
from django.db import migrations, models
@@ -14,6 +14,14 @@ class Migration(migrations.Migration):
]
operations = [
migrations.CreateModel(
name='Team',
fields=[
('id', models.IntegerField(primary_key=True, serialize=False)),
('logo', models.ImageField(upload_to='logos')),
('logo_mono', models.ImageField(upload_to='logos_mono')),
],
),
migrations.CreateModel(
name="Preferences",
fields=[

View File

@@ -0,0 +1,33 @@
# Generated by Django 3.2.13 on 2022-06-09 12:22
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('teamsnap', '0003_auto_20220609_0721'),
]
operations = [
migrations.AlterField(
model_name='opponent',
name='logo',
field=models.ImageField(blank=True, null=True, upload_to='logos'),
),
migrations.AlterField(
model_name='opponent',
name='logo_mono',
field=models.ImageField(blank=True, null=True, upload_to='logos_mono'),
),
migrations.AlterField(
model_name='team',
name='logo',
field=models.ImageField(blank=True, null=True, upload_to='logos'),
),
migrations.AlterField(
model_name='team',
name='logo_mono',
field=models.ImageField(blank=True, null=True, upload_to='logos_mono'),
),
]

View File

View File

@@ -7,3 +7,43 @@ from benchcoach.users.models import User
class Preferences(models.Model):
user = models.OneToOneField(User, on_delete=models.CASCADE)
managed_team_id = models.IntegerField()
class Team(models.Model):
id = models.IntegerField(primary_key=True)
logo = models.ImageField(
upload_to="logos",
height_field=None,
width_field=None,
max_length=100,
null=True,
blank=True,
)
logo_mono = models.ImageField(
upload_to="logos_mono",
height_field=None,
width_field=None,
max_length=100,
null=True,
blank=True,
)
class Opponent(models.Model):
id = models.IntegerField(primary_key=True)
logo = models.ImageField(
upload_to="logos",
height_field=None,
width_field=None,
max_length=100,
null=True,
blank=True,
)
logo_mono = models.ImageField(
upload_to="logos_mono",
height_field=None,
width_field=None,
max_length=100,
null=True,
blank=True,
)

View File

@@ -0,0 +1,14 @@
import pyteamsnap
def get_teamsnap_client(request):
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
)
return pyteamsnap.api.TeamSnap(token=ts_token)

View File

@@ -1,6 +1,5 @@
import datetime
import pyteamsnap.api
import requests
from allauth.socialaccount.providers.oauth2.views import (
OAuth2Adapter,
@@ -19,6 +18,7 @@ from django.views.generic.edit import FormView
from .forms import PreferencesForm
from .models import Preferences
from .provider import TeamsnapProvider
from .utils import get_teamsnap_client
class TeamsnapAdapter(OAuth2Adapter):
@@ -53,19 +53,6 @@ oauth2_login = OAuth2LoginView.adapter_view(TeamsnapAdapter)
oauth2_callback = OAuth2CallbackView.adapter_view(TeamsnapAdapter)
def get_teamsnap_client(request):
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
)
return pyteamsnap.api.TeamSnap(token=ts_token)
class PreferencesFormView(FormView):
template_name = "preferences.html"
form_class = PreferencesForm
@@ -395,8 +382,7 @@ def submit_lineup(request, team_id, event_id):
try:
r.append(event_lineup_entry.put())
except Exception as e:
e
pass
raise e
pass
elif data.get("sequence") is not None and data.get("label"):
event_lineup_entry = EventLineupEntry.new(client)