sort of working, good enough for now
This commit is contained in:
@@ -1179,6 +1179,8 @@ class Rower(models.Model):
|
||||
workoutnametemplate = WorkoutNameTemplateField(default=['date','name','distance','ownerfirst','ownerlast','duration','boattype','workouttype'])
|
||||
|
||||
# Access tokens
|
||||
training_plan_code = models.CharField(default='', max_length=200, blank=True, null=True)
|
||||
training_plan_secret = models.CharField(default='', max_length=200, blank=True, null=True)
|
||||
c2token = models.CharField(
|
||||
default='', max_length=200, blank=True, null=True)
|
||||
tokenexpirydate = models.DateTimeField(blank=True, null=True)
|
||||
@@ -5209,6 +5211,47 @@ class RowerBillingAddressForm(ModelForm):
|
||||
super(RowerBillingAddressForm, self).__init__(*args, **kwargs)
|
||||
self.fields['country'].required = True
|
||||
|
||||
class NextWeekPlanForm(ModelForm):
|
||||
# add some extra fields save_credentials and delete_existing to the form
|
||||
delete_existing = forms.BooleanField(required=False, initial=False, label="Remove any existing sessions")
|
||||
save_credentials = forms.BooleanField(required=False, initial=False, label="Save credentials for next time")
|
||||
|
||||
class Meta:
|
||||
model = Rower
|
||||
fields = ['training_plan_code',
|
||||
'training_plan_secret',
|
||||
'actualfit',
|
||||
'actualfatigue']
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
super(NextWeekPlanForm, self).__init__(*args, **kwargs)
|
||||
|
||||
def clean(self):
|
||||
cleaned_data = super(NextWeekPlanForm, self).clean()
|
||||
plan = cleaned_data.get('training_plan_code')
|
||||
secret = cleaned_data.get('training_plan_secret')
|
||||
save_credentials = cleaned_data.get('save_credentials')
|
||||
fitness = cleaned_data.get('actualfit')
|
||||
fatigue = cleaned_data.get('actualfatigue')
|
||||
|
||||
if not fitness or not fatigue:
|
||||
raise forms.ValidationError("You need to fill in fitness and fatigue")
|
||||
|
||||
r = self.instance
|
||||
r.actualfit = fitness
|
||||
r.actualfatigue = fatigue
|
||||
w = Workout.objects.filter(user=r).order_by('-date').exclude(duplicate=True)
|
||||
r.last_workout = w.last().id
|
||||
r.save()
|
||||
|
||||
if not plan or not secret:
|
||||
raise forms.ValidationError("Plan Code and Secret are required")
|
||||
if save_credentials:
|
||||
r.training_plan_code = plan
|
||||
r.training_plan_secret = secret
|
||||
r.save()
|
||||
|
||||
return cleaned_data
|
||||
|
||||
# Form to set rower's Email and Weight category
|
||||
class AccountRowerForm(ModelForm):
|
||||
|
||||
Reference in New Issue
Block a user