diff --git a/config/settings/base.py b/config/settings/base.py index 16a8608..e79480a 100644 --- a/config/settings/base.py +++ b/config/settings/base.py @@ -281,4 +281,3 @@ INSTALLED_APPS += [ "teamsnap.dashboard", ] SOCIALACCOUNT_PROVIDERS = {"teamsnap": {"SCOPE": ["read", "write"]}} -SESSION_SERIALIZER = "django.contrib.sessions.serializers.PickleSerializer" diff --git a/teamsnap/dashboard/views.py b/teamsnap/dashboard/views.py index bcb9d55..13163f1 100644 --- a/teamsnap/dashboard/views.py +++ b/teamsnap/dashboard/views.py @@ -25,7 +25,7 @@ def dashboard(request, team_id=None): team_id=request.user.teamsnap_preferences.managed_team_id, ) - from pyteamsnap.objects import AvailabilitySummary, Event + from pyteamsnap.api import AvailabilitySummary, Event client = get_teamsnap_client(request) ts_events = Event.search(client, team_id=team_id) diff --git a/teamsnap/lineup/views.py b/teamsnap/lineup/views.py index a1bd75b..ae5a8a5 100644 --- a/teamsnap/lineup/views.py +++ b/teamsnap/lineup/views.py @@ -17,7 +17,7 @@ def teamsnap_event_redirect(request, event_id, team_id): def edit_lineup(request, event_ids, team_id): import re - from pyteamsnap.objects import ( + from pyteamsnap.api import ( Availability, AvailabilitySummary, Event, @@ -25,6 +25,7 @@ def edit_lineup(request, event_ids, team_id): EventLineupEntry, Member, ) + from teamsnap.forms import LineupEntryFormset client = get_teamsnap_client(request) @@ -199,7 +200,8 @@ def edit_lineup(request, event_ids, team_id): def submit_lineup(request, team_id, event_id): - from pyteamsnap.objects import Event, EventLineup, EventLineupEntry + from pyteamsnap.api import Event, EventLineup, EventLineupEntry + from teamsnap.forms import LineupEntryFormset client = get_teamsnap_client(request) @@ -258,8 +260,7 @@ def multi_lineup_choose(request, team_id=None): team_id=request.user.teamsnap_preferences.managed_team_id, ) from django.forms import formset_factory - - from pyteamsnap.objects import Event + from pyteamsnap.api import Event from .forms import EventChooseForm diff --git a/teamsnap/utils/__init__.py b/teamsnap/utils/__init__.py index 01add0d..6b31ac6 100644 --- a/teamsnap/utils/__init__.py +++ b/teamsnap/utils/__init__.py @@ -1,26 +1,14 @@ -import logging - -from pyteamsnap.client import TeamSnap - -# This retrieves a Python logging instance (or creates it) -logger = logging.getLogger(__name__) +import pyteamsnap def get_teamsnap_client(request): - client = request.session.get("teamsnap_client") - if client: - logger.info("TeamSnap client found saved in session, loading.") - return client - elif not client: - logger.info("No TeamSnap client saved in session, getting one.") - request.user.socialaccount_set.filter(provider="teamsnap").first() - current_teamsnap_user = request.user.socialaccount_set.filter( - provider="teamsnap" - ).first() + 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 - ) - client = TeamSnap(token=ts_token) - request.session["teamsnap_client"] = client - return client + ts_token = ( + current_teamsnap_user.socialtoken_set.order_by("-expires_at").first().token + ) + + return pyteamsnap.api.TeamSnap(token=ts_token) diff --git a/teamsnap/views.py b/teamsnap/views.py index c5ed20d..8e97d43 100644 --- a/teamsnap/views.py +++ b/teamsnap/views.py @@ -116,7 +116,7 @@ def schedule_view(request, team_id=None): client = get_teamsnap_client(request) no_past = bool(request.GET.get("no_past", 0)) games_only = bool(request.GET.get("games_only", 0)) - from pyteamsnap.objects import Event + from pyteamsnap.api import Event ts_events = Event.search(client, team_id=team_id) if no_past: @@ -143,7 +143,7 @@ def view_event(request, event_id, team_id=None): "teamsnap_event", team_id=request.user.teamsnap_preferences.managed_team_id ) - from pyteamsnap.objects import ( + from pyteamsnap.api import ( AvailabilitySummary, Event, EventLineup, @@ -183,8 +183,7 @@ def view_event(request, event_id, team_id=None): def multi_lineup_choose(request, team_id): from django.forms import formset_factory - - from pyteamsnap.objects import Event + from pyteamsnap.api import Event from .forms import EventChooseForm