improved workout edit form
This commit is contained in:
@@ -1799,7 +1799,7 @@ 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,
|
||||
@@ -1808,35 +1808,14 @@ class WorkoutForm(ModelForm):
|
||||
|
||||
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):
|
||||
|
||||
@@ -17,6 +17,27 @@
|
||||
{% include "monitorjobs.html" %}
|
||||
<script type='text/javascript'
|
||||
src='https://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js'>
|
||||
</script>
|
||||
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js"></script>
|
||||
<script>
|
||||
$( document ).ready(function() {
|
||||
$('#id_workouttype').on('change', function(){
|
||||
if (
|
||||
$(this).val() == 'rower'
|
||||
|| $(this).val() == 'skierg'
|
||||
|| $(this).val() == 'dynamic'
|
||||
|| $(this).val() == 'sliders'
|
||||
|| $(this).val() == 'paddle'
|
||||
|| $(this).val() == 'snow'
|
||||
) {
|
||||
$('#id_boattype').toggle(false);
|
||||
$('#id_boattype').val('1x');
|
||||
} else {
|
||||
$('#id_boattype').toggle(true);
|
||||
}
|
||||
});
|
||||
$('#id_workouttype').change();
|
||||
});
|
||||
</script>
|
||||
{% endblock %}
|
||||
|
||||
@@ -107,16 +128,7 @@
|
||||
{{ form.as_table }}
|
||||
</table>
|
||||
{% csrf_token %}
|
||||
<div class="grid_2 prefix_2 alpha tooltip">
|
||||
{% if workout.privacy == 'visible' %}
|
||||
<a class="button blue small" href="/rowers/workout/{{ workout.id }}/setprivate">Set Private</a>
|
||||
<span class="tooltiptext">Only you can see this workout</span>
|
||||
{% else %}
|
||||
<a class="button blue small" href="/rowers/workout/{{ workout.id }}/makepublic">Make Public</a>
|
||||
<span class="tooltiptext">Make this workout visible to your teams and followers</span>
|
||||
{% endif %}
|
||||
</div>
|
||||
<div id="formbutton" class="grid_1 suffix_1 omega">
|
||||
<div id="formbutton" class="grid_1 prefix_2 suffix_1 omega">
|
||||
<input class="button green" type="submit" value="Save">
|
||||
</div>
|
||||
</form>
|
||||
|
||||
@@ -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
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user