Private
Public Access
1
0

multicompare view line 330 urls.py

This commit is contained in:
Sander Roosendaal
2018-10-09 22:03:07 +02:00
parent c693655966
commit 40ec94d5b0
5 changed files with 209 additions and 192 deletions

View File

@@ -1,10 +1,10 @@
{% extends "base.html" %}
{% extends "newbase.html" %}
{% load staticfiles %}
{% load rowerfilters %}
{% block title %}View Comparison {% endblock %}
{% block content %}
{% block main %}
<script type="text/javascript" src="/static/js/bokeh-0.12.3.min.js"></script>
<script async="true" type="text/javascript">
@@ -13,58 +13,31 @@
{{ interactiveplot |safe }}
<script>
// Set things up to resize the plot on a window resize. You can play with
// the arguments of resize_width_height() to change the plot's behavior.
var plot_resize_setup = function () {
var plotid = Object.keys(Bokeh.index)[0]; // assume we have just one plot
var plot = Bokeh.index[plotid];
var plotresizer = function() {
// arguments: use width, use height, maintain aspect ratio
plot.resize_width_height(true, false, false);
};
window.addEventListener('resize', plotresizer);
plotresizer();
};
window.addEventListener('load', plot_resize_setup);
</script>
<h1>Interactive Comparison</h1>
<ul class="main-content">
<li class="grid_2">
<form enctype="multipart/form-data" action="/rowers/multi-compare" method="post">
{% csrf_token %}
<table>
{{ chartform.as_table }}
</table>
<style>
/* Need this to get the page in "desktop mode"; not having an infinite height.*/
html, body {height: 100%; margin:5px;}
</style>
<div class="grid_12 alpha">
{% include "teambuttons.html" with teamid=teamid team=team %}
</div>
<div class="grid_12">
<div id="workouts" class="grid_8 alpha">
<h1>Interactive Comparison</h1>
</div>
<div class="grid_4 omega">
<form enctype="multipart/form-data" action="/rowers/multi-compare" method="post">
{% csrf_token %}
<table>
{{ chartform.as_table }}
</table>
<div class="grid_1 prefix_2 suffix_1">
<p>
<input name='workoutselectform' class="button green" type="submit" value="Submit">
</p>
</form>
</li>
<li class="grid_4">
<div>
{{ the_div|safe }}
</div>
</form>
</div>
</div>
<div class="grid_12 alpha">
<div id="theplot" class="grid_12 alpha flexplot">
{{ the_div|safe }}
</div>
</div>
</li>
</ul>
{% endblock %}
{% block sidebar %}
{% include 'menu_workouts.html' %}
{% endblock %}

View File

