some javascript to improve planned session manage
This commit is contained in:
@@ -605,20 +605,21 @@ class FusionMetricChoiceForm(ModelForm):
|
||||
class PlannedSessionSelectForm(forms.Form):
|
||||
|
||||
def __init__(self, sessionchoices, *args, **kwargs):
|
||||
|
||||
initialsession = kwargs.pop('initialsession',None)
|
||||
super(PlannedSessionSelectForm, self).__init__(*args,**kwargs)
|
||||
|
||||
self.fields['plannedsession'] = forms.ChoiceField(
|
||||
label='Sessions',
|
||||
choices = sessionchoices,
|
||||
widget = forms.RadioSelect,
|
||||
initial=initialsession
|
||||
)
|
||||
|
||||
|
||||
class WorkoutSessionSelectForm(forms.Form):
|
||||
|
||||
def __init__(self, workoutdata, *args, **kwargs):
|
||||
|
||||
|
||||
super(WorkoutSessionSelectForm, self).__init__(*args, **kwargs)
|
||||
|
||||
self.fields['workouts'] = forms.MultipleChoiceField(
|
||||
|
||||
@@ -105,19 +105,17 @@ def is_session_complete(r,ps):
|
||||
elif ps.sessionunit == 'km':
|
||||
value *= 1000.
|
||||
|
||||
print score,value,ps.sessionvalue,ps.sessionunit
|
||||
|
||||
ratio = score/float(value)
|
||||
|
||||
status = 'partial'
|
||||
|
||||
if ps.sessiontype == 'training':
|
||||
if ps.sessioncriterium == 'exact':
|
||||
if ps.sessiontype == 'session':
|
||||
if ps.criterium == 'exact':
|
||||
if ratio == 1.0:
|
||||
return ratio,'completed'
|
||||
else:
|
||||
return ratio,'partial'
|
||||
elif ps.sessioncriterium == 'minimum':
|
||||
elif ps.criterium == 'minimum':
|
||||
if ratio > 1.0:
|
||||
return ratio,'completed'
|
||||
else:
|
||||
@@ -133,12 +131,12 @@ def is_session_complete(r,ps):
|
||||
else:
|
||||
return ratio,'partial'
|
||||
elif ps.sessiontype == 'challenge':
|
||||
if ps.sessioncriterium == 'exact':
|
||||
if ps.criterium == 'exact':
|
||||
if ratio == 1.0:
|
||||
return ratio,'completed'
|
||||
else:
|
||||
return ratio,'partial'
|
||||
elif ps.sessioncriterium == 'minimum':
|
||||
elif ps.criterium == 'minimum':
|
||||
if ratio > 1.0:
|
||||
return ratio,'completed'
|
||||
else:
|
||||
|
||||
@@ -4,6 +4,18 @@
|
||||
|
||||
{% 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 %}
|
||||
<div class="grid_12 alpha">
|
||||
{% include "planningbuttons.html" %}
|
||||
@@ -72,3 +84,22 @@
|
||||
|
||||
</form>
|
||||
{% 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+)/deleteconfirm$',views.plannedsession_deleteconfirm_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/?$',
|
||||
views.plannedsessions_manage_view),
|
||||
url(r'^sessions/manage/rower/(?P<rowerid>\d+)$',
|
||||
|
||||
@@ -11724,6 +11724,11 @@ def plannedsession_create_view(request):
|
||||
comment = cd['comment']
|
||||
name = cd['name']
|
||||
|
||||
if sessionunit == 'min':
|
||||
sessionmode = 'time'
|
||||
elif sessionunit in ['km','m']:
|
||||
sessionmode = 'distance'
|
||||
|
||||
ps = PlannedSession(
|
||||
name=name,
|
||||
startdate=startdate,
|
||||
@@ -11786,7 +11791,12 @@ def plannedsessions_view(request,timeperiod='today',rowerid=0):
|
||||
})
|
||||
|
||||
@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:
|
||||
r = getrower(request.user)
|
||||
@@ -11799,10 +11809,12 @@ def plannedsessions_manage_view(request,timeperiod='today',rowerid=0):
|
||||
raise Http404("You don't have access to this plan")
|
||||
|
||||
startdate,enddate = get_dates_timeperiod(timeperiod)
|
||||
|
||||
|
||||
|
||||
|
||||
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(
|
||||
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 = []
|
||||
|
||||
for ps in sps:
|
||||
@@ -11828,6 +11842,8 @@ def plannedsessions_manage_view(request,timeperiod='today',rowerid=0):
|
||||
for w in ws:
|
||||
wtpl = (w.id, w.__unicode__())
|
||||
choices.append(wtpl)
|
||||
if w.id in initialworkouts:
|
||||
workoutdata['initial'].append(w.id)
|
||||
|
||||
workoutdata['choices'] = tuple(choices)
|
||||
|
||||
@@ -11856,8 +11872,25 @@ def plannedsessions_manage_view(request,timeperiod='today',rowerid=0):
|
||||
messages.error(request,er)
|
||||
|
||||
|
||||
ps_form = PlannedSessionSelectForm(plannedsessionstuple)
|
||||
ps_form = PlannedSessionSelectForm(plannedsessionstuple,
|
||||
initialsession=initialsession)
|
||||
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',
|
||||
{
|
||||
@@ -11896,6 +11929,12 @@ def plannedsession_edit_view(request,id=0):
|
||||
sessionmode = cd['sessionmode']
|
||||
sessionvalue = cd['sessionvalue']
|
||||
sessionunit = cd['sessionunit']
|
||||
|
||||
if sessionunit == 'min':
|
||||
sessionmode = 'time'
|
||||
elif sessionunit in ['km','m']:
|
||||
sessionmode = 'distance'
|
||||
|
||||
comment = cd['comment']
|
||||
name = cd['name']
|
||||
|
||||
@@ -11952,8 +11991,6 @@ def plannedsession_view(request,id=0,rowerid=0):
|
||||
|
||||
ratio,status = is_session_complete(r,ps)
|
||||
|
||||
print ratio
|
||||
|
||||
ratio = int(100.*ratio)
|
||||
|
||||
return render(request,'plannedsessionview.html',
|
||||
|
||||
Reference in New Issue
Block a user