source: OpenWorkouts-current/ow/schemas/workout.py @ 5ec3a0b

currentfeature/docs
Last change on this file since 5ec3a0b was 5ec3a0b, checked in by borja <borja@…>, 5 years ago

Imported sources from the old python2-only repository:

  • Modified the code so it is python 3.6 compatible
  • Fixed deprecation warnings, pyramid 1.10.x supported now
  • Fixed deprecation warnings about some libraries, like pyramid-simpleform
  • Added pytest-pycodestyle and pytest-flakes for automatic checks on the source code files when running tests.
  • Added default pytest.ini setup to enforce some default parameters when running tests.
  • Cleaned up the code a bit, catched up with tests coverage.
  • Property mode set to 100644
File size: 1.8 KB
Line 
1from formencode import Schema, validators
2
3from ow.schemas.blob import FieldStorageBlob
4
5
6class 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
20class 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
40class 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'])
Note: See TracBrowser for help on using the repository browser.