@@ -29,7 +29,9 @@
hidden.hide();
if (modality.val() == 'water') {
hidden.show();
}
// Setup an event listener for when the state of the
// checkbox changes.
@@ -68,12 +70,25 @@
<ul class="main-content">
<li class="grid_4">
<p>Select two or more workouts on the left, set your plot settings,
and press submit</p>
<p>
You can use the date and search forms to search through all
workouts from this team.
</p>
<p>
TIP: Agree with your team members to put tags (e.g. '8x500m')
in the notes section of
your workouts. That makes it easy to search.
</p>
</li>
<li class="grid_2 maxheight">
{% if workouts %}
<form enctype="multipart/form-data" action="/rowers/multi-compare" method="post">
{% if workouts %}
<input type="checkbox" onClick="toggle(this)" /> Toggle All<br/>
<table width="100%" class="listtable">
{{ form.as_table }}
</table>
@@ -83,54 +98,42 @@
{% endif %}
</li>
<li class="grid_2">
<p>
{% csrf_token %}
<table>
{{ chartform.as_table }}
</table>
</p>
<p>
<input name="chartform" class="button green" type="submit" value="Submit">
</p>
</form>
</li>
<li class="grid_2">
{% if team %}
<form enctype="multipart/form-data"
action="/rowers/team-compare-select/team/{{ team.id }}"
method="post">
{% else %}
<form enctype="multipart/form-data"
action="/rowers/team-compare-select/"
method="post">
{% endif %}
<table>
{{ dateform.as_table }}
</table>
<table>
{{ modalityform.as_table }}
</table>
{% csrf_token %}
<p>
{% csrf_token %}
<table>
{{ chartform.as_table }}
</table>
</p>
<p>
<input name='workoutselectform' class="button green" type="submit" value="Submit">
<input name='modalityform' class="button green" type="submit" value="Submit">
</p>
</form>
</li>
<li>
{% if team %}
<form enctype="multipart/form-data" action="/rowers/team-compare-select/team/{{ team.id }}/" method="post">
{% else %}
<form enctype="multipart/form-data" action="/rowers/team-compare-select/" method="post">
{% endif %}
<table>
{{ dateform.as_table }}
</table>
</li>
<li>
<p>
{% csrf_token %}
<input name='daterange' class="button green" type="submit" value="Submit">
</p>
</form>
</li>
<li>
{% if team %}
<form enctype="multipart/form-data" action="/rowers/team-compare-select/team/{{ team.id }}/" method="post">
{% else %}
<form enctype="multipart/form-data" action="/rowers/team-compare-select/" method="post">
{% endif %}
<table>
{{ modalityform.as_table }}
</table>
</li>
<li>
{% csrf_token %}
<p>
<input name='modalityform' class="button green" type="submit" value="Submit">
</p>
</form>
</li>
<li class="grid_2">
{% if team %}
<form id="searchform" action="/rowers/team-compare-select/team/{{ team.id }}/{{ startdate|date:"Y-m-d" }}/{{ enddate|date:"Y-m-d" }}"
<form id="searchform" action=""
method="get" accept-charset="utf-8">
{% else %}
<form id="searchform" action="/rowers/team-compare-select/{{ startdate|date:"Y-m-d" }}/{{ enddate|date:"Y-m-d" }}"
@@ -142,19 +145,6 @@
</button>
</form>
</li>
<li>
<p>Select two or more workouts on the left, set your plot settings below,
and press submit</p>
<p>
You can use the date and search forms above to search through all
workouts from this team.
</p>
<p>
TIP: Agree with your team members to put tags (e.g. '8x500m')
in the notes section of
your workouts. That makes it easy to search.
</p>
</li>
</ul>
{% endblock %}

View File

@@ -107,9 +107,6 @@ $('#id_workouttype').change();
{{ workout.summary }}
</pre>
</p>
<p>
<a href="/rowers/workout/{{ workout.id }}/recalcsummary">Update Summary</a>
</p>
</li>
{% if mapdiv %}
<li class="grid_2">

View File

