clean up for linters

This commit is contained in:
2022-06-07 19:50:46 -05:00
parent 42d5c452e7
commit 8093d8288e
9 changed files with 78 additions and 82 deletions

View File

@@ -23,7 +23,7 @@ def _update_or_create_site_with_sequence(site_model, connection, domain, name):
# site is created. # site is created.
# To avoid this, we need to manually update DB sequence and make sure it's # To avoid this, we need to manually update DB sequence and make sure it's
# greater than the maximum value. # greater than the maximum value.
max_id = site_model.objects.order_by('-id').first().id max_id = site_model.objects.order_by("-id").first().id
with connection.cursor() as cursor: with connection.cursor() as cursor:
cursor.execute("SELECT last_value from django_site_id_seq") cursor.execute("SELECT last_value from django_site_id_seq")
(current_id,) = cursor.fetchone() (current_id,) = cursor.fetchone()

View File

@@ -273,8 +273,4 @@ SOCIALACCOUNT_FORMS = {"signup": "benchcoach.users.forms.UserSocialSignupForm"}
# Your stuff... # Your stuff...
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
INSTALLED_APPS += ["teamsnap", "instagen"] INSTALLED_APPS += ["teamsnap", "instagen"]
SOCIALACCOUNT_PROVIDERS = { SOCIALACCOUNT_PROVIDERS = {"teamsnap": {"SCOPE": ["read", "write"]}}
'teamsnap': {
'SCOPE': ["read", "write"]
}
}

View File

@@ -64,7 +64,14 @@ INSTALLED_APPS += ["django_extensions"] # noqa F405
# Your stuff... # Your stuff...
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
ALLOWED_HOSTS += ["localhost", "0.0.0.0", "127.0.0.1", "asc-nas.local", "10.0.1.4", "benchcoach-dev.ascorrea.com"] ALLOWED_HOSTS += [
"localhost",
"0.0.0.0",
"127.0.0.1",
"asc-nas.local",
"10.0.1.4",
"benchcoach-dev.ascorrea.com",
]
ACCOUNT_AUTHENTICATION_METHOD = "email" ACCOUNT_AUTHENTICATION_METHOD = "email"
ACCOUNT_EMAIL_REQUIRED = True ACCOUNT_EMAIL_REQUIRED = True
ACCOUNT_USERNAME_REQUIRED = False ACCOUNT_USERNAME_REQUIRED = False

View File

@@ -12,6 +12,7 @@
import os import os
import sys import sys
import django import django
if os.getenv("READTHEDOCS", default=False) == "True": if os.getenv("READTHEDOCS", default=False) == "True":

View File

