Skip to content
Snippets Groups Projects
Commit 9f8fbf77 authored by Jiří Kalvoda's avatar Jiří Kalvoda
Browse files

Fields: UsersFilterForm

Oprava na formdata=request.args.
Rozdrobení metody validate na validate_[fields].
parent 4af2cc14
No related branches found
No related tags found
No related merge requests found
...@@ -28,14 +28,14 @@ class UsersFilterForm(PagerForm): ...@@ -28,14 +28,14 @@ class UsersFilterForm(PagerForm):
search_email = wtforms.TextField("E-mail") search_email = wtforms.TextField("E-mail")
# participants # participants
year = wtforms.IntegerField("Ročník") year = mo_fields.OptionalInt("Ročník")
school_code = wtforms.StringField("Škola") school = mo_fields.School()
# rounds->participations # rounds->participations
round_year = wtforms.IntegerField("Ročník") round_year = mo_fields.OptionalInt("Ročník")
round_category = wtforms.SelectField("Kategorie") round_category = wtforms.SelectField("Kategorie")
round_seq = wtforms.SelectField("Kolo") round_seq = wtforms.SelectField("Kolo")
contest_site_code = wtforms.StringField("Soutěžní oblast") contest_site = mo_fields.Place("Soutěžní oblast")
participation_state = wtforms.SelectField('Účast', choices=[('*', '*')] + list(db.PartState.choices())) participation_state = wtforms.SelectField('Účast', choices=[('*', '*')] + list(db.PartState.choices()))
submit = wtforms.SubmitField("Filtrovat") submit = wtforms.SubmitField("Filtrovat")
...@@ -52,34 +52,40 @@ class UsersFilterForm(PagerForm): ...@@ -52,34 +52,40 @@ class UsersFilterForm(PagerForm):
f_contest_site: Optional[db.Place] = None f_contest_site: Optional[db.Place] = None
f_participation_state: Optional[db.PartState] = None f_participation_state: Optional[db.PartState] = None
def __init__(self, formdata, **kwargs): def __init__(self, **kwargs):
super().__init__(formdata=formdata, **kwargs) super().__init__(**kwargs)
self.round_category.choices = ['*'] + sorted(db.get_categories()) self.round_category.choices = ['*'] + sorted(db.get_categories())
self.round_seq.choices = ['*'] + sorted(db.get_seqs()) self.round_seq.choices = ['*'] + sorted(db.get_seqs())
def validate(self): def validate_search_name(self, field):
self.f_search_name = f"%{self.search_name.data}%" if self.search_name.data else None self.f_search_name = f"%{field.data}%"
self.f_search_email = f"%{self.search_email.data}%" if self.search_email.data else None
self.f_year = self.year.data def validate_search_email(self, field):
self.f_round_year = self.round_year.data self.f_search_email = f"%{field.data}%"
if self.school_code.data: def validate_year(self, field):
self.f_school = db.get_place_by_code(self.school_code.data) self.f_year = field.data
if not self.f_school:
flash(f"Zadaná škola '{self.school_code.data}' neexistuje", "danger") def validate_round_year(self, field):
self.f_school = db.Place() self.f_round_year = field.data
if self.contest_site_code.data:
self.f_contest_site = db.get_place_by_code(self.contest_site_code.data) def validate_school(self, field):
if not self.f_contest_site: self.f_school = field.place
flash(f"Zadaná soutěžní oblast '{self.contest_site_code.data}' neexistuje", "danger")
self.f_contest_site = db.Place() def validate_contest_site(self, field):
self.f_contest_site = field.place
self.f_round_category = None if self.round_category.data == '*' else self.round_category.data
self.f_round_seq = None if self.round_seq.data == '*' else self.round_seq.data def validate_round_category(self, field):
self.f_participation_state = None if self.participation_state.data == '*' else self.participation_state.data self.f_round_category = None if field.data == '*' else field.data
def validate_round_seq(self, field):
@app.route('/org/user/') self.f_round_seq = None if field.data == '*' else field.data
def validate_participation_state(self, field):
self.f_participation_state = None if field.data == '*' else field.data
@app.route('/org/user/', methods=('GET', 'POST'))
def org_users(): def org_users():
sess = db.get_session() sess = db.get_session()
rr = g.gatekeeper.rights_generic() rr = g.gatekeeper.rights_generic()
...@@ -87,7 +93,8 @@ def org_users(): ...@@ -87,7 +93,8 @@ def org_users():
q = sess.query(db.User).filter_by(is_admin=False, is_org=False).options( q = sess.query(db.User).filter_by(is_admin=False, is_org=False).options(
subqueryload(db.User.participants).joinedload(db.Participant.school_place) subqueryload(db.User.participants).joinedload(db.Participant.school_place)
) )
filter = UsersFilterForm(request.args) filter = UsersFilterForm(formdata=request.args)
if request.args:
filter.validate() filter.validate()
if filter.f_search_name: if filter.f_search_name:
......
...@@ -20,7 +20,7 @@ ...@@ -20,7 +20,7 @@
{{ wtf.form_field(filter.round_seq) }} {{ wtf.form_field(filter.round_seq) }}
</div> </div>
<div class="col-sm-2"> <div class="col-sm-2">
{{ wtf.form_field(filter.contest_site_code, placeholder='Kód') }} {{ wtf.form_field(filter.contest_site, placeholder='Kód') }}
</div> </div>
<div class="col-sm-2"> <div class="col-sm-2">
{{ wtf.form_field(filter.participation_state) }} {{ wtf.form_field(filter.participation_state) }}
...@@ -32,7 +32,7 @@ ...@@ -32,7 +32,7 @@
{{ wtf.form_field(filter.year) }} {{ wtf.form_field(filter.year) }}
</div> </div>
<div class="col-sm-2"> <div class="col-sm-2">
{{ wtf.form_field(filter.school_code, placeholder='Kód') }} {{ wtf.form_field(filter.school, placeholder='Kód') }}
</div> </div>
<div class="col-sm-3"> <div class="col-sm-3">
{{ wtf.form_field(filter.search_name, placeholder='Libovolná část jména') }} {{ wtf.form_field(filter.search_name, placeholder='Libovolná část jména') }}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment