improved workout edit form
This commit is contained in:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user