some javascript to improve planned session manage
This commit is contained in:
@@ -605,13 +605,14 @@ class FusionMetricChoiceForm(ModelForm):
|
|||||||
class PlannedSessionSelectForm(forms.Form):
|
class PlannedSessionSelectForm(forms.Form):
|
||||||
|
|
||||||
def __init__(self, sessionchoices, *args, **kwargs):
|
def __init__(self, sessionchoices, *args, **kwargs):
|
||||||
|
initialsession = kwargs.pop('initialsession',None)
|
||||||
super(PlannedSessionSelectForm, self).__init__(*args,**kwargs)
|
super(PlannedSessionSelectForm, self).__init__(*args,**kwargs)
|
||||||
|
|
||||||
self.fields['plannedsession'] = forms.ChoiceField(
|
self.fields['plannedsession'] = forms.ChoiceField(
|
||||||
label='Sessions',
|
label='Sessions',
|
||||||
choices = sessionchoices,
|
choices = sessionchoices,
|
||||||
widget = forms.RadioSelect,
|
widget = forms.RadioSelect,
|
||||||
|
initial=initialsession
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -105,19 +105,17 @@ def is_session_complete(r,ps):
|
|||||||
elif ps.sessionunit == 'km':
|
elif ps.sessionunit == 'km':
|
||||||
value *= 1000.
|
value *= 1000.
|
||||||
|
|
||||||
print score,value,ps.sessionvalue,ps.sessionunit
|
|
||||||
|
|
||||||
ratio = score/float(value)
|
ratio = score/float(value)
|
||||||
|
|
||||||
status = 'partial'
|
status = 'partial'
|
||||||
|
|
||||||
if ps.sessiontype == 'training':
|
if ps.sessiontype == 'session':
|
||||||
if ps.sessioncriterium == 'exact':
|
if ps.criterium == 'exact':
|
||||||
if ratio == 1.0:
|
if ratio == 1.0:
|
||||||
return ratio,'completed'
|
return ratio,'completed'
|
||||||
else:
|
else:
|
||||||
return ratio,'partial'
|
return ratio,'partial'
|
||||||
elif ps.sessioncriterium == 'minimum':
|
elif ps.criterium == 'minimum':
|
||||||
if ratio > 1.0:
|
if ratio > 1.0:
|
||||||
return ratio,'completed'
|
return ratio,'completed'
|
||||||
else:
|
else:
|
||||||
@@ -133,12 +131,12 @@ def is_session_complete(r,ps):
|
|||||||
else:
|
else:
|
||||||
return ratio,'partial'
|
return ratio,'partial'
|
||||||
elif ps.sessiontype == 'challenge':
|
elif ps.sessiontype == 'challenge':
|
||||||
if ps.sessioncriterium == 'exact':
|
if ps.criterium == 'exact':
|
||||||
if ratio == 1.0:
|
if ratio == 1.0:
|
||||||
return ratio,'completed'
|
return ratio,'completed'
|
||||||
else:
|
else:
|
||||||
return ratio,'partial'
|
return ratio,'partial'
|
||||||
elif ps.sessioncriterium == 'minimum':
|
elif ps.criterium == 'minimum':
|
||||||
if ratio > 1.0:
|
if ratio > 1.0:
|
||||||
return ratio,'completed'
|
return ratio,'completed'
|
||||||
else:
|
else:
|
||||||
|
|||||||
@@ -4,6 +4,18 @@
|
|||||||
|
|
||||||
{% block title %}Planned Sessions{% endblock %}
|
{% block title %}Planned Sessions{% endblock %}
|
||||||
|
|
||||||
|
{% block meta %}
|
||||||
|
<script type='text/javascript'
|
||||||
|
src='https://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js'>
|
||||||
|
</script>
|
||||||
|
<script type='text/javascript'
|
||||||
|
src='https://ajax.aspnetcdn.com/ajax/jquery.validate/1.14.0/jquery.validate.min.js'>
|
||||||
|
</script>
|
||||||
|
<script>
|
||||||
|
</script>
|
||||||
|
{% endblock %}
|
||||||
|
|
||||||
|
|
||||||
{% block content %}
|
{% block content %}
|
||||||
<div class="grid_12 alpha">
|
<div class="grid_12 alpha">
|
||||||
{% include "planningbuttons.html" %}
|
{% include "planningbuttons.html" %}
|
||||||
@@ -72,3 +84,22 @@
|
|||||||
|
|
||||||
</form>
|
</form>
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
|
{% block scripts %}
|
||||||
|
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js"></script>
|
||||||
|
<script>
|
||||||
|
$(document).ready(function(){
|
||||||
|
$('#id_plannedsession').on('click', function(evt) {
|
||||||
|
var selectedsession = $("input:radio[name='plannedsession']:checked").val();
|
||||||
|
|
||||||
|
var url = window.location.pathname
|
||||||
|
if (url.indexOf("/session/") >= 0) {
|
||||||
|
url = url.replace(/\/session\/\d+/g, "/session/"+selectedsession);
|
||||||
|
} else {
|
||||||
|
url += "/session/"+selectedsession
|
||||||
|
}
|
||||||
|
window.location.replace(url);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
{% endblock %}
|
||||||
|
|||||||
@@ -401,6 +401,17 @@ urlpatterns = [
|
|||||||
url(r'^sessions/(?P<id>\d+)$',views.plannedsession_view),
|
url(r'^sessions/(?P<id>\d+)$',views.plannedsession_view),
|
||||||
url(r'^sessions/(?P<id>\d+)/deleteconfirm$',views.plannedsession_deleteconfirm_view),
|
url(r'^sessions/(?P<id>\d+)/deleteconfirm$',views.plannedsession_deleteconfirm_view),
|
||||||
url(r'^sessions/(?P<id>\d+)/delete$',views.plannedsession_delete_view),
|
url(r'^sessions/(?P<id>\d+)/delete$',views.plannedsession_delete_view),
|
||||||
|
|
||||||
|
url(r'^sessions/manage/session/(?P<initialsession>\d+)$',
|
||||||
|
views.plannedsessions_manage_view),
|
||||||
|
url(r'^sessions/manage/rower/(?P<rowerid>\d+)/session/(?P<initialsession>\d+)$',
|
||||||
|
views.plannedsessions_manage_view),
|
||||||
|
url(r'^sessions/manage/(?P<timeperiod>[\w\ ]+.*)/rower/(?P<rowerid>\d+)/session/(?P<initialsession>\d+)$',
|
||||||
|
views.plannedsessions_manage_view),
|
||||||
|
url(r'^sessions/manage/(?P<timeperiod>[\w\ ]+.*)/session/(?P<initialsession>\d+)$',
|
||||||
|
views.plannedsessions_manage_view),
|
||||||
|
|
||||||
|
|
||||||
url(r'^sessions/manage/?$',
|
url(r'^sessions/manage/?$',
|
||||||
views.plannedsessions_manage_view),
|
views.plannedsessions_manage_view),
|
||||||
url(r'^sessions/manage/rower/(?P<rowerid>\d+)$',
|
url(r'^sessions/manage/rower/(?P<rowerid>\d+)$',
|
||||||
|
|||||||
@@ -11724,6 +11724,11 @@ def plannedsession_create_view(request):
|
|||||||
comment = cd['comment']
|
comment = cd['comment']
|
||||||
name = cd['name']
|
name = cd['name']
|
||||||
|
|
||||||
|
if sessionunit == 'min':
|
||||||
|
sessionmode = 'time'
|
||||||
|
elif sessionunit in ['km','m']:
|
||||||
|
sessionmode = 'distance'
|
||||||
|
|
||||||
ps = PlannedSession(
|
ps = PlannedSession(
|
||||||
name=name,
|
name=name,
|
||||||
startdate=startdate,
|
startdate=startdate,
|
||||||
@@ -11786,7 +11791,12 @@ def plannedsessions_view(request,timeperiod='today',rowerid=0):
|
|||||||
})
|
})
|
||||||
|
|
||||||
@login_required()
|
@login_required()
|
||||||
def plannedsessions_manage_view(request,timeperiod='today',rowerid=0):
|
def plannedsessions_manage_view(request,timeperiod='today',rowerid=0,
|
||||||
|
initialsession=0):
|
||||||
|
|
||||||
|
is_ajax = False
|
||||||
|
if request.is_ajax():
|
||||||
|
is_ajax = True
|
||||||
|
|
||||||
if rowerid==0:
|
if rowerid==0:
|
||||||
r = getrower(request.user)
|
r = getrower(request.user)
|
||||||
@@ -11800,9 +11810,11 @@ def plannedsessions_manage_view(request,timeperiod='today',rowerid=0):
|
|||||||
|
|
||||||
startdate,enddate = get_dates_timeperiod(timeperiod)
|
startdate,enddate = get_dates_timeperiod(timeperiod)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
sps = get_sessions(r,startdate=startdate,enddate=enddate)
|
sps = get_sessions(r,startdate=startdate,enddate=enddate)
|
||||||
|
if initialsession==0:
|
||||||
|
initialsession=sps[0].id
|
||||||
|
|
||||||
|
ps0 = PlannedSession.objects.get(id=initialsession)
|
||||||
|
|
||||||
ws = Workout.objects.filter(
|
ws = Workout.objects.filter(
|
||||||
user=r,date__gte=startdate,
|
user=r,date__gte=startdate,
|
||||||
@@ -11812,6 +11824,8 @@ def plannedsessions_manage_view(request,timeperiod='today',rowerid=0):
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
initialworkouts = [w.id for w in Workout.objects.filter(user=r,plannedsession=ps0)]
|
||||||
|
|
||||||
plannedsessionstuple = []
|
plannedsessionstuple = []
|
||||||
|
|
||||||
for ps in sps:
|
for ps in sps:
|
||||||
@@ -11828,6 +11842,8 @@ def plannedsessions_manage_view(request,timeperiod='today',rowerid=0):
|
|||||||
for w in ws:
|
for w in ws:
|
||||||
wtpl = (w.id, w.__unicode__())
|
wtpl = (w.id, w.__unicode__())
|
||||||
choices.append(wtpl)
|
choices.append(wtpl)
|
||||||
|
if w.id in initialworkouts:
|
||||||
|
workoutdata['initial'].append(w.id)
|
||||||
|
|
||||||
workoutdata['choices'] = tuple(choices)
|
workoutdata['choices'] = tuple(choices)
|
||||||
|
|
||||||
@@ -11856,9 +11872,26 @@ def plannedsessions_manage_view(request,timeperiod='today',rowerid=0):
|
|||||||
messages.error(request,er)
|
messages.error(request,er)
|
||||||
|
|
||||||
|
|
||||||
ps_form = PlannedSessionSelectForm(plannedsessionstuple)
|
ps_form = PlannedSessionSelectForm(plannedsessionstuple,
|
||||||
|
initialsession=initialsession)
|
||||||
w_form = WorkoutSessionSelectForm(workoutdata=workoutdata)
|
w_form = WorkoutSessionSelectForm(workoutdata=workoutdata)
|
||||||
|
|
||||||
|
|
||||||
|
if is_ajax:
|
||||||
|
ajax_workouts = []
|
||||||
|
for id,name in workoutdata['choices']:
|
||||||
|
if id in initialworkouts:
|
||||||
|
ajax_workouts.append((id,name,True))
|
||||||
|
else:
|
||||||
|
ajax_workouts.append((id,name,False))
|
||||||
|
|
||||||
|
ajax_response = {
|
||||||
|
'workouts':ajax_workouts,
|
||||||
|
'plannedsessionstuple':plannedsessionstuple,
|
||||||
|
}
|
||||||
|
return JSONResponse(ajax_response)
|
||||||
|
|
||||||
|
|
||||||
return render(request,'plannedsessionsmanage.html',
|
return render(request,'plannedsessionsmanage.html',
|
||||||
{
|
{
|
||||||
'teams':get_my_teams(request.user),
|
'teams':get_my_teams(request.user),
|
||||||
@@ -11896,6 +11929,12 @@ def plannedsession_edit_view(request,id=0):
|
|||||||
sessionmode = cd['sessionmode']
|
sessionmode = cd['sessionmode']
|
||||||
sessionvalue = cd['sessionvalue']
|
sessionvalue = cd['sessionvalue']
|
||||||
sessionunit = cd['sessionunit']
|
sessionunit = cd['sessionunit']
|
||||||
|
|
||||||
|
if sessionunit == 'min':
|
||||||
|
sessionmode = 'time'
|
||||||
|
elif sessionunit in ['km','m']:
|
||||||
|
sessionmode = 'distance'
|
||||||
|
|
||||||
comment = cd['comment']
|
comment = cd['comment']
|
||||||
name = cd['name']
|
name = cd['name']
|
||||||
|
|
||||||
@@ -11952,8 +11991,6 @@ def plannedsession_view(request,id=0,rowerid=0):
|
|||||||
|
|
||||||
ratio,status = is_session_complete(r,ps)
|
ratio,status = is_session_complete(r,ps)
|
||||||
|
|
||||||
print ratio
|
|
||||||
|
|
||||||
ratio = int(100.*ratio)
|
ratio = int(100.*ratio)
|
||||||
|
|
||||||
return render(request,'plannedsessionview.html',
|
return render(request,'plannedsessionview.html',
|
||||||
|
|||||||
Reference in New Issue
Block a user