1 | from formencode import Schema, validators |
---|
2 | |
---|
3 | from ow.schemas.blob import FieldStorageBlob |
---|
4 | |
---|
5 | |
---|
6 | class UploadedWorkoutSchema(Schema): |
---|
7 | """ |
---|
8 | Schema for a workout added with a fit, gpx, etc file. |
---|
9 | We ask only for the tracking file, title and notes, the rest of the workout |
---|
10 | data will be extracted from the uploaded file. |
---|
11 | """ |
---|
12 | allow_extra_fields = True |
---|
13 | filter_extra_fields = True |
---|
14 | title = validators.UnicodeString(if_missing='') |
---|
15 | notes = validators.UnicodeString(if_missing='') |
---|
16 | # This one can not be none, it is a required field |
---|
17 | tracking_file = FieldStorageBlob(not_empty=True, whitelist=['gpx', 'fit']) |
---|
18 | |
---|
19 | |
---|
20 | class ManualWorkoutSchema(Schema): |
---|
21 | """ |
---|
22 | Schema for a workout added manually |
---|
23 | """ |
---|
24 | allow_extra_fields = True |
---|
25 | filter_extra_fields = True |
---|
26 | sport = validators.UnicodeString(if_missing='') |
---|
27 | title = validators.UnicodeString(if_missing='') |
---|
28 | notes = validators.UnicodeString(if_missing='') |
---|
29 | start_date = validators.DateConverter(month_style='dd/mm/yyyy', |
---|
30 | not_empty=True) |
---|
31 | start_time = validators.TimeConverter(not_empty=True) |
---|
32 | # We split duration into three fields, so it is easier for users to provide |
---|
33 | # the full duration of a workout manually |
---|
34 | duration_hours = validators.Number(not_empty=True) |
---|
35 | duration_minutes = validators.Number(not_empty=True) |
---|
36 | duration_seconds = validators.Number(not_empty=True) |
---|
37 | distance = validators.Number(if_empty=0) |
---|
38 | |
---|
39 | |
---|
40 | class UpdateWorkoutSchema(Schema): |
---|
41 | """ |
---|
42 | Schema for the update of a workout using a fit, gpx, etc file. |
---|
43 | We ask only for the tracking file, any other data can be updated using |
---|
44 | the "manual update" view |
---|
45 | """ |
---|
46 | allow_extra_fields = True |
---|
47 | filter_extra_fields = True |
---|
48 | # This one can not be none, it is a required field |
---|
49 | tracking_file = FieldStorageBlob(not_empty=True, whitelist=['gpx', 'fit']) |
---|