updates to use pyteamsnap module

This commit is contained in:
2022-06-28 12:44:02 -05:00
parent 21f46597f8
commit 1f115facb5

View File

@@ -78,17 +78,18 @@ class PreferencesFormView(FormView):
""" """
Returns the initial data to use for forms on this view. Returns the initial data to use for forms on this view.
""" """
import pyteamsnap import pyteamsnap.client
import pyteamsnap.objects
ts_account = self.request.user.socialaccount_set.first() ts_account = self.request.user.socialaccount_set.first()
ts_token = ts_account.socialtoken_set.first() ts_token = ts_account.socialtoken_set.first()
# ts_token = # ts_token =
ts = pyteamsnap.TeamSnap(token=ts_token) ts = pyteamsnap.client.TeamSnap(token=ts_token)
me = pyteamsnap.api.Me(ts) me = pyteamsnap.objects.Me(ts)
teams = [ teams = [
(id, pyteamsnap.api.Team.get(ts, id=id)) (id, pyteamsnap.objects.Team.get(ts, id=id))
for id in me.data["managed_team_ids"] for id in me.data["managed_team_ids"]
] ]
@@ -183,7 +184,6 @@ def view_event(request, event_id, team_id=None):
def multi_lineup_choose(request, team_id): def multi_lineup_choose(request, team_id):
from django.forms import formset_factory from django.forms import formset_factory
from pyteamsnap.objects import Event from pyteamsnap.objects import Event
from .forms import EventChooseForm from .forms import EventChooseForm
@@ -248,13 +248,13 @@ class OpponentFormView(FormView):
def form_valid(self, form): def form_valid(self, form):
# This method is called when valid form data has been POSTed. # This method is called when valid form data has been POSTed.
# It should return an HttpResponse. # It should return an HttpResponse.
import pyteamsnap import pyteamsnap.objects
ts_client = get_teamsnap_client(self.request) ts_client = get_teamsnap_client(self.request)
user = pyteamsnap.api.Me(ts_client) user = pyteamsnap.objects.Me(ts_client)
team_id = int(self.kwargs.get("team_id")) team_id = int(self.kwargs.get("team_id"))
opponent_id = int(self.kwargs.get("opponent_id")) opponent_id = int(self.kwargs.get("opponent_id"))
opponent = pyteamsnap.api.Opponent.get(ts_client, opponent_id) opponent = pyteamsnap.objects.Opponent.get(ts_client, opponent_id)
if ( if (
team_id in user.data["managed_team_ids"] team_id in user.data["managed_team_ids"]
and opponent.data["team_id"] == team_id and opponent.data["team_id"] == team_id