changed sync to post form (still called send to benchcoach)

This commit is contained in:
2021-12-30 10:40:30 -06:00
parent 90d72033b4
commit 590069c3b1
5 changed files with 66 additions and 54 deletions

View File

@@ -57,20 +57,7 @@
<div class="card-header d-inline-flex"> <div class="card-header d-inline-flex">
<div class="d-inline-flex flex-grow-1"><h5>Event</h5></div> <div class="d-inline-flex flex-grow-1"><h5>Event</h5></div>
<div class="d-inline-flex"> <div class="d-inline-flex">
<form method="post" action="{% url 'sync' %}">{% csrf_token %} {% include 'teamsnap/update-button.html' with object_name='event' object_id=event.id next=request.path %}
<input type="hidden" name="object_name" value="event">
<input type="hidden" name="object_id" value={{ event.teamsnap_event.id }}>
<input type="hidden" name="next" value="{{ request.path }}">
<button type="submit" value="update_event" class="btn btn-sm btn-outline-secondary d-xl-flex align-items-xl-center mx-1">
<i class="bi bi-cloud-fill"></i><i class="bi bi-arrow-right"></i><i class="bi bi-clipboard"></i>
</button>
</input>
</form>
<button type="button" value="Submit" class="btn btn-sm btn-outline-primary d-xl-flex align-items-xl-center mx-1">
<i class="bi bi-pencil-square mx-1"></i>Edit
</button>
</div> </div>
</div> </div>
<div class="card-body p-0"> <div class="card-body p-0">
@@ -108,11 +95,6 @@
<div class="d-inline-flex flex-grow-1"> <div class="d-inline-flex flex-grow-1">
<h5>Bench</h5> <h5>Bench</h5>
</div> </div>
<div>
<button class="btn btn-sm btn-outline-secondary d-xl-flex align-items-xl-center" type="button">
<i class="bi bi-arrow-clockwise"></i>TeamSnap
</button>
</div>
</div> </div>
<div class="card-body p-0"> <div class="card-body p-0">

View File

@@ -21,9 +21,10 @@
<td>{{ obj_data.object_count }}</td> <td>{{ obj_data.object_count }}</td>
<th>{{ obj_data.counterpart.name }} </th> <th>{{ obj_data.counterpart.name }} </th>
<td>{{ obj_data.counterpart.object_count }}</td> <td>{{ obj_data.counterpart.object_count }}</td>
<td><a class="btn btn-primary" href="{% url 'send' object_name=obj_data.counterpart.name %}" role="button">
<i class="bi bi-arrow-clockwise"></i><i class="bi bi-asterisk"></i> Sync <td>
</a></td> {% include 'teamsnap/update-button.html' with object_name=obj_data.counterpart.name object_id='' next=request.path %}
</td>
</tr> </tr>
{% endfor %} {% endfor %}
</ul> </ul>

View File

@@ -0,0 +1,8 @@
<form method="post" id="formSync" action="{% url 'send' %}">{% csrf_token %}
<input type="hidden" name="object_name" value="{{ object_name }}">
<input type="hidden" name="object_id" value={{ object_id }}>
<input type="hidden" name="next" value="{{ next }}">
<button type="submit" value="update_event" class="btn btn-sm btn-outline-secondary d-xl-flex align-items-xl-center mx-1">
<i class="bi bi-arrow-clockwise"></i><i class="bi bi-asterisk"></i>
</button>
</form>

View File

