Skip to content
Snippets Groups Projects

Používání mo.web.fields

Merged Jiří Kalvoda requested to merge jk/fields into devel
All threads resolved!
1 file
+ 18
57
Compare changes
  • Side-by-side
  • Inline
+ 18
57
@@ -40,50 +40,11 @@ class UsersFilterForm(PagerForm):
@@ -40,50 +40,11 @@ class UsersFilterForm(PagerForm):
submit = wtforms.SubmitField("Filtrovat")
submit = wtforms.SubmitField("Filtrovat")
# Výstupní hodnoty filtru, None při nepoužitém filtru, prázdná db hodnota při
# nepovedené filtraci (neexistující místo a podobně)
f_search_name: Optional[str] = None
f_search_email: Optional[str] = None
f_year: Optional[int] = None
f_school: Optional[db.Place] = None
f_round_year: Optional[int] = None
f_round_category: Optional[str] = None
f_round_seq: Optional[int] = None
f_contest_site: Optional[db.Place] = None
f_participation_state: Optional[db.PartState] = None
def __init__(self, **kwargs):
def __init__(self, **kwargs):
super().__init__(**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_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'))
@app.route('/org/user/', methods=('GET', 'POST'))
def org_users():
def org_users():
@@ -97,29 +58,29 @@ def org_users():
@@ -97,29 +58,29 @@ def org_users():
if request.args:
if request.args:
filter.validate()
filter.validate()
if filter.f_search_name:
if filter.search_name.data:
q = q.filter(or_(
q = q.filter(or_(
db.User.first_name.ilike(filter.f_search_name),
db.User.first_name.ilike(f"%{filter.search_name.data}%"),
db.User.last_name.ilike(filter.f_search_name)
db.User.last_name .ilike(f"%{filter.search_name.data}%")
))
))
if filter.f_search_email:
if filter.search_email.data:
q = q.filter(db.User.email.ilike(filter.f_search_email))
q = q.filter(db.User.email.ilike(f"%{filter.search_email.data}%"))
if filter.f_year or filter.f_school:
if filter.year.data or filter.school.place:
participant_filter = sess.query(db.Participant.user_id)
participant_filter = sess.query(db.Participant.user_id)
if filter.f_year:
if filter.year.data:
participant_filter = participant_filter.filter_by(year=filter.f_year)
participant_filter = participant_filter.filter_by(year=filter.year.data)
if filter.f_school:
if filter.school.place:
participant_filter = participant_filter.filter_by(school=filter.f_school.place_id)
participant_filter = participant_filter.filter_by(school=filter.school.place.place_id)
q = q.filter(db.User.user_id.in_(participant_filter))
q = q.filter(db.User.user_id.in_(participant_filter))
round_filter = sess.query(db.Round.round_id)
round_filter = sess.query(db.Round.round_id)
round_filter_apply = False
round_filter_apply = False
if filter.f_round_year:
if filter.round_year.data:
round_filter = round_filter.filter_by(year=filter.f_round_year)
round_filter = round_filter.filter_by(year=filter.round_year.data)
round_filter_apply = True
round_filter_apply = True
if filter.f_round_category:
if filter.round_category.data and filter.round_category.data != "*":
round_filter = round_filter.filter_by(category=filter.f_round_category)
round_filter = round_filter.filter_by(category=filter.round_category.data)
round_filter_apply = True
round_filter_apply = True
if filter.round_seq.data and filter.round_seq.data != "*":
if filter.round_seq.data and filter.round_seq.data != "*":
round_filter = round_filter.filter_by(seq=filter.round_seq.data)
round_filter = round_filter.filter_by(seq=filter.round_seq.data)
@@ -130,8 +91,8 @@ def org_users():
@@ -130,8 +91,8 @@ def org_users():
if round_filter_apply:
if round_filter_apply:
contest_filter = contest_filter.filter(db.Contest.round_id.in_(round_filter))
contest_filter = contest_filter.filter(db.Contest.round_id.in_(round_filter))
contest_filter_apply = True
contest_filter_apply = True
if filter.f_contest_site:
if filter.contest_site.place:
contest_filter = contest_filter.filter_by(place_id=filter.f_contest_site.place_id)
contest_filter = contest_filter.filter_by(place_id=filter.contest_site.place.place_id)
contest_filter_apply = True
contest_filter_apply = True
participation_filter = sess.query(db.Participation.user_id)
participation_filter = sess.query(db.Participation.user_id)
@@ -139,8 +100,8 @@ def org_users():
@@ -139,8 +100,8 @@ def org_users():
if contest_filter_apply:
if contest_filter_apply:
participation_filter = participation_filter.filter(db.Participation.contest_id.in_(contest_filter))
participation_filter = participation_filter.filter(db.Participation.contest_id.in_(contest_filter))
participation_filter_apply = True
participation_filter_apply = True
if filter.f_participation_state:
if filter.participation_state.data and filter.participation_state.data != '*':
participation_filter = participation_filter.filter_by(state=filter.f_participation_state)
participation_filter = participation_filter.filter_by(state=filter.participation_state.data)
participation_filter_apply = True
participation_filter_apply = True
if participation_filter_apply:
if participation_filter_apply:
Loading