@@ -2,10 +2,8 @@ import os
from dataclasses import dataclass from dataclasses import dataclass
from datetime import datetime from datetime import datetime
from pathlib import Path from pathlib import Path
from typing import List
from zoneinfo import ZoneInfo
from PIL import Image, ImageDraw, ImageFilter, ImageFont from PIL import Image, ImageDraw, ImageFont
# image_directory = 'input/images/logos-bw/{filename}.{ext}' # image_directory = 'input/images/logos-bw/{filename}.{ext}'
@@ -115,19 +113,6 @@ def gen_image(
# transparent color. # transparent color.
tmp = Image.new("RGBA", background_image.size, (0, 0, 0, 0)) tmp = Image.new("RGBA", background_image.size, (0, 0, 0, 0))
# Create a drawing context for it.
draw = ImageDraw.Draw(tmp)
# section margin describes the margin of the section rectangles from the sides of the image
section_margin_pct = 0.05
llx = int(section_margin_pct * background_image.size[0])
urx = int((1 - section_margin_pct) * background_image.size[0])
lly = int((1 - section_margin_pct) * background_image.size[1])
ury = int(0.50 * background_image.size[1])
lly2 = int(0.49 * background_image.size[1])
ury2 = int(0.05 * background_image.size[1])
section_info = Image.open( section_info = Image.open(
Path( Path(
"instagen/static/instagen/graphics/{name}{ext}".format( "instagen/static/instagen/graphics/{name}{ext}".format(
@@ -150,7 +135,6 @@ def gen_image(
font = ImageFont.truetype(font_regular_path, 62) font = ImageFont.truetype(font_regular_path, 62)
text = f"{date:%a, %B %-d %-I:%M %p}".upper() text = f"{date:%a, %B %-d %-I:%M %p}".upper()
# text = date # text = date
text_size = draw.textsize(text, font)
loc = (1050, 280) loc = (1050, 280)
section_info_draw.text(loc, text, (14, 42, 28), font=font, anchor="ra") section_info_draw.text(loc, text, (14, 42, 28), font=font, anchor="ra")
@@ -160,7 +144,6 @@ def gen_image(
text = location.name.upper() text = location.name.upper()
else: else:
text = location_name.upper() text = location_name.upper()
text_size = section_info_draw.textsize(text, font)
loc = (1050, 355) loc = (1050, 355)
section_info_draw.text(loc, text, (14, 42, 28), font=font, anchor="ra") section_info_draw.text(loc, text, (14, 42, 28), font=font, anchor="ra")
@@ -169,7 +152,6 @@ def gen_image(
text = "VS" text = "VS"
else: else:
text = "AT" text = "AT"
text_size = section_title_draw.textsize(text, font)
loc = (540, 120) loc = (540, 120)
color = (255, 255, 255) color = (255, 255, 255)
section_title_draw.text(loc, text, color, font=font, anchor="mm") section_title_draw.text(loc, text, color, font=font, anchor="mm")
@@ -249,19 +231,6 @@ def gen_results_image(
# transparent color. # transparent color.
tmp = Image.new("RGBA", background_image.size, (0, 0, 0, 0)) tmp = Image.new("RGBA", background_image.size, (0, 0, 0, 0))
# Create a drawing context for it.
draw = ImageDraw.Draw(tmp)
# section margin describes the margin of the section rectangles from the sides of the image
section_margin_pct = 0.05
llx = int(section_margin_pct * background_image.size[0])
urx = int((1 - section_margin_pct) * background_image.size[0])
lly = int((1 - section_margin_pct) * background_image.size[1])
ury = int(0.50 * background_image.size[1])
lly2 = int(0.49 * background_image.size[1])
ury2 = int(0.05 * background_image.size[1])
section_info = Image.open( section_info = Image.open(
Path( Path(
"instagen/static/instagen/graphics/{name}{ext}".format( "instagen/static/instagen/graphics/{name}{ext}".format(
@@ -301,7 +270,6 @@ def gen_results_image(
text = f"{date:%a, %B %-d %-I:%M %p}".upper() text = f"{date:%a, %B %-d %-I:%M %p}".upper()
# text = date # text = date
font = ImageFont.truetype(font_condensed_path, 34) font = ImageFont.truetype(font_condensed_path, 34)
text_size = section_info_draw.textsize(text, font)
loc = (1050, 355) loc = (1050, 355)
section_info_draw.text(loc, text, (14, 42, 28), font=font, anchor="ra") section_info_draw.text(loc, text, (14, 42, 28), font=font, anchor="ra")
@@ -310,7 +278,6 @@ def gen_results_image(
text = "VS" text = "VS"
else: else:
text = "AT" text = "AT"
text_size = section_title_draw.textsize(text, font)
loc = (540, 120) loc = (540, 120)
color = (255, 255, 255) color = (255, 255, 255)
section_title_draw.text(loc, text, color, font=font, anchor="mm") section_title_draw.text(loc, text, color, font=font, anchor="mm")

View File

@@ -1,6 +1,7 @@
[flake8] [flake8]
max-line-length = 120 max-line-length = 120
exclude = .tox,.git,*/migrations/*,*/static/CACHE/*,docs,node_modules,venv exclude = .tox,.git,*/migrations/*,*/static/CACHE/*,docs,node_modules,venv
ignore = W503
[pycodestyle] [pycodestyle]
max-line-length = 120 max-line-length = 120

View File

@@ -15,11 +15,25 @@ class Migration(migrations.Migration):
operations = [ operations = [
migrations.CreateModel( migrations.CreateModel(
name='Preferences', name="Preferences",
fields=[ fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), (
('managed_team_id', models.IntegerField()), "id",
('user', models.OneToOneField(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)), models.BigAutoField(
auto_created=True,
primary_key=True,
serialize=False,
verbose_name="ID",
),
),
("managed_team_id", models.IntegerField()),
(
"user",
models.OneToOneField(
on_delete=django.db.models.deletion.CASCADE,
to=settings.AUTH_USER_MODEL,
),
),
], ],
), ),
] ]

View File

@@ -7,8 +7,8 @@ from .views import (
dashboard, dashboard,
edit_lineup, edit_lineup,
schedule_view, schedule_view,
submit_lineup,
view_event, view_event,
submit_lineup
) )
urlpatterns = default_urlpatterns(TeamsnapProvider) urlpatterns = default_urlpatterns(TeamsnapProvider)
@@ -30,12 +30,13 @@ urlpatterns += [
name="teamsnap_edit_lineup", name="teamsnap_edit_lineup",
), ),
path( path(
'<int:team_id>/event/<int:event_id>/submit_lineup/', "<int:team_id>/event/<int:event_id>/submit_lineup/",
submit_lineup, submit_lineup,
name='teamsnap_submit_lineup' name="teamsnap_submit_lineup",
),
path(
"<int:team_id>/event/<str:event_ids>/edit_lineup/",
edit_lineup,
name="teamsnap_edit_multiple_lineups",
), ),
path('<int:team_id>/event/<str:event_ids>/edit_lineup/',
edit_lineup,
name='teamsnap_edit_multiple_lineups'
),
] ]

View File

@@ -1,19 +1,20 @@
import datetime import datetime
import pyteamsnap.api
import requests import requests
from allauth.socialaccount.providers.oauth2.views import ( from allauth.socialaccount.providers.oauth2.views import (
OAuth2Adapter, OAuth2Adapter,
OAuth2CallbackView, OAuth2CallbackView,
OAuth2LoginView, OAuth2LoginView,
) )
from django.http import HttpResponseNotAllowed, HttpResponseServerError, JsonResponse
from django.shortcuts import redirect, render from django.shortcuts import redirect, render
from django.views.generic.edit import FormView from django.views.generic.edit import FormView
from django.http import HttpResponseNotAllowed, HttpResponse, JsonResponse, HttpResponseServerError
from .forms import PreferencesForm from .forms import PreferencesForm
from .models import Preferences from .models import Preferences
from .provider import TeamsnapProvider from .provider import TeamsnapProvider
import pyteamsnap.api
class TeamsnapAdapter(OAuth2Adapter): class TeamsnapAdapter(OAuth2Adapter):
provider_id = TeamsnapProvider.id provider_id = TeamsnapProvider.id
@@ -46,6 +47,7 @@ class TeamsnapAdapter(OAuth2Adapter):
oauth2_login = OAuth2LoginView.adapter_view(TeamsnapAdapter) oauth2_login = OAuth2LoginView.adapter_view(TeamsnapAdapter)
oauth2_callback = OAuth2CallbackView.adapter_view(TeamsnapAdapter) oauth2_callback = OAuth2CallbackView.adapter_view(TeamsnapAdapter)
def get_teamsnap_client(request): def get_teamsnap_client(request):
request.user.socialaccount_set.filter(provider="teamsnap").first() request.user.socialaccount_set.filter(provider="teamsnap").first()
current_teamsnap_user = request.user.socialaccount_set.filter( current_teamsnap_user = request.user.socialaccount_set.filter(
@@ -58,6 +60,7 @@ def get_teamsnap_client(request):
return pyteamsnap.api.TeamSnap(token=ts_token) return pyteamsnap.api.TeamSnap(token=ts_token)
class PreferencesFormView(FormView): class PreferencesFormView(FormView):
template_name = "preferences.html" template_name = "preferences.html"
form_class = PreferencesForm form_class = PreferencesForm
@@ -190,8 +193,6 @@ def view_event(request, event_id, team_id=None):
def edit_lineup(request, event_ids, team_id): def edit_lineup(request, event_ids, team_id):
import re import re
from teamsnap.forms import LineupEntryFormset
from pyteamsnap.api import ( from pyteamsnap.api import (
Availability, Availability,
AvailabilitySummary, AvailabilitySummary,
@@ -199,9 +200,10 @@ def edit_lineup(request, event_ids, team_id):
EventLineup, EventLineup,
EventLineupEntry, EventLineupEntry,
Member, Member,
TeamSnap,
) )
from teamsnap.forms import LineupEntryFormset
client = get_teamsnap_client(request) client = get_teamsnap_client(request)
event_ids = str(event_ids).split(",") event_ids = str(event_ids).split(",")
@@ -231,28 +233,34 @@ def edit_lineup(request, event_ids, team_id):
for lineup_entry in ts_lineup_entries: for lineup_entry in ts_lineup_entries:
members.append( members.append(
{ {
"member": getattr(ts_member_lookup[lineup_entry.data['member_id']],'data'), "member": getattr(
ts_member_lookup[lineup_entry.data["member_id"]], "data"
),
"availability": getattr( "availability": getattr(
ts_availability_lookup.get(lineup_entry.data['member_id'], {}), "data", {} ts_availability_lookup.get(lineup_entry.data["member_id"], {}),
), "data",
"lineup_entry": getattr( {},
lineup_entry, "data", {}
), ),
"lineup_entry": getattr(lineup_entry, "data", {}),
} }
) )
in_lineup_already = [m['member'] for m in members] in_lineup_already = [m["member"] for m in members]
for member in ts_members: for member in ts_members:
if not member.data in in_lineup_already: if member.data not in in_lineup_already:
members.append( members.append(
{ {
"member": getattr(member, "data"), "member": getattr(member, "data"),
"availability": getattr( "availability": getattr(
ts_availability_lookup.get(member.data["id"], {}), "data", {} ts_availability_lookup.get(member.data["id"], {}),
"data",
{},
), ),
"lineup_entry": getattr( "lineup_entry": getattr(
ts_lineup_entries_lookup.get(member.data["id"], {}), "data", {} ts_lineup_entries_lookup.get(member.data["id"], {}),
"data",
{},
), ),
} }
) )
@@ -346,9 +354,7 @@ def edit_lineup(request, event_ids, team_id):
} }
) )
return render( return render(request, "lineup/multiple_edit.html", context={"contexts": contexts})
request, "lineup/multiple_edit.html", context={"contexts": contexts}
)
def dashboard(request, team_id=None): def dashboard(request, team_id=None):
@@ -389,14 +395,14 @@ def dashboard(request, team_id=None):
def submit_lineup(request, team_id, event_id): def submit_lineup(request, team_id, event_id):
from pyteamsnap.api import Event, EventLineup, EventLineupEntry
from teamsnap.forms import LineupEntryFormset from teamsnap.forms import LineupEntryFormset
from pyteamsnap.api import EventLineup, TeamSnap, EventLineupEntry, Event
client = get_teamsnap_client(request) client = get_teamsnap_client(request)
ts_event = Event.get(client,event_id) ts_event = Event.get(client, event_id)
ts_lineup = EventLineup.search(client, event_id=event_id) ts_lineup = EventLineup.search(client, event_id=event_id)
event_lineup_id = ts_lineup[0].data['id'] event_lineup_id = ts_lineup[0].data["id"]
if request.GET: if request.GET:
return HttpResponseNotAllowed() return HttpResponseNotAllowed()
if request.POST: if request.POST:
@@ -405,12 +411,14 @@ def submit_lineup(request, team_id, event_id):
r = [] r = []
for form in formset: for form in formset:
data = form.cleaned_data data = form.cleaned_data
if data.get('event_lineup_entry_id'): if data.get("event_lineup_entry_id"):
event_lineup_entry = EventLineupEntry.get(client, id=data.get('event_lineup_entry_id')) event_lineup_entry = EventLineupEntry.get(
if data.get('position_only'): client, id=data.get("event_lineup_entry_id")
data['label'] = data['label'] + ' [PO]' )
if data.get("position_only"):
data["label"] = data["label"] + " [PO]"
event_lineup_entry.data.update(data) event_lineup_entry.data.update(data)
if not data.get('sequence') and not data.get('label'): if not data.get("sequence") and not data.get("label"):
try: try:
r.append(event_lineup_entry.delete()) r.append(event_lineup_entry.delete())
except Exception as e: except Exception as e:
@@ -418,13 +426,14 @@ def submit_lineup(request, team_id, event_id):
else: else:
try: try:
r.append(event_lineup_entry.put()) r.append(event_lineup_entry.put())
except: except Exception as e:
e
pass pass
pass pass
elif data.get('sequence') is not None and data.get('label'): elif data.get("sequence") is not None and data.get("label"):
event_lineup_entry = EventLineupEntry.new(client) event_lineup_entry = EventLineupEntry.new(client)
if data.get('position_only'): if data.get("position_only"):
data['label'] = data['label'] + ' [PO]' data["label"] = data["label"] + " [PO]"
event_lineup_entry.data.update(data) event_lineup_entry.data.update(data)
event_lineup_entry.data.update({"event_lineup_id": event_lineup_id}) event_lineup_entry.data.update({"event_lineup_id": event_lineup_id})
try: try: