-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathforms.py
More file actions
63 lines (49 loc) · 2.55 KB
/
Copy pathforms.py
File metadata and controls
63 lines (49 loc) · 2.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
from flask_wtf import FlaskForm
from wtforms import SelectField, SubmitField, StringField
from model import Results, Races, Racers
class RaceForm(FlaskForm):
name_date = StringField('name_date', id='name_date',
validators=[Races.validator])
submit = SubmitField('Show me this race!', id='race_name_submit')
def __init__(self, race_id, *args, **kwargs):
"""Instantiate the race name selection form. race_id is the id for
the currently selected race.
"""
super(RaceForm, self).__init__(*args, **kwargs)
# Filter to transform empty string into the currently selected race
self.name_date.filters = [lambda x: x or
Races.get_race_name_date(race_id)]
def reset_placeholder(self, race_id):
"""Clear form data and set placeholder text to the race name
corresponding to the given race_id."""
if self.name_date.data == '':
if self.name_date.errors:
self.name_date.errors.pop() # don't show errors for empty
self.name_date.description = Races.get_race_name_date(race_id)
self.name_date.data = ''
class CategoryForm(FlaskForm):
category = SelectField('Category: ', id='category')
submit = SubmitField('Show me this category!', id='category_submit')
def __init__(self, categories, *args, **kwargs):
super(CategoryForm, self).__init__(*args, **kwargs)
self.category.choices = categories
class RacerForm(FlaskForm):
racer_name = StringField('racer_name', id='racer_name',
validators=[Racers.validator])
# Filter to transform empty string into the currently selected racer
submit = SubmitField('Show me this racer!', id='racer_name_submit')
def __init__(self, RacerID, *args, **kwargs):
"""Instantiate the racer selection form. RacerID is the id for
the currently selected racer.
"""
super(RacerForm, self).__init__(*args, **kwargs)
# Filter to transform empty string into the currently selected racer
self.racer_name.filters = [lambda x: x or
Racers.get_racer_name(RacerID)]
def reset_placeholder(self, RacerID):
"""Clear form data and set placeholder text to the racer name
corresponding to the given RacerID."""
if self.racer_name.data == '':
self.racer_name.errors.pop() # don't show errors for empty string
self.racer_name.description = Racers.get_racer_name(RacerID)
self.racer_name.data = ''