diff --git a/mo/imports.py b/mo/imports.py index dfd5e5213f8729333d7cb8d3e40db38f56972866..332845371d95707b1e7413dc63a52414fe76b523 100644 --- a/mo/imports.py +++ b/mo/imports.py @@ -16,8 +16,6 @@ import mo.util from mo.util import logger from mo.util_format import format_decimal -reason = "import" - class ImportType(db.MOEnum): participants = auto() @@ -191,7 +189,7 @@ class Import: def find_or_create_user(self, email: str, krestni: str, prijmeni: str, is_org: bool) -> Optional[db.User]: try: - user, is_new = mo.users.find_or_create_user(email, krestni, prijmeni, is_org, reason=reason) + user, is_new = mo.users.find_or_create_user(email, krestni, prijmeni, is_org, reason='import') except mo.CheckError as e: return self.error(str(e)) if is_new: @@ -215,7 +213,7 @@ class Import: def find_or_create_participant(self, user: db.User, year: int, school_id: int, birth_year: int, grade: str) -> Optional[db.Participant]: try: - part, is_new = mo.users.find_or_create_participant(user, year, school_id, birth_year, grade, reason=reason) + part, is_new = mo.users.find_or_create_participant(user, year, school_id, birth_year, grade, reason='import') except mo.CheckError as e: return self.error(str(e)) if is_new: @@ -224,7 +222,7 @@ class Import: def find_or_create_participation(self, user: db.User, contest: db.Contest, place: Optional[db.Place]) -> Optional[db.Participation]: try: - pion, is_new = mo.users.find_or_create_participation(user, contest, place, reason=reason) + pion, is_new = mo.users.find_or_create_participation(user, contest, place, reason='import') except mo.CheckError as e: return self.error(str(e)) if is_new: diff --git a/mo/users.py b/mo/users.py index bb9c43b4b19158f29ab1761437cd03dc8389c7e7..6fef5ec9ad8280e6f5bf6693abdb76782885de6e 100644 --- a/mo/users.py +++ b/mo/users.py @@ -49,7 +49,7 @@ def validate_and_find_school(kod: str) -> db.Place: return place -def find_or_create_user(email: str, krestni: str, prijmeni: str, is_org: bool, reason: str = "undef-reason") -> Tuple[db.User, bool]: +def find_or_create_user(email: str, krestni: str, prijmeni: str, is_org: bool, reason: str) -> Tuple[db.User, bool]: sess = db.get_session() user = sess.query(db.User).filter_by(email=email).one_or_none() is_new = user is None @@ -74,7 +74,7 @@ def find_or_create_user(email: str, krestni: str, prijmeni: str, is_org: bool, r return user, is_new -def find_or_create_participant(user: db.User, year: int, school_id: int, birth_year: int, grade: str, reason: str = "undef-reason") -> Tuple[db.Participant, bool]: +def find_or_create_participant(user: db.User, year: int, school_id: int, birth_year: int, grade: str, reason: str) -> Tuple[db.Participant, bool]: sess = db.get_session() part = sess.query(db.Participant).get((user.user_id, year)) is_new = part is None @@ -95,7 +95,7 @@ def find_or_create_participant(user: db.User, year: int, school_id: int, birth_y return part, is_new -def find_or_create_participation(user: db.User, contest: db.Contest, place: Optional[db.Place], reason: str = "undef-reason") -> Tuple[db.Participation, bool]: +def find_or_create_participation(user: db.User, contest: db.Contest, place: Optional[db.Place], reason: str) -> Tuple[db.Participation, bool]: if place is None: place = contest.place @@ -137,7 +137,7 @@ def normalize_email(addr: str) -> str: if m[0].isprintable(): raise mo.CheckError(f'E-mailová adresa obsahuje nepovolené znaky: {m[0]}') else: - raise mo.CheckError('E-mailová adresa obsahuje netisknutelné znaky: '+repr(m[0])) + raise mo.CheckError('E-mailová adresa obsahuje netisknutelné znaky: ' + repr(m[0])) try: # Tady úmyslně používáme knihovnu jen ke kontrole a ne k normalizaci, diff --git a/mo/web/org_contest.py b/mo/web/org_contest.py index 40e13cd3a12d6723507cec963c679f96f9930d9e..7e6c9e37c5eba5d50e1edd75c2769905999af834 100644 --- a/mo/web/org_contest.py +++ b/mo/web/org_contest.py @@ -1655,8 +1655,6 @@ class ParticipantAddForm(FlaskForm): def org_contest_add_user(id: int, site_id: Optional[int] = None): contest, master_contest, site, rr = get_contest_site_rr(id, site_id, right_needed=Right.manage_contest) - reason = "form-add-participation" - form = ParticipantAddForm() if site_id is not None: if not form.is_submitted(): @@ -1666,9 +1664,9 @@ def org_contest_add_user(id: int, site_id: Optional[int] = None): if form.validate_on_submit(): try: - user, is_new_user = mo.users.find_or_create_user(form.email.data, form.first_name.data, form.last_name.data, False, reason=reason) - participant, is_new_participant = mo.users.find_or_create_participant(user, contest.round.year, form.school.get_place_id(), form.birth_year.data, form.grade.data, reason=reason) - participation, is_new_participation = mo.users.find_or_create_participation(user, contest, form.participation_place.get_place(), reason=reason) + user, is_new_user = mo.users.find_or_create_user(form.email.data, form.first_name.data, form.last_name.data, False, reason='web') + participant, is_new_participant = mo.users.find_or_create_participant(user, contest.round.year, form.school.get_place_id(), form.birth_year.data, form.grade.data, reason='web') + participation, is_new_participation = mo.users.find_or_create_participation(user, contest, form.participation_place.get_place(), reason='web') except mo.CheckError as e: db.get_session().rollback() flash(f"{e}", "danger")