@@ -14,7 +14,7 @@ urlpatterns = [
path('sync_teamsnap_db', views.sync_teamsnapdb_with_teamsnapapi, name="sync with teamsnapapi"), path('sync_teamsnap_db', views.sync_teamsnapdb_with_teamsnapapi, name="sync with teamsnapapi"),
path('sync_benchcoach_db', views.sync_teamsnapdb_to_benchcoachdb, name="sync benchcoach"), path('sync_benchcoach_db', views.sync_teamsnapdb_to_benchcoachdb, name="sync benchcoach"),
path('update/<str:object_name>', views.update_teamsnapdb_from_teamsnapapi, name="update"), path('update/<str:object_name>', views.update_teamsnapdb_from_teamsnapapi, name="update"),
path('send/<str:object_name>', views.send_to_benchcoach, name="send"), path('send', views.send_to_benchcoach, name="send"),
path('sync/', views.sync, name="sync"), path('sync/', views.sync, name="sync"),
path('import/', views.import_teamsnap, name="import") path('import/', views.import_teamsnap, name="import")
# path('import_teamsnap', views.import_teamsnap, name="import teamsnap"), # path('import_teamsnap', views.import_teamsnap, name="import teamsnap"),

View File

@@ -175,47 +175,68 @@ def update_teamsnapdb_from_teamsnapapi(request, object_name, object_id=None):
return redirect('teamsnap home') return redirect('teamsnap home')
@login_required() @login_required()
def send_to_benchcoach(request, object_name): def send_to_benchcoach(request, object_name=None, object_id=None): #TODO rename
Object = { if request.POST:
obj.__name__.lower(): obj next = request.POST.get('next')
for obj in object_name = request.POST.get('object_name')
[Availability, Event, LineupEntry, Location, Member, Opponent, Team, User] object_id = request.POST.get('object_id')
}.get(object_name)
TEAM_ID = request.user.profile.teamsnapsettings.managed_team.id Object = {
TOKEN = request.user.profile.teamsnap_access_token obj.__name__.lower(): obj
for obj in
[Availability, Event, LineupEntry, Location, Member, Opponent, Team, User]
}.get(object_name)
sync_engine = TeamsnapSyncEngine(teamsnap_token=TOKEN, managed_team_teamsnap_id=TEAM_ID) TEAM_ID = request.user.profile.teamsnapsettings.managed_team.id
r = {} TOKEN = request.user.profile.teamsnap_access_token
r[object_name]=[] sync_engine = TeamsnapSyncEngine(teamsnap_token=TOKEN, managed_team_teamsnap_id=TEAM_ID)
r = {}
if object_name == 'team': r[object_name]=[]
r[object_name] = sync_engine.sync(qs=benchcoach.models.Team.objects.all())
if object_name == 'venue': if object_name == 'team':
r[object_name] = sync_engine.sync(qs=benchcoach.models.Venue.objects.all()) if object_id:
pass r[object_name] = sync_engine.sync(qs=benchcoach.models.Team.objects.filter(id=object_id))
else:
r[object_name] = sync_engine.sync(qs=benchcoach.models.Team.objects.all())
if object_name == 'player': if object_name == 'venue':
r[object_name] = sync_engine.sync(qs=benchcoach.models.Player.objects.all()) if object_id:
r[object_name] = sync_engine.sync(qs=benchcoach.models.Venue.objects.filter(id=object_id))
else:
r[object_name] = sync_engine.sync(qs=benchcoach.models.Venue.objects.all())
if object_name == 'event': if object_name == 'player':
r[object_name] = sync_engine.sync(qs=benchcoach.models.Event.objects.all()) if object_id:
pass r[object_name] = sync_engine.sync(qs=benchcoach.models.Player.objects.filter(id=object_id))
else:
r[object_name] = sync_engine.sync(qs=benchcoach.models.Player.objects.all())
if object_name == 'availability': if object_name == 'event':
r[object_name] = [] if object_id:
for event in benchcoach.models.Player.objects.all(): r[object_name] = sync_engine.sync(qs=benchcoach.models.Event.objects.filter(id=object_id))
r[object_name] += sync_engine.sync(qs=event.availability_set.all()) r['availability'] = sync_engine.sync(qs=benchcoach.models.Event.objects.get(id=object_id).availability_set.all())
else:
r[object_name] = sync_engine.sync(qs=benchcoach.models.Event.objects.all())
for object_name, results in r.items(): if object_name == 'availability':
if len(results) == 0: r[object_name] = []
messages.error(request, f"Error! No {object_name} objects updated") if object_id:
else: r[object_name] += sync_engine.sync(qs=benchcoach.models.Availability.objects.filter(id=object_id))
messages.success(request, f"Success! {len(results)} {object_name} objects updated.") else:
for event in benchcoach.models.Player.objects.all():
r[object_name] += sync_engine.sync(qs=event.availability_set.all())
return redirect('teamsnap home') for object_name, results in r.items():
if len(results) == 0:
messages.error(request, f"Error! No {object_name} objects updated")
else:
messages.success(request, f"Success! {len(results)} {object_name} objects updated.")
return redirect(next)
else:
return HttpResponse(404)
def sync_teamsnapdb_with_teamsnapapi(request): def sync_teamsnapdb_with_teamsnapapi(request):
''' '''