diff --git a/.idea/runConfigurations/runserver_plus.xml b/.idea/runConfigurations/runserver_plus.xml
index cae6ab1..47811a3 100644
--- a/.idea/runConfigurations/runserver_plus.xml
+++ b/.idea/runConfigurations/runserver_plus.xml
@@ -14,7 +14,7 @@
-
+
@@ -25,4 +25,4 @@
-
+
\ No newline at end of file
diff --git a/config/settings/base.py b/config/settings/base.py
index 2ed7583..d0da613 100644
--- a/config/settings/base.py
+++ b/config/settings/base.py
@@ -273,3 +273,8 @@ SOCIALACCOUNT_FORMS = {"signup": "benchcoach.users.forms.UserSocialSignupForm"}
# Your stuff...
# ------------------------------------------------------------------------------
INSTALLED_APPS += ["teamsnap", "instagen"]
+SOCIALACCOUNT_PROVIDERS = {
+ 'teamsnap': {
+ 'SCOPE': ["read", "write"]
+ }
+}
diff --git a/teamsnap/templates/lineup/multiple_edit.html b/teamsnap/templates/lineup/multiple_edit.html
index 56387db..006fd4d 100644
--- a/teamsnap/templates/lineup/multiple_edit.html
+++ b/teamsnap/templates/lineup/multiple_edit.html
@@ -18,11 +18,14 @@
{# #}
{# #}
-
-
+
+{% endblock %}
+
+{% block inline_javascript %}
+ {{ block.super }}
+
+
+
+
{% endblock %}
diff --git a/teamsnap/templates/lineup/widgets/lineup.html b/teamsnap/templates/lineup/widgets/lineup.html
index dae1975..41cc336 100644
--- a/teamsnap/templates/lineup/widgets/lineup.html
+++ b/teamsnap/templates/lineup/widgets/lineup.html
@@ -1,5 +1,5 @@
diff --git a/teamsnap/urls.py b/teamsnap/urls.py
index 14c89a1..55b08b6 100644
--- a/teamsnap/urls.py
+++ b/teamsnap/urls.py
@@ -8,6 +8,7 @@ from .views import (
edit_lineup,
schedule_view,
view_event,
+ submit_lineup
)
urlpatterns = default_urlpatterns(TeamsnapProvider)
@@ -28,4 +29,13 @@ urlpatterns += [
edit_lineup,
name="teamsnap_edit_lineup",
),
+ path(
+ '/event//submit_lineup/',
+ submit_lineup,
+ name='teamsnap_submit_lineup'
+ ),
+ path('/event//edit_lineup/',
+ edit_lineup,
+ name='teamsnap_edit_multiple_lineups'
+ ),
]
diff --git a/teamsnap/views.py b/teamsnap/views.py
index a7a62df..1439cfc 100644
--- a/teamsnap/views.py
+++ b/teamsnap/views.py
@@ -8,6 +8,7 @@ from allauth.socialaccount.providers.oauth2.views import (
)
from django.shortcuts import redirect, render
from django.views.generic.edit import FormView
+from django.http import HttpResponseNotAllowed, HttpResponse, JsonResponse, HttpResponseServerError
from .forms import PreferencesForm
from .models import Preferences
@@ -365,9 +366,9 @@ def edit_lineup(request, event_ids, team_id):
}
)
- return render(
- request, "lineup/multiple_edit.html", context={"contexts": contexts}
- )
+ return render(
+ request, "lineup/multiple_edit.html", context={"contexts": contexts}
+ )
def dashboard(request, team_id=None):
@@ -412,3 +413,63 @@ def dashboard(request, team_id=None):
],
},
)
+
+def submit_lineup(request, team_id, event_id):
+ from teamsnap.forms import LineupEntryFormset
+
+ request.user.socialaccount_set.filter(provider="teamsnap").first()
+ from pyteamsnap.api import EventLineup, TeamSnap, EventLineupEntry, Event
+ 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)
+ ts_event = Event.get(client,event_id)
+ ts_lineup = EventLineup.search(client, event_id=event_id)
+ event_lineup_id = ts_lineup[0].data['id']
+ if request.GET:
+ return HttpResponseNotAllowed()
+ if request.POST:
+ formset = LineupEntryFormset(request.POST)
+ if formset.is_valid():
+ r = []
+ for form in formset:
+ data = form.cleaned_data
+ if data.get('event_lineup_entry_id'):
+ event_lineup_entry = EventLineupEntry.get(client, id=data.get('event_lineup_entry_id'))
+ if data.get('position_only'):
+ data['label'] = data['label'] + ' [PO]'
+ event_lineup_entry.data.update(data)
+ if not data.get('sequence') and not data.get('label'):
+ try:
+ r.append(event_lineup_entry.delete())
+ except Exception as e:
+ raise e
+ else:
+ try:
+ r.append(event_lineup_entry.put())
+ except:
+ pass
+ pass
+ elif data.get('sequence') is not None and data.get('label'):
+ event_lineup_entry = EventLineupEntry.new(client)
+ if data.get('position_only'):
+ data['label'] = data['label'] + ' [PO]'
+ event_lineup_entry.data.update(data)
+ event_lineup_entry.data.update({"event_lineup_id": event_lineup_id})
+ try:
+ r.append(event_lineup_entry.post())
+ except Exception as e:
+ raise e
+ else:
+ pass
+ else:
+ # breakpoint()
+ pass
+ # breakpoint()
+ pass
+ return JsonResponse(ts_event.data)
+ pass
+ return HttpResponseServerError