diff --git a/mo/web/org_users.py b/mo/web/org_users.py
index bfe5e22b56a6e486d68049db216fe1faea482fc9..134aa2c1e4bc02795bb2ceebface420037d4fbc1 100644
--- a/mo/web/org_users.py
+++ b/mo/web/org_users.py
@@ -28,14 +28,14 @@ class UsersFilterForm(PagerForm):
search_email = wtforms.TextField("E-mail")
# participants
- year = wtforms.IntegerField("Ročník")
- school_code = wtforms.StringField("Škola")
+ year = mo_fields.OptionalInt("Ročník")
+ school = mo_fields.School()
# rounds->participations
- round_year = wtforms.IntegerField("Ročník")
+ round_year = mo_fields.OptionalInt("Ročník")
round_category = wtforms.SelectField("Kategorie")
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()))
submit = wtforms.SubmitField("Filtrovat")
@@ -52,34 +52,40 @@ class UsersFilterForm(PagerForm):
f_contest_site: Optional[db.Place] = None
f_participation_state: Optional[db.PartState] = None
- def __init__(self, formdata, **kwargs):
- super().__init__(formdata=formdata, **kwargs)
+ def __init__(self, **kwargs):
+ super().__init__(**kwargs)
self.round_category.choices = ['*'] + sorted(db.get_categories())
self.round_seq.choices = ['*'] + sorted(db.get_seqs())
- def validate(self):
- self.f_search_name = f"%{self.search_name.data}%" if self.search_name.data else None
- self.f_search_email = f"%{self.search_email.data}%" if self.search_email.data else None
- self.f_year = self.year.data
- self.f_round_year = self.round_year.data
-
- if self.school_code.data:
- self.f_school = db.get_place_by_code(self.school_code.data)
- if not self.f_school:
- flash(f"Zadaná škola '{self.school_code.data}' neexistuje", "danger")
- self.f_school = db.Place()
- if self.contest_site_code.data:
- self.f_contest_site = db.get_place_by_code(self.contest_site_code.data)
- if not self.f_contest_site:
- flash(f"Zadaná soutěžní oblast '{self.contest_site_code.data}' neexistuje", "danger")
- self.f_contest_site = db.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
- self.f_participation_state = None if self.participation_state.data == '*' else self.participation_state.data
-
-
-@app.route('/org/user/')
+ def validate_search_name(self, field):
+ self.f_search_name = f"%{field.data}%"
+
+ def validate_search_email(self, field):
+ self.f_search_email = f"%{field.data}%"
+
+ def validate_year(self, field):
+ self.f_year = field.data
+
+ def validate_round_year(self, field):
+ self.f_round_year = field.data
+
+ def validate_school(self, field):
+ self.f_school = field.place
+
+ def validate_contest_site(self, field):
+ self.f_contest_site = field.place
+
+ def validate_round_category(self, field):
+ self.f_round_category = None if field.data == '*' else field.data
+
+ def validate_round_seq(self, field):
+ 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():
sess = db.get_session()
rr = g.gatekeeper.rights_generic()
@@ -87,8 +93,8 @@ def org_users():
q = sess.query(db.User).filter_by(is_admin=False, is_org=False).options(
subqueryload(db.User.participants).joinedload(db.Participant.school_place)
)
- filter = UsersFilterForm(request.args)
- filter.validate()
+ filter = UsersFilterForm()
+ filter.validate_on_submit()
if filter.f_search_name:
q = q.filter(or_(
diff --git a/mo/web/templates/org_users.html b/mo/web/templates/org_users.html
index e1b2b2f6e54997fd51082177402df64b0d4fb752..c1c63aae0bd051342d551cc8d24cfbddcf7e4200 100644
--- a/mo/web/templates/org_users.html
+++ b/mo/web/templates/org_users.html
@@ -7,7 +7,8 @@
{% endif %}
<div class="form-frame">
-<form action="" method="GET" role="form">
+<form action="" method="POST" role="form">
+ {{ filter.csrf_token }}
<div class="row">
<div class='col-sm-2'><strong>Filtr podle účasti v kole:</strong></div>
<div class="col-sm-2">
@@ -20,7 +21,7 @@
{{ wtf.form_field(filter.round_seq) }}
</div>
<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 class="col-sm-2">
{{ wtf.form_field(filter.participation_state) }}
@@ -32,7 +33,7 @@
{{ wtf.form_field(filter.year) }}
</div>
<div class="col-sm-2">
- {{ wtf.form_field(filter.school_code, placeholder='Kód') }}
+ {{ wtf.form_field(filter.school, placeholder='Kód') }}
</div>
<div class="col-sm-3">
{{ wtf.form_field(filter.search_name, placeholder='Libovolná část jména') }}