Private
Public Access
1
0

sessions manage

This commit is contained in:
Sander Roosendaal
2018-10-15 16:56:45 +02:00
parent e1cd70f016
commit bd757c7bb4
4 changed files with 90 additions and 165 deletions

View File

@@ -140,7 +140,7 @@
<label for="athlete-selector"><i class="fas fa-users fa-fw"></i>&nbsp;Athletes</label>
<ul>
{% for member in user|team_members %}
<a href={{ request.path|userurl:member }}>
<a href={{ request.path|userurl:member }}?when={{ timeperiod }}>
<i class="fas fa-user fa-fw"></i>
{% if member == rower.user %}
&bull;

View File

@@ -1,4 +1,4 @@
{% extends "base.html" %}
{% extends "newbase.html" %}
{% load staticfiles %}
{% load rowerfilters %}
@@ -16,119 +16,71 @@
{% endblock %}
{% block content %}
<div class="grid_12 alpha">
{% include "planningbuttons.html" %}
</div>
<div class="grid_12 alpha">
<div class="grid_6 alpha">
<h1>Manage Plan Execution for {{ rower.user.first_name }} {{ rower.user.last_name }}</h1>
</div>
{% block main %}
<h1>Manage Plan Execution for {{ rower.user.first_name }} {{ rower.user.last_name }}</h1>
<div id="timeperiod" class="grid_2 dropdown">
<button class="grid_2 alpha button gray small dropbtn">Select Time Period ({{ timeperiod|verbosetimeperiod }})</button>
<div class="dropdown-content">
<a class="button gray small alpha"
href="/rowers/sessions/manage/today/rower/{{ rower.id }}">
Today
</a>
<a class="button gray small alpha"
href="/rowers/sessions/manage/thisweek/rower/{{ rower.id }}">
This Week
</a>
<a class="button gray small alpha"
href="/rowers/sessions/manage/thismonth/rower/{{ rower.id }}">
This Month
</a>
<a class="button gray small alpha"
href="/rowers/sessions/manage/lastweek/rower/{{ rower.id }}">
Last Week
</a>
<a class="button gray small alpha"
href="/rowers/sessions/manage/lastmonth/rower/{{ rower.id }}">
Last Month
</a>
<a class="button gray small alpha"
href="/rowers/sessions/manage/nextweek/rower/{{ rower.id }}">
Next Week
</a>
<a class="button gray small alpha"
href="/rowers/sessions/manage/nextmonth/rower/{{ rower.id }}">
Next Month
</a>
</div>
</div>
{% if user.is_authenticated and user|is_manager %}
<div class="grid_2 dropdown">
<button class="grid_2 alpha button green small dropbtn">
{{ rower.user.first_name }} {{ rower.user.last_name }}
</button>
<div class="dropdown-content">
{% for member in user|team_rowers %}
<a class="button green small" href="/rowers/sessions/manage/{{ timeperiod }}/rower/{{ member.id }}">{{ member.user.first_name }} {{ member.user.last_name }}</a>
{% endfor %}
</div>
</div>
{% endif %}
</div>
<div class="grid_12 alpha">
<p>Select one session on the left, and one or more workouts on the right
to match the workouts to the session. For tests and training sessions,
the selected workouts must be done on the same date. For all sessions,
the workout dates must be between the start and end date for the
session.
</p>
<p>
If you select a workout that has already been matched to another session,
it will change to match this session.
</p>
<p>
Workouts marked with a red check mark (<span style="color:red"><b>&#10004;</b></span>)
are currently linked to one of your sessions. A workout can only be assigned to
one session at a time.
</p>
</div>
<form id="session_form" action="/rowers/sessions/manage/{{ timeperiod }}/rower/{{ rower.id }}"
<p>Select one session on the left, and one or more workouts on the right
to match the workouts to the session. For tests and training sessions,
the selected workouts must be done on the same date. For all sessions,
the workout dates must be between the start and end date for the
session.
</p>
<p>
If you select a workout that has already been matched to another session,
it will change to match this session.
</p>
<p>
Workouts marked with a red check mark (<span style="color:red"><b>&#10004;</b></span>)
are currently linked to one of your sessions. A workout can only be assigned to
one session at a time.
</p>
<form id="session_form" action="/rowers/sessions/manage/user/{{ rower.user.id }}/?when={{ timeperiod }}"
method="post">
<div class="grid_12 alpha">
<div class="grid_6 alpha">
<p>Planned Sessions</p>
<table width="100%">
<tr>
{% for field in ps_form.hidden_fields %}
{{ field }}
{% endfor %}
{% for field in ps_form.visible_fields %}
<td> {{ field }}</td>
{% endfor %}
</tr>
<ul class="main-content">
<li class="grid_2">
<h2>Planned Sessions</h2>
<table width="100%">
<tr>
{% for field in ps_form.hidden_fields %}
{{ field }}
{% endfor %}
{% for field in ps_form.visible_fields %}
<td> {{ field }}</td>
{% endfor %}
</tr>
</table>
</div>
<div class="grid_6 omega">
<p>Workouts</p>
<table width="100%">
<tr>
{% for field in w_form.hidden_fields %}
{{ field }}
{% endfor %}
{% for field in w_form.visible_fields %}
<td>
{{ field }}
</td>
{% endfor %}
</tr>
</table>
</div>
</div>
<div class="grid_2 prefix_2 suffix_8">
</li>
<li class="grid_2">
<h2>Workouts</h2>
<table width="100%">
<tr>
{% for field in w_form.hidden_fields %}
{{ field }}
{% endfor %}
{% for field in w_form.visible_fields %}
<td>
{{ field }}
</td>
{% endfor %}
</tr>
</table>
</li>
<li class="grid_2">
{% csrf_token %}
<input class="button green" type="submit" value="Submit">
</div>
</li>
</ul>
</form>
{% endblock %}
{% block sidebar %}
{% include 'menu_plan.html' %}
{% endblock %}
{% block scripts %}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js"></script>
<script>
@@ -144,13 +96,13 @@
function getURL() {
var url = window.location.pathname;
var selectedsession = $("input:radio[name='plannedsession']:checked").val();
if (url.indexOf("/session/") >= 0) {
url = url.replace(/\/session\/\d+/g, "/session/"+selectedsession);
} else {
url += "/session/"+selectedsession
url = url.replace("manage","manage/session/"+selectedsession);
};
url += '?when={{ timeperiod }}'
return url};
function loadJSON( url ) {

View File

@@ -469,13 +469,13 @@ urlpatterns = [
url(r'^sessions/(?P<pk>\d+)/deleteconfirm$',views.PlannedSessionDelete.as_view()),
url(r'^sessions/(?P<pk>\d+)/delete$',views.PlannedSessionDelete.as_view(),
name='plannedsession_delete_view'),
url(r'^sessions/manage/session/(?P<initialsession>\d+)$',
url(r'^sessions/manage/session/(?P<initialsession>\d+)/$',
views.plannedsessions_manage_view),
url(r'^sessions/manage/user/(?P<userid>\d+)/session/(?P<initialsession>\d+)$',
url(r'^sessions/manage/session/(?P<initialsession>\d+)/user/(?P<userid>\d+)/$',
views.plannedsessions_manage_view),
url(r'^sessions/manage/?$',
views.plannedsessions_manage_view),
url(r'^sessions/manage/user/(?P<userid>\d+)$',
url(r'^sessions/manage/user/(?P<userid>\d+)/$',
views.plannedsessions_manage_view),
url(r'^sessions/coach$',views.plannedsessions_coach_view),
url(r'^sessions/print/?$',views.plannedsessions_print_view),

View File

@@ -14298,13 +14298,19 @@ def plannedsessions_print_view(request,timeperiod='thisweek',userid=0):
@login_required()
def plannedsessions_manage_view(request,timeperiod='thisweek',userid=0,
def plannedsessions_manage_view(request,userid=0,
initialsession=0):
is_ajax = False
if request.is_ajax():
is_ajax = True
when = request.GET.get('when')
if when:
timeperiod = when
else:
timeperiod = 'thisweek'
r = getrequestrower(request,userid=userid)
startdate,enddate = get_dates_timeperiod(timeperiod)
@@ -14336,7 +14342,7 @@ def plannedsessions_manage_view(request,timeperiod='thisweek',userid=0,
"date","startdatetime","id"
)
initialworkouts = [w.id for w in Workout.objects.filter(user=r,plannedsession=ps0)]
linkedworkouts = []
@@ -14413,6 +14419,23 @@ def plannedsessions_manage_view(request,timeperiod='thisweek',userid=0,
return JSONResponse(ajax_response)
breadcrumbs = [
{
'url':reverse(plannedsessions_view,
kwargs={'userid':userid}),
'name': 'Plan'
},
{
'url':reverse(plannedsessions_manage_view,
kwargs={
'userid':userid,
'initialsession':initialsession,
}
),
'name': 'Link Sessions to Workouts'
},
]
return render(request,'plannedsessionsmanage.html',
{
@@ -14420,6 +14443,8 @@ def plannedsessions_manage_view(request,timeperiod='thisweek',userid=0,
'plan':trainingplan,
'plannedsessions':sps,
'workouts':ws,
'active':'nav-plan',
'breadcrumbs':breadcrumbs,
'timeperiod':timeperiod,
'rower':r,
'ps_form':ps_form,
@@ -14858,58 +14883,6 @@ class PlannedSessionDelete(DeleteView):
return obj
@login_required()
def plannedsession_delete_view(request,id=0):
r = getrower(request.user)
try:
ps = PlannedSession.objects.get(id=id)
except PlannedSession.DoesNotExist:
raise Http404("Planned Session does not exist")
if ps.manager != request.user:
raise PermissionDenied("You are not allowed to delete this planned session")
ws = Workout.objects.filter(plannedsession=ps)
for w in ws:
w.plannedsession=None
w.save()
ps.delete()
url = reverse(plannedsessions_view)
return HttpResponseRedirect(url)
@login_required()
def plannedsession_deleteconfirm_view(request,id=0):
r = getrower(request.user)
try:
ps = PlannedSession.objects.get(id=id)
except PlannedSession.DoesNotExist:
raise Http404("Planned Session does not exist")
if ps.manager != request.user:
raise PermissionDenied("You are not allowed to delete this planned session")
psdict = my_dict_from_instance(ps,PlannedSession)
return render(request,'plannedsessiondeleteconfirm.html',
{
'ps':ps,
'psdict': psdict,
'attrs':[
'name','startdate','enddate','sessiontype',
],
'rower':r,
}
)
def virtualevents_view(request):
is_ajax = False