Workout With Friends Stay fit with a little motivation

- Main Page
- Namespaces
- Classes
- Files

- File List
- File Members

All Classes Namespaces Files Functions Variables Properties
workout.py
Go to the documentation of this file.
1 from __future__ import unicode_literals
2 from cgi import FieldStorage
3 from wowf.forms import Form
4 from wowf.lib.utils import parse_workout_report
5 from wowf.lib.validators import FileType
6 from wtforms import validators
7 from wtforms.fields import FileField, IntegerField
8
9
10 class UploadWorkoutForm(Form):
11 pass
12
13
14 class UploadDeviceWorkoutForm(UploadWorkoutForm):
15
16 _samples = {}
17 workout_report = FileField('Workout report', [
18 FileType(['csv'], message='Workout report must be a %(allowed)s')])
19
20 def validate_workout_report(self, field):
21 if not isinstance(field.data, FieldStorage):
22 raise validators.ValidationError('Must upload workout report')
23 self._samples = parse_workout_report(field.data.file)
24 if not (self._samples and self._samples['timestamp']):
25 raise validators.ValidationError('Workout report is invalid format')
26
27
28 class UploadWeightWorkoutForm(UploadWorkoutForm):
29
30 repetitions = IntegerField('Repetitions', [
31 validators.Required(message='Must enter your repetitions'),
32 validators.NumberRange(min=0, message='Repetitions must be at least %(min)d')])
33
34
35 class UploadSpeedWorkoutForm(UploadDeviceWorkoutForm):
36
37 def upload_workout(self, user, challenge):
38 workout = user.create_speed_workout(challenge, self._samples)
39 return workout
40
41
42 class UploadEnduranceWorkoutForm(UploadDeviceWorkoutForm):
43
44 def upload_workout(self, user, challenge):
45 workout = user.create_endurance_workout(challenge, self._samples)
46 return workout
47
48
49 class UploadBenchPressWorkoutForm(UploadWeightWorkoutForm):
50
51 def upload_workout(self, user, challenge):
52 workout = user.create_bench_press_workout(challenge, self.repetitions.data)
53 return workout
54
55
56 class UploadSquatWorkoutForm(UploadWeightWorkoutForm):
57
58 def upload_workout(self, user, challenge):
59 workout = user.create_squat_workout(challenge, self.repetitions.data)
60 return workout
61