Private
Public Access
1
0

join working but needs improvement (form with title)

This commit is contained in:
Sander Roosendaal
2017-11-22 18:06:45 +01:00
parent 6a76ba05fa
commit 618e64579c
5 changed files with 269 additions and 3 deletions

View File

@@ -158,6 +158,69 @@ def filter_df(datadf, fieldname, value, largerthan=True):
return datadf
# joins workouts
def join_workouts(r,ids,title='Joined Workout',
parent=None,
setprivate=False,
forceunit='lbs'):
message = None
summary = ''
if parent:
oarlength = parent.oarlength
inboard = parent.inboard
workouttype = parent.workouttype
notes = parent.notes
summary = parent.summary
if parent.privacy == 'hidden':
makeprivate = True
else:
makeprivate = False
startdatetime = parent.startdatetime
else:
oarlength = 2.89
inboard = 0.88
workouttype = 'rower'
notes = ''
summary = ''
makeprivate = False
startdatetime = timezone.now()
if setprivate:
makeprivate = True
# reorder in chronological order
ws = Workout.objects.filter(id__in=ids).order_by("date", "starttime")
files = [w.csvfilename for w in ws]
row = rdata(files[0])
files = files[1:]
while len(files):
row2 = rdata(files[0])
if row2 != 0:
row = row+row2
files = files[1:]
timestr = strftime("%Y%m%d-%H%M%S")
csvfilename = 'media/df_' + timestr + '.csv'
row.write_csv(csvfilename,gzip=True)
id, message = save_workout_database(csvfilename, r,
workouttype=workouttype,
title=title,
notes=notes,
oarlength=oarlength,
inboard=inboard,
makeprivate=makeprivate,
dosmooth=False,
consistencychecks=False)
return (id, message)
def df_resample(datadf):
# time stamps must be in seconds

View File

@@ -146,7 +146,7 @@
<div id="form_settings" class="grid_4 alpha">
<p><b>Warning: You are on an experimental part of the site. Use at your own risk.</b></p>
<p>Select two or more workouts on the left, set your plot settings below,
and press submit"</p>
and press submit</p>
{% csrf_token %}
<table>
{{ chartform.as_table }}

View File

@@ -0,0 +1,164 @@
{% extends "base.html" %}
{% load staticfiles %}
{% load rowerfilters %}
{% block title %}Workouts{% endblock %}
{% block content %}
<script>
function toggle(source) {
checkboxes = document.querySelectorAll("input[name='workouts']");
for(var i=0, n=checkboxes.length;i<n;i++) {
checkboxes[i].checked = source.checked;
}
}
</script>
<script src="https://code.jquery.com/jquery-1.9.1.min.js"></script>
<script>
$(function() {
// Get the form fields and hidden div
var modality = $("#id_modality");
var hidden = $("#id_waterboattype");
// Hide the fields.
// Use JS to do this in case the user doesn't have JS
// enabled.
hidden.hide();
// Setup an event listener for when the state of the
// checkbox changes.
modality.change(function() {
// Check to see if the checkbox is checked.
// If it is, show the fields and populate the input.
// If not, hide the fields.
var Value = modality.val();
if (Value=='water') {
// Show the hidden fields.
hidden.show();
} else {
// Make sure that the hidden fields are indeed
// hidden.
hidden.hide();
// You may also want to clear the value of the
// hidden fields here. Just in case somebody
// shows the fields, enters data to them and then
// unticks the checkbox.
//
// This would do the job:
//
// $("#hidden_field").val("");
}
});
});
</script>
<div class="grid_12 alpha">
{% include "teambuttons.html" with teamid=team.id team=team %}
</div>
<div class="grid_12 alpha">
<h3>{{ team.name }} Team Workouts</h3>
</div>
<div class="grid_12 alpha">
<div class="grid_6 alpha">
{% if team %}
<form enctype="multipart/form-data" action="/rowers/workouts-join-select/team/{{ team.id }}/" method="post">
{% else %}
<form enctype="multipart/form-data" action="/rowers/workouts-join-select/" method="post">
{% endif %}
<div class="grid_4 alpha">
<table>
{{ dateform.as_table }}
</table>
{% csrf_token %}
</div>
<div class="grid_2 omega">
<input name='daterange' class="button green" type="submit" value="Submit">
</div>
</form>
{% if team %}
<form enctype="multipart/form-data" action="/rowers/workouts-join-select/team/{{ team.id }}/" method="post">
{% else %}
<form enctype="multipart/form-data" action="/rowers/workouts-join-select/" method="post">
{% endif %}
<div class="grid_4 alpha">
<table>
{{ modalityform.as_table }}
</table>
{% csrf_token %}
</div>
<div class="grid_2 omega">
<input name='modalityform' class="button green" type="submit" value="Submit">
</div>
</form>
</div>
<div class="grid_5 prefix_1 omega">
{% if team %}
<form id="searchform" action="/rowers/workouts-join-select/team/{{ team.id }}/{{ startdate|date:"Y-m-d" }}/{{ enddate|date:"Y-m-d" }}"
method="get" accept-charset="utf-8">
{% else %}
<form id="searchform" action="/rowers/workouts-join-select/{{ startdate|date:"Y-m-d" }}/{{ enddate|date:"Y-m-d" }}"
method="get" accept-charset="utf-8">
{% endif %}
<div class="grid_3 prefix_1 alpha">
<input class="searchfield" id="searchbox" name="q" type="text" placeholder="Search">
</div>
<div class="grid_1 omega">
<button class="button blue small" type="submit">
Search
</button>
</div>
</form>
</div>
</div>
<form enctype="multipart/form-data" action="/rowers/workouts-join" method="post">
<div id="workouts_table" class="grid_8 alpha">
{% if workouts %}
<input type="checkbox" onClick="toggle(this)" /> Toggle All<br/>
<table width="100%" class="listtable">
{{ form.as_table }}
</table>
{% else %}
<p> No workouts found </p>
{% endif %}
</div>
<div id="form_settings" class="grid_4 alpha">
<p><b>Warning: You are on an experimental part of the site. Use at your own risk.</b></p>
<p>Select two or more workouts on the left,
and press submit</p>
<div class="grid_1 prefix_2 suffix_1">
<p>
{% csrf_token %}
<input name='workoutselectform' class="button green" type="submit" value="Submit">
</p>
</div>
<div class="grid_4">
<p>You can use the date and search forms above to search through all
workouts from this team.</p>
</div>
</div>
</form>
{% endblock %}

