Merge branch 'v2-gamecard' into v2
# Conflicts: # config/settings/base.py
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -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 %}
|
||||
|
||||
@@ -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=[
|
||||
|
||||
33
teamsnap/migrations/0004_auto_20220609_0722.py
Normal file
33
teamsnap/migrations/0004_auto_20220609_0722.py
Normal 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'),
|
||||
),
|
||||
]
|
||||
0
teamsnap/migrations/__init__.py
Normal file
0
teamsnap/migrations/__init__.py
Normal 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,
|
||||
)
|
||||
|
||||
14
teamsnap/utils/__init__.py
Normal file
14
teamsnap/utils/__init__.py
Normal 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)
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user