@@ -240,9 +240,9 @@ urlpatterns = [
url(r'^workout/(?P<id>\d+)/edit$',views.workout_edit_view,
name='workout_edit_view'),
url(r'^workout/(?P<id>\d+)/map$',views.workout_map_view),
url(r'^workout/(?P<id>\d+)/setprivate$',views.workout_setprivate_view),
# url(r'^workout/(?P<id>\d+)/setprivate$',views.workout_setprivate_view),
url(r'^workout/(?P<id>\d+)/updatecp$',views.workout_update_cp_view),
url(r'^workout/(?P<id>\d+)/makepublic$',views.workout_makepublic_view),
# url(r'^workout/(?P<id>\d+)/makepublic$',views.workout_makepublic_view),
# url(r'^workout/(?P<id>\d+)/geeky$',views.workout_geeky_view),
# url(r'^workout/(?P<id>\d+)/advanced$',views.workout_advanced_view),
url(r'^workout/(?P<id>\d+)/instroke/(?P<metric>\w+.*)$',views.instroke_chart),

View File

@@ -5136,21 +5136,16 @@ def team_comparison_select(request,
modalities = [m[0] for m in types.workouttypes]
modality = 'all'
if request.method == 'POST' and 'daterange' in request.POST:
if request.method == 'POST':
dateform = DateRangeForm(request.POST)
if dateform.is_valid():
startdate = dateform.cleaned_data['startdate']
enddate = dateform.cleaned_data['enddate']
startdatestring = startdate.strftime('%Y-%m-%d')
enddatestring = enddate.strftime('%Y-%m-%d')
else:
dateform = DateRangeForm(initial={
'startdate':startdate,
'enddate':enddate,
})
request.session['startdate'] = startdatestring
request.session['enddate'] = enddatestring
if request.method == 'POST' and 'modality' in request.POST:
modalityform = TrendFlexModalForm(request.POST)
if modalityform.is_valid():
modality = modalityform.cleaned_data['modality']
@@ -5171,6 +5166,19 @@ def team_comparison_select(request,
request.session['modalities'] = modalities
request.session['waterboattype'] = waterboattype
else:
dateform = DateRangeForm(initial={
'startdate':startdate,
'enddate':enddate,
})
modalityform = TrendFlexModalForm(initial={
'modality':modality,
'waterboattype':waterboattype,
'rankingonly':rankingonly,
})
negtypes = []
for b in types.boattypes:
@@ -5241,16 +5249,23 @@ def team_comparison_select(request,
theid = 0
chartform = ChartParamChoiceForm(initial={'teamid':0})
modalityform = TrendFlexModalForm(initial={
'modality':modality,
'waterboattype':waterboattype,
'rankingonly':rankingonly,
})
messages.info(request,successmessage)
messages.error(request,message)
r = getrower(request.user)
breadcrumbs = [
{
'url':'/rowers/list-workouts',
'name':'Workouts'
},
{
'url':reverse(team_comparison_select,kwargs={'teamid':teamid}),
'name': 'Compare Select'
},
]
return render(request, 'team_compare_select.html',
{'workouts': workouts,
'dateform':dateform,
@@ -5258,6 +5273,8 @@ def team_comparison_select(request,
'enddate':enddate,
'team':theteam,
'form':form,
'rower':r,
'breadcrumbs':breadcrumbs,
'active':'nav-workouts',
'chartform':chartform,
'modalityform':modalityform,
@@ -5303,9 +5320,27 @@ def multi_compare_view(request):
if errormessage != '':
messages.error(request,errormessage)
r = getrower(request.user)
breadcrumbs = [
{
'url':'/rowers/list-workouts',
'name':'Workouts'
},
{
'url':reverse(team_comparison_select,kwargs={'teamid':teamid}),
'name': 'Compare Select'
},
{
'url':reverse(multi_compare_view),
'name': 'Comparison Chart'
}
]
return render(request,'multicompare.html',
{'interactiveplot':script,
'the_div':div,
'breadcrumbs':breadcrumbs,
'rower':r,
'active':'nav-workouts',
'promember':promember,
'teamid':teamid,
'chartform':chartform,
@@ -5335,9 +5370,29 @@ def multi_compare_view(request):
script = res[0]
div = res[1]
r = getrower(request.user)
breadcrumbs = [
{
'url':'/rowers/list-workouts',
'name':'Workouts'
},
{
'url':reverse(team_comparison_select,kwargs={'teamid':teamid}),
'name': 'Compare Select'
},
{
'url':reverse(multi_compare_view),
'name': 'Comparison Chart'
}
]
return render(request,'multicompare.html',
{'interactiveplot':script,
'the_div':div,
'breadcrumbs':breadcrumbs,
'rower':r,
'active':'nav-workouts',
'promember':promember,
'teamid':teamid,
'chartform':chartform,
@@ -6475,74 +6530,76 @@ def workout_comparison_list(request,id=0,message='',successmessage='',
try:
r = getrower(request.user)
u = User.objects.get(id=r.user.id)
if request.method == 'POST':
dateform = DateRangeForm(request.POST)
if dateform.is_valid():
startdate = dateform.cleaned_data['startdate']
enddate = dateform.cleaned_data['enddate']
else:
dateform = DateRangeForm(initial={
'startdate':startdate,
'enddate':enddate,
})
if startdatestring:
startdate = iso8601.parse_date(startdatestring)
if enddatestring:
enddate = iso8601.parse_date(enddatestring)
startdate = datetime.datetime.combine(startdate,datetime.time())
enddate = datetime.datetime.combine(enddate,datetime.time(23,59,59))
#enddate = enddate+datetime.timedelta(days=1)
if enddate < startdate:
s = enddate
enddate = startdate
startdate = s
workouts = Workout.objects.filter(user=r,
startdatetime__gte=startdate,
startdatetime__lte=enddate).order_by("-date", "-starttime").exclude(id=id)
query = request.GET.get('q')
if query:
query_list = query.split()
workouts = workouts.filter(
reduce(operator.and_,
(Q(name__icontains=q) for q in query_list)) |
reduce(operator.and_,
(Q(notes__icontains=q) for q in query_list))
)
paginator = Paginator(workouts,15) # show 25 workouts per page
page = request.GET.get('page')
try:
workouts = paginator.page(page)
except PageNotAnInteger:
workouts = paginator.page(1)
except EmptyPage:
workouts = paginator.page(paginator.num_pages)
row = get_workout(id)
messages.error(request,message)
messages.info(request,successmessage)
return render(request, 'comparison_list.html',
{'id':int(id),
'workout':row,
'workouts': workouts,
'last_name':u.last_name,
'first_name':u.first_name,
'dateform':dateform,
'startdate':startdate,
'enddate':enddate,
'teams':get_my_teams(request.user),
})
except Rower.DoesNotExist:
raise Http404("User has no rower instance")
u = User.objects.get(id=r.user.id)
if request.method == 'POST':
dateform = DateRangeForm(request.POST)
if dateform.is_valid():
startdate = dateform.cleaned_data['startdate']
enddate = dateform.cleaned_data['enddate']
else:
dateform = DateRangeForm(initial={
'startdate':startdate,
'enddate':enddate,
})
if startdatestring:
startdate = iso8601.parse_date(startdatestring)
if enddatestring:
enddate = iso8601.parse_date(enddatestring)
startdate = datetime.datetime.combine(startdate,datetime.time())
enddate = datetime.datetime.combine(enddate,datetime.time(23,59,59))
#enddate = enddate+datetime.timedelta(days=1)
if enddate < startdate:
s = enddate
enddate = startdate
startdate = s
workouts = Workout.objects.filter(user=r,
startdatetime__gte=startdate,
startdatetime__lte=enddate).order_by("-date", "-starttime").exclude(id=id)
query = request.GET.get('q')
if query:
query_list = query.split()
workouts = workouts.filter(
reduce(operator.and_,
(Q(name__icontains=q) for q in query_list)) |
reduce(operator.and_,
(Q(notes__icontains=q) for q in query_list))
)
paginator = Paginator(workouts,15) # show 25 workouts per page
page = request.GET.get('page')
try:
workouts = paginator.page(page)
except PageNotAnInteger:
workouts = paginator.page(1)
except EmptyPage:
workouts = paginator.page(paginator.num_pages)
row = get_workout(id)
messages.error(request,message)
messages.info(request,successmessage)
return render(request, 'comparison_list.html',
{'id':int(id),
'workout':row,
'workouts': workouts,
'last_name':u.last_name,
'first_name':u.first_name,
'dateform':dateform,
'startdate':startdate,
'enddate':enddate,
'teams':get_my_teams(request.user),
})
# List of workouts to compare a selected workout to
@user_passes_test(ispromember,login_url="/",redirect_field_name=None)