re-add multiple event views, add message for success
This commit is contained in:
2
.idea/runConfigurations/runserver_plus.xml
generated
2
.idea/runConfigurations/runserver_plus.xml
generated
@@ -14,7 +14,7 @@
|
|||||||
<option name="IS_MODULE_SDK" value="true" />
|
<option name="IS_MODULE_SDK" value="true" />
|
||||||
<option name="ADD_CONTENT_ROOTS" value="true" />
|
<option name="ADD_CONTENT_ROOTS" value="true" />
|
||||||
<option name="ADD_SOURCE_ROOTS" value="true" />
|
<option name="ADD_SOURCE_ROOTS" value="true" />
|
||||||
<option name="launchJavascriptDebuger" value="false" />
|
<option name="launchJavascriptDebuger" value="true" />
|
||||||
<option name="port" value="8000" />
|
<option name="port" value="8000" />
|
||||||
<option name="host" value="127.0.0.1" />
|
<option name="host" value="127.0.0.1" />
|
||||||
<option name="additionalOptions" value="--cert-file ./certs/benchcoach.ascorrea.com+4.pem --key-file certs/benchcoach.ascorrea.com+4-key.pem" />
|
<option name="additionalOptions" value="--cert-file ./certs/benchcoach.ascorrea.com+4.pem --key-file certs/benchcoach.ascorrea.com+4-key.pem" />
|
||||||
|
|||||||
@@ -273,3 +273,8 @@ SOCIALACCOUNT_FORMS = {"signup": "benchcoach.users.forms.UserSocialSignupForm"}
|
|||||||
# Your stuff...
|
# Your stuff...
|
||||||
# ------------------------------------------------------------------------------
|
# ------------------------------------------------------------------------------
|
||||||
INSTALLED_APPS += ["teamsnap", "instagen"]
|
INSTALLED_APPS += ["teamsnap", "instagen"]
|
||||||
|
SOCIALACCOUNT_PROVIDERS = {
|
||||||
|
'teamsnap': {
|
||||||
|
'SCOPE': ["read", "write"]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -18,11 +18,14 @@
|
|||||||
{# </div>#}
|
{# </div>#}
|
||||||
{# </div>#}
|
{# </div>#}
|
||||||
<div class="container overflow-scroll">
|
<div class="container overflow-scroll">
|
||||||
|
<div id="popup-messages-content">
|
||||||
|
</div>
|
||||||
<div class="row flex-row flex-nowrap">
|
<div class="row flex-row flex-nowrap">
|
||||||
<table>
|
<table>
|
||||||
<tbody>
|
<tbody>
|
||||||
<tr class="align-top mx-1">
|
<tr class="align-top mx-1">
|
||||||
{% for event_data in contexts %}
|
{% for event_data in contexts %}
|
||||||
|
|
||||||
<td class="px-1">
|
<td class="px-1">
|
||||||
{% include "lineup/widgets/lineup.html" with event=event_data.event event_id=event_data.event.data.id formset=event_data.formset formset_startinglineup=event_data.formset_startinglineup formset_bench=event_data.formset_bench formset_out=event_data.formset_out formset_startingpositionalonly=event_data.formset_startingpositionalonly %}
|
{% include "lineup/widgets/lineup.html" with event=event_data.event event_id=event_data.event.data.id formset=event_data.formset formset_startinglineup=event_data.formset_startinglineup formset_bench=event_data.formset_bench formset_out=event_data.formset_out formset_startingpositionalonly=event_data.formset_startingpositionalonly %}
|
||||||
</td>
|
</td>
|
||||||
@@ -32,6 +35,43 @@
|
|||||||
</table>
|
</table>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<script src="{% static 'js/Sortable.js' %}"></script>
|
|
||||||
<script src="{% static 'teamsnap/js/lineup-table.js' %}"></script>
|
{% endblock %}
|
||||||
|
|
||||||
|
{% block inline_javascript %}
|
||||||
|
{{ block.super }}
|
||||||
|
<script src="{% static 'js/Sortable.js' %}"></script>
|
||||||
|
<script src="{% static 'js/lineup-table.js' %}"></script>
|
||||||
|
<script>
|
||||||
|
window.addEventListener('DOMContentLoaded', () => {
|
||||||
|
/* Run whatever you want */
|
||||||
|
const postForms = document.querySelectorAll("[id^=form-lineup]");
|
||||||
|
for (postForm of postForms) {
|
||||||
|
function handleSubmit(postForm) {
|
||||||
|
postForm.addEventListener("submit", e => {
|
||||||
|
e.preventDefault();
|
||||||
|
formData = new FormData(postForm);
|
||||||
|
fetch(postForm.action, {
|
||||||
|
method: 'POST',
|
||||||
|
body: formData,
|
||||||
|
})
|
||||||
|
.then(response => response.json())
|
||||||
|
.then(data => {
|
||||||
|
{#postForm.reset();#}
|
||||||
|
document.querySelector("#popup-messages-content").innerHTML = `<div class="alert alert-dismissible alert-success" role="alert">
|
||||||
|
<strong>Success!</strong> ${data.formatted_title} <strong>saved</strong>.
|
||||||
|
<button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>
|
||||||
|
</div> `
|
||||||
|
})
|
||||||
|
.catch((error) => {
|
||||||
|
console.error('Error:', error);
|
||||||
|
});
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
handleSubmit(postForm)
|
||||||
|
}
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
<div class="card mx-auto benchcoach-lineup" style="max-width: 455px" id="benchcoach-lineup-{{ event_id }}">
|
<div class="card mx-auto benchcoach-lineup" style="max-width: 455px" id="benchcoach-lineup-{{ event_id }}">
|
||||||
<form method="post" action="">
|
<form method="post" action='{% url 'teamsnap_submit_lineup' team_id=event.data.team_id event_id=event.data.id %}' id="form-lineup-{{ event.data.id }}">
|
||||||
{{ formset.management_form }}
|
{{ formset.management_form }}
|
||||||
{% csrf_token %}
|
{% csrf_token %}
|
||||||
<div class="border-bottom p-2">
|
<div class="border-bottom p-2">
|
||||||
@@ -71,7 +71,6 @@
|
|||||||
</div>
|
</div>
|
||||||
{% include 'lineup/widgets/lineup_table.html' with formset=formset_out table_id="benchcoach-out" %}
|
{% include 'lineup/widgets/lineup_table.html' with formset=formset_out table_id="benchcoach-out" %}
|
||||||
|
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ from .views import (
|
|||||||
edit_lineup,
|
edit_lineup,
|
||||||
schedule_view,
|
schedule_view,
|
||||||
view_event,
|
view_event,
|
||||||
|
submit_lineup
|
||||||
)
|
)
|
||||||
|
|
||||||
urlpatterns = default_urlpatterns(TeamsnapProvider)
|
urlpatterns = default_urlpatterns(TeamsnapProvider)
|
||||||
@@ -28,4 +29,13 @@ urlpatterns += [
|
|||||||
edit_lineup,
|
edit_lineup,
|
||||||
name="teamsnap_edit_lineup",
|
name="teamsnap_edit_lineup",
|
||||||
),
|
),
|
||||||
|
path(
|
||||||
|
'<int:team_id>/event/<int:event_id>/submit_lineup/',
|
||||||
|
submit_lineup,
|
||||||
|
name='teamsnap_submit_lineup'
|
||||||
|
),
|
||||||
|
path('<int:team_id>/event/<str:event_ids>/edit_lineup/',
|
||||||
|
edit_lineup,
|
||||||
|
name='teamsnap_edit_multiple_lineups'
|
||||||
|
),
|
||||||
]
|
]
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ from allauth.socialaccount.providers.oauth2.views import (
|
|||||||
)
|
)
|
||||||
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
|
||||||
@@ -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
|
||||||
|
|||||||
Reference in New Issue
Block a user