From 229145679a60ab8d2c54f6370e5ec597ec7dd662 Mon Sep 17 00:00:00 2001 From: Sander Roosendaal Date: Fri, 8 Jun 2018 08:47:55 +0200 Subject: [PATCH] improved workout edit form --- rowers/models.py | 43 ++++++++---------------------- rowers/templates/workout_form.html | 32 +++++++++++++++------- rowers/views.py | 6 +++++ 3 files changed, 39 insertions(+), 42 deletions(-) diff --git a/rowers/models.py b/rowers/models.py index 737dd97b..8f6ebcac 100644 --- a/rowers/models.py +++ b/rowers/models.py @@ -1799,45 +1799,24 @@ class WorkoutForm(ModelForm): # duration = forms.TimeInput(format='%H:%M:%S.%f') class Meta: model = Workout - fields = ['name','date','starttime','timezone','duration','distance','workouttype','boattype','weightcategory','notes','privacy','rankingpiece'] + fields = ['name','date','starttime','timezone','duration','distance','workouttype','boattype','weightcategory','notes','rankingpiece'] widgets = { 'date': AdminDateWidget(), 'notes': forms.Textarea, 'duration': forms.TimeInput(format='%H:%M:%S.%f'), } - def __init__(self, *args, **kwargs): + def __init__(self, *args, **kwargs): super(WorkoutForm, self).__init__(*args, **kwargs) - # this line to be removed - del self.fields['privacy'] - - if self.instance.workouttype not in types.otwtypes: - del self.fields['boattype'] - - fieldorder = ( - 'name', - 'date', - 'starttime', - 'timezone', - 'duration', - 'distance', - 'workouttype', - 'weightcategory', - 'notes', - 'rankingpiece', - 'boattype' - ) - - fields = OrderedDict() - for key in fieldorder: - try: - fields[key] = self.fields.pop(key) - except KeyError: - pass - for key, valye in self.fields.items(): - fields[key] = value - self.fields = fields - + self.fields['private'] = forms.BooleanField(initial=False, + required=False, + label='Private') + if 'instance' in kwargs: + if kwargs['instance'].privacy == 'visible': + self.fields['private'].initial = False + else: + self.fields['private'].initial = True + # Used for the rowing physics calculations class AdvancedWorkoutForm(ModelForm): quick_calc = forms.BooleanField(initial=True,required=False) diff --git a/rowers/templates/workout_form.html b/rowers/templates/workout_form.html index 5160aec2..3cef35a9 100644 --- a/rowers/templates/workout_form.html +++ b/rowers/templates/workout_form.html @@ -17,6 +17,27 @@ {% include "monitorjobs.html" %} + + {% endblock %} @@ -107,16 +128,7 @@ {{ form.as_table }} {% csrf_token %} -
- {% if workout.privacy == 'visible' %} - Set Private - Only you can see this workout - {% else %} - Make Public - Make this workout visible to your teams and followers - {% endif %} -
-
+
diff --git a/rowers/views.py b/rowers/views.py index cdcee2fb..665b9d9c 100644 --- a/rowers/views.py +++ b/rowers/views.py @@ -9190,6 +9190,7 @@ def workout_edit_view(request,id=0,message="",successmessage=""): weightcategory = form.cleaned_data['weightcategory'] duration = form.cleaned_data['duration'] distance = form.cleaned_data['distance'] + private = form.cleaned_data['private'] notes = form.cleaned_data['notes'] thetimezone = form.cleaned_data['timezone'] @@ -9206,6 +9207,11 @@ def workout_edit_view(request,id=0,message="",successmessage=""): except KeyError: rankingpiece =- Workout.objects.get(id=id).rankingpiece + if private: + privacy = 'private' + else: + privacy = 'visible' + startdatetime = datetime.datetime.combine( date,starttime )