View File

@@ -132,6 +132,7 @@ urlpatterns = [
url(r'^team-compare-select/(?P<startdatestring>\w+.*)/(?P<enddatestring>\w+.*)$',views.team_comparison_select),
url(r'^team-compare-select/$',views.team_comparison_select),
url(r'^workouts-join-select/team/(?P<teamid>\d+)/(?P<startdatestring>\w+.*)/(?P<enddatestring>\w+.*)$',views.workouts_join_select),
url(r'^workouts-join$',views.workouts_join_view),
url(r'^workouts-join-select/team/(?P<teamid>\d+)/$',views.workouts_join_select),
url(r'^workouts-join-select/(?P<startdatestring>\w+.*)/(?P<enddatestring>\w+.*)$',views.workouts_join_select),
url(r'^workouts-join-select/$',views.workouts_join_select),

View File

@@ -4191,6 +4191,43 @@ def workout_setprivate_view(request,id,
return HttpResponseRedirect(url)
# Joining workout
@user_passes_test(ispromember,login_url="/",redirect_field_name=None)
def workouts_join_view(request):
promember=0
if not request.user.is_anonymous():
r = getrower(request.user)
result = request.user.is_authenticated() and ispromember(request.user)
if result:
promember=1
if request.method == 'POST' and 'workouts' in request.POST:
form = WorkoutMultipleCompareForm(request.POST)
if form.is_valid():
cd = form.cleaned_data
workouts = cd['workouts']
ids = [int(w.id) for w in workouts]
request.session['ids'] = ids
id,message = dataprep.join_workouts(r,ids)
if message:
messages.error(request,message)
url = reverse(workout_edit_view,
kwargs = {
'id':int(id),
})
return HttpResponseRedirect(url)
else:
return HttpResponse("Form is not valid")
else:
url = reverse(workouts_join_select)
return HttpResponseRedirect(url)
@user_passes_test(ispromember,login_url="/",redirect_field_name=None)
def workouts_join_select(request,
startdatestring="",
@@ -4337,7 +4374,7 @@ def workouts_join_select(request,
messages.info(request,successmessage)
messages.error(request,message)
return render(request, 'team_compare_select.html',
return render(request, 'workout_join_select.html',
{'workouts': workouts,
'dateform':dateform,
'startdate':startdate,
@@ -8816,7 +8853,8 @@ def workout_upload_view(request,
optionsform = UploadOptionsForm(request.POST)
if form.is_valid():
f = request.FILES['file']
# f = request.FILES['file']
f = form.cleaned_data['file']
res = handle_uploaded_file(f)
t = form.cleaned_data['title']