Private
Public Access
1
0

session coach view v1

This commit is contained in:
Sander Roosendaal
2018-02-11 13:55:51 +01:00
parent fdc4ec15ea
commit 8884e2f7b1
7 changed files with 228 additions and 12 deletions

View File

@@ -16,7 +16,7 @@ queuelow = django_rq.get_queue('low')
queuehigh = django_rq.get_queue('low')
from rowers.models import (
Rower, Workout,
Rower, Workout,Team,
GeoCourse, TrainingMicroCycle,TrainingMesoCycle,TrainingMacroCycle,
TrainingPlan,PlannedSession,
)
@@ -118,6 +118,9 @@ def get_session_metrics(ps):
def is_session_complete(r,ps):
status = 'not done'
if r not in ps.rower.all():
return 0,'not assigned'
ws = Workout.objects.filter(user=r,plannedsession=ps)
@@ -253,6 +256,25 @@ def get_dates_timeperiod(timeperiod):
return startdate,enddate
def get_sessions_manager(m,teamid=0,startdate=date.today(),
enddate=date.today()+timezone.timedelta(+1000)):
if teamid:
t = Team.objects.get(id=teamid)
sps = PlannedSession.objects.filter(
team__in=[t],
manager=m,
startdate__lte=enddate,
enddate__gte=startdate,
).order_by("startdate","enddate")
else:
sps = PlannedSession.objects.filter(
manager=m,
startdate__lte=enddate,
enddate__gte=startdate,
).order_by("startdate","enddate")
return sps
def get_sessions(r,startdate=date.today(),
enddate=date.today()+timezone.timedelta(+1000)):
@@ -264,17 +286,6 @@ def get_sessions(r,startdate=date.today(),
return sps
def get_sessions_manager(manager,startdate=date.today(),
enddate=date.today()+timezone.timedelta(+1000)):
sps = PlannedSession.objects.filter(
manager=manager,
startdate__lte=enddate,
enddate__gte=startdate,
).order_by("startdate","enddate").exclude(team__isnull=True)
return sps
def get_workouts_session(r,ps):
ws = Workout.objects.filter(user=r,plannedsession=ps)

View File

@@ -0,0 +1,126 @@
{% extends "base.html" %}
{% load staticfiles %}
{% load rowerfilters %}
{% block title %}Planned Sessions{% endblock %}
{% block content %}
<div class="grid_12 alpha">
{% include "planningbuttons.html" %}
</div>
<div class="grid_4 alpha">
{% if theteam %}
<h1>Coach Overview. Team {{ theteam.name }}</h1>
{% else %}
<h1>Coach Overview</h1>
{% endif %}
</div>
<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/coach/today">
Today
</a>
<a class="button gray small alpha"
href="/rowers/sessions/coach/thisweek">
This Week
</a>
<a class="button gray small alpha"
href="/rowers/sessions/coach/thismonth">
This Month
</a>
<a class="button gray small alpha"
href="/rowers/sessions/coach/lastweek">
Last Week
</a>
<a class="button gray small alpha"
href="/rowers/sessions/coach/lastmonth/">
Last 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">
See individual plans for Rower
</button>
<div class="dropdown-content">
{% for member in user|team_rowers %}
<a class="button green small" href="/rowers/sessions/{{ timeperiod }}/rower/{{ member.id }}">{{ member.user.first_name }} {{ member.user.last_name }}</a>
{% endfor %}
</div>
</div>
<div class="grid_2 dropdown">
<button class="grid_2 alpha button green small dropbtn">
Select Team
</button>
<div class="dropdown-content">
<a class="button green small" href="/rowers/sessions/coach/{{ timeperiod }}">
All Teams
</a>
{% for team in myteams %}
<a class="button green small" href="/rowers/sessions/coach/{{ timeperiod }}/team/{{ team.id }}">{{ team.name }}</a>
{% endfor %}
</div>
</div>
{% endif %}
<div class="grid_12 alpha">
<table width="90%" class="listtable">
<thead>
<tr>
<th>On or after</th>
<th>On or before</th>
<th>Name</th>
{% for r in rowers %}
<th class="rotate"><div><span>
{{ r.user.first_name }} {{ r.user.last_name }}
</span></div></th>
{% endfor %}
</tr>
</thead>
<tbody>
{% for key, thedict in statusdict.items %}
<tr>
<td>
{{ thedict|lookup:'startdate'|date:"Y-m-d" }}
</td>
<td>
{{ thedict|lookup:'enddate'|date:"Y-m-d" }}
</td>
<td>
<a href="/rowers/sessions/{{ key }}">
{{ thedict|lookup:'name' }}
</a>
</td>
{% for r in rowers %}
<td>
{% if thedict|lookup:'results'|lookup:r.id == 'completed' %}
<a class="green dot"
href="/rowers/sessions/manage/{{ timeperiod }}/rower/{{ r.id }}/session/{{ key }}">&nbsp;</a>
{% elif thedict|lookup:'results'|lookup:r.id == 'partial' %}
<a class="orange dot"
href="/rowers/sessions/manage/{{ timeperiod }}/rower/{{ r.id }}/session/{{ key }}">&nbsp;</a>
{% elif thedict|lookup:'results'|lookup:r.id == 'not done' %}
<a class="white dot"
href="/rowers/sessions/manage/{{ timeperiod }}/rower/{{ r.id }}/session/{{ key }}">&nbsp;</a>
{% elif thedict|lookup:'results'|lookup:r.id == 'not assigned' %}
&nbsp;
{% else %}
<a class="red dot"
href="/rowers/sessions/manage/{{ timeperiod }}/rower/{{ r.id }}/session/{{ key }}">&nbsp;</a>
{% endif %}
</td>
{% endfor %}
</tr>
{% endfor %}
</tbody>
</table>
</div>
</form>
{% endblock %}

View File

@@ -9,6 +9,16 @@
{% include "planningbuttons.html" %}
</div>
<div class="grid_12 alpha">
<div class="grid_2 alpha">
{% if user.is_authenticated and psdict.id.1|is_session_manager:user %}
<a class="button small gray" href="/rowers/sessions/{{ psdict.id.1 }}/edit">
Edit Session</a>
{% else %}
&nbsp;
{% endif %}
</div>
</div>
<div class="grid_12 alpha">
<div id="left" class="grid_6 alpha">
<h1>Session {{ psdict.name.1 }}</h1>

View File

@@ -100,6 +100,16 @@ def ualookup(dict, key):
return s
from rowers.models import PlannedSession
@register.filter
def is_session_manager(id,user):
try:
ps = PlannedSession.objects.get(id=id)
except PlannedSession.DoesNotExist:
return False
return ps.manager == user
@register.filter(name='times')
def times(number):
return range(number)

View File

@@ -448,6 +448,11 @@ urlpatterns = [
views.plannedsessions_manage_view),
url(r'^sessions/manage/(?P<timeperiod>[\w\ ]+.*)$',
views.plannedsessions_manage_view),
url(r'^sessions/coach$',views.plannedsessions_coach_view),
url(r'^sessions/coach/(?P<timeperiod>[\w\ ]+.*)/team/(?P<teamid>\d+)$',
views.plannedsessions_coach_view),
url(r'^sessions/coach/(?P<timeperiod>[\w\ ]+.*)$',
views.plannedsessions_coach_view),
url(r'^sessions/?$',views.plannedsessions_view),
url(r'^sessions/rower/(?P<rowerid>\d+)$',views.plannedsessions_view),
url(r'^sessions/(?P<timeperiod>[\w\ ]+.*)/rower/(?P<rowerid>\d+)$',views.plannedsessions_view),

View File

@@ -294,6 +294,7 @@ def calculate_age(born):
def my_dict_from_instance(instance,model):
thedict = {}
thedict['id'] = instance.id
for attr, value in instance.__dict__.iteritems():
try:

View File

@@ -11854,6 +11854,58 @@ def plannedsession_teamedit_view(request,timeperiod='thisweek',
'plannedsessions':sps,
})
@user_passes_test(iscoachmember,login_url="/rowers/planmembership/",
redirect_field_name=None)
def plannedsessions_coach_view(request,timeperiod='thisweek',
teamid=0):
startdate,enddate = get_dates_timeperiod(timeperiod)
if teamid != 0:
try:
theteam = Team.objects.get(id=teamid)
except Team.DoesNotExist:
theteam = False
else:
theteam = False
sps = get_sessions_manager(request.user,teamid=teamid,
enddate=enddate,
startdate=startdate)
rowers = []
for ps in sps:
rowers += ps.rower.all()
rowers = list(set(rowers))
statusdict = {}
for ps in sps:
rowerstatus = {}
for r in rowers:
ratio, status = is_session_complete(r,ps)
rowerstatus[r.id] = status
sessiondict = {
'results':rowerstatus,
'name': ps.name,
'startdate': ps.startdate,
'enddate': ps.enddate,
}
statusdict[ps.id] = sessiondict
myteams = Team.objects.filter(manager=request.user)
return render(request,'plannedsessionscoach.html',
{
'myteams':myteams,
'plannedsessions':sps,
'statusdict':statusdict,
'timeperiod':timeperiod,
'rowers':rowers,
'theteam':theteam,
}
)
@login_required()
def plannedsessions_view(request,timeperiod='thisweek',rowerid=0):
@@ -12181,6 +12233,7 @@ def plannedsession_view(request,id=0,rowerid=0):
resultsdict = pd.DataFrame(resultsdict).transpose().to_dict()
psdict = my_dict_from_instance(ps,PlannedSession)
print psdict
ws = get_workouts_session(r,ps)