join works
This commit is contained in:
@@ -188,8 +188,11 @@ def join_workouts(r,ids,title='Joined Workout',
|
||||
makeprivate = False
|
||||
startdatetime = timezone.now()
|
||||
|
||||
if setprivate:
|
||||
if setprivate == True and makeprivate == False:
|
||||
makeprivate = True
|
||||
elif setprivate == False and makeprivate == True:
|
||||
makeprivate = False
|
||||
|
||||
|
||||
# reorder in chronological order
|
||||
ws = Workout.objects.filter(id__in=ids).order_by("date", "starttime")
|
||||
@@ -864,6 +867,7 @@ def save_workout_database(f2, r, dosmooth=True, workouttype='rower',
|
||||
pytz.timezone(timezone_str)
|
||||
).strftime('%H:%M:%S')
|
||||
|
||||
|
||||
if makeprivate:
|
||||
privacy = 'hidden'
|
||||
else:
|
||||
|
||||
@@ -522,6 +522,10 @@ class ChartParamChoiceForm(forms.Form):
|
||||
formaxlabels.pop('time')
|
||||
metricchoices = list(sorted(formaxlabels.items(), key = lambda x:x[1]))
|
||||
|
||||
class WorkoutJoinParamForm(forms.Form):
|
||||
workout_name = forms.CharField(required = True, initial = 'Joined Workout')
|
||||
set_private = forms.BooleanField(initial=False, required = False)
|
||||
|
||||
class FusionMetricChoiceForm(ModelForm):
|
||||
class Meta:
|
||||
model = Workout
|
||||
|
||||
@@ -147,6 +147,9 @@
|
||||
<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>
|
||||
<table>
|
||||
{{ joinparamform.as_table }}
|
||||
</table>
|
||||
<div class="grid_1 prefix_2 suffix_1">
|
||||
<p>
|
||||
{% csrf_token %}
|
||||
|
||||
@@ -46,7 +46,7 @@ from rowers.forms import (
|
||||
RegistrationFormUniqueEmail,CNsummaryForm,UpdateWindForm,
|
||||
UpdateStreamForm,WorkoutMultipleCompareForm,ChartParamChoiceForm,
|
||||
FusionMetricChoiceForm,BoxPlotChoiceForm,MultiFlexChoiceForm,
|
||||
TrendFlexModalForm,WorkoutSplitForm,
|
||||
TrendFlexModalForm,WorkoutSplitForm,WorkoutJoinParamForm,
|
||||
)
|
||||
from rowers.models import Workout, User, Rower, WorkoutForm,FavoriteChart
|
||||
from rowers.models import (
|
||||
@@ -4207,14 +4207,20 @@ def workouts_join_view(request):
|
||||
|
||||
if request.method == 'POST' and 'workouts' in request.POST:
|
||||
form = WorkoutMultipleCompareForm(request.POST)
|
||||
if form.is_valid():
|
||||
paramform = WorkoutJoinParamForm(request.POST)
|
||||
if form.is_valid() and paramform.is_valid():
|
||||
workout_name = paramform.cleaned_data['workout_name']
|
||||
set_private = paramform.cleaned_data['set_private']
|
||||
|
||||
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)
|
||||
id,message = dataprep.join_workouts(r,ids,
|
||||
title=workout_name,
|
||||
setprivate=set_private)
|
||||
|
||||
if message:
|
||||
messages.error(request,message)
|
||||
@@ -4227,7 +4233,8 @@ def workouts_join_view(request):
|
||||
return HttpResponseRedirect(url)
|
||||
|
||||
else:
|
||||
return HttpResponse("Form is not valid")
|
||||
return HttpResponse("form is not valid")
|
||||
|
||||
else:
|
||||
url = reverse(workouts_join_select)
|
||||
return HttpResponseRedirect(url)
|
||||
@@ -4368,7 +4375,7 @@ def workouts_join_select(request,
|
||||
else:
|
||||
theid = 0
|
||||
|
||||
chartform = ChartParamChoiceForm(initial={'teamid':0})
|
||||
joinparamform = WorkoutJoinParamForm()
|
||||
modalityform = TrendFlexModalForm(initial={
|
||||
'modality':modality,
|
||||
'waterboattype':waterboattype
|
||||
@@ -4385,7 +4392,7 @@ def workouts_join_select(request,
|
||||
'enddate':enddate,
|
||||
'team':theteam,
|
||||
'form':form,
|
||||
'chartform':chartform,
|
||||
'joinparamform':joinparamform,
|
||||
'modalityform':modalityform,
|
||||
'teams':get_my_teams(request.user),
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user