Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Odevzdávací Systém MO
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Model registry
Analyze
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
MO-P
Odevzdávací Systém MO
Commits
cbe2ef05
Project 'mj/mo-submit' was moved to 'mo-p/osmo'. Please update any links and bookmarks that may still have the old path.
Commit
cbe2ef05
authored
Sep 28, 2021
by
Jiří Kalvoda
Browse files
Options
Downloads
Patches
Plain Diff
Users: find_or_create_user umí na požádání změnit účastníka na orga
parent
85b6e07a
Branches
Branches containing commit
No related tags found
1 merge request
!97
Import orgů
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
mo/imports.py
+1
-1
1 addition, 1 deletion
mo/imports.py
mo/users.py
+14
-4
14 additions, 4 deletions
mo/users.py
mo/web/org_contest.py
+1
-1
1 addition, 1 deletion
mo/web/org_contest.py
with
16 additions
and
6 deletions
mo/imports.py
+
1
−
1
View file @
cbe2ef05
...
@@ -195,7 +195,7 @@ class Import:
...
@@ -195,7 +195,7 @@ class Import:
def
find_or_create_user
(
self
,
email
:
str
,
krestni
:
Optional
[
str
],
prijmeni
:
Optional
[
str
],
is_org
:
bool
)
->
Optional
[
db
.
User
]:
def
find_or_create_user
(
self
,
email
:
str
,
krestni
:
Optional
[
str
],
prijmeni
:
Optional
[
str
],
is_org
:
bool
)
->
Optional
[
db
.
User
]:
try
:
try
:
user
,
is_new
=
mo
.
users
.
find_or_create_user
(
email
,
krestni
,
prijmeni
,
is_org
,
reason
=
'
import
'
)
user
,
is_new
,
is_change_user_to_org
=
mo
.
users
.
find_or_create_user
(
email
,
krestni
,
prijmeni
,
is_org
,
reason
=
'
import
'
)
except
mo
.
CheckError
as
e
:
except
mo
.
CheckError
as
e
:
return
self
.
error
(
str
(
e
))
return
self
.
error
(
str
(
e
))
if
is_new
:
if
is_new
:
...
...
This diff is collapsed.
Click to expand it.
mo/users.py
+
14
−
4
View file @
cbe2ef05
...
@@ -52,6 +52,11 @@ def validate_and_find_school(kod: str) -> db.Place:
...
@@ -52,6 +52,11 @@ def validate_and_find_school(kod: str) -> db.Place:
return
place
return
place
class
CheckErrorOrgIsUser
(
mo
.
CheckError
):
"""
Při požadavku na orga nalezen uživatel nebo opačně.
"""
pass
def
change_user_to_org
(
user
,
reason
:
str
):
def
change_user_to_org
(
user
,
reason
:
str
):
if
(
db
.
get_session
().
query
(
db
.
Participation
,
db
.
Contest
,
db
.
Round
)
if
(
db
.
get_session
().
query
(
db
.
Participation
,
db
.
Contest
,
db
.
Round
)
.
select_from
(
db
.
Participation
)
.
select_from
(
db
.
Participation
)
...
@@ -70,10 +75,11 @@ def change_user_to_org(user, reason: str):
...
@@ -70,10 +75,11 @@ def change_user_to_org(user, reason: str):
)
)
def
find_or_create_user
(
email
:
str
,
krestni
:
Optional
[
str
],
prijmeni
:
Optional
[
str
],
is_org
:
bool
,
reason
:
str
)
->
Tuple
[
db
.
User
,
bool
]:
def
find_or_create_user
(
email
:
str
,
krestni
:
Optional
[
str
],
prijmeni
:
Optional
[
str
],
is_org
:
bool
,
reason
:
str
,
allow_change_user_to_org
=
False
)
->
Tuple
[
db
.
User
,
bool
,
bool
]:
sess
=
db
.
get_session
()
sess
=
db
.
get_session
()
user
=
sess
.
query
(
db
.
User
).
filter_by
(
email
=
email
).
one_or_none
()
user
=
sess
.
query
(
db
.
User
).
filter_by
(
email
=
email
).
one_or_none
()
is_new
=
user
is
None
is_new
=
user
is
None
is_change_user_to_org
=
False
if
user
is
None
:
# HACK: Podmínku je nutné zapsat znovu místo užití is_new, jinak si s tím mypy neporadí
if
user
is
None
:
# HACK: Podmínku je nutné zapsat znovu místo užití is_new, jinak si s tím mypy neporadí
if
not
krestni
or
not
prijmeni
:
if
not
krestni
or
not
prijmeni
:
raise
mo
.
CheckError
(
'
Osoba s daným emailem zatím neexistuje, je nutné uvést její jméno.
'
)
raise
mo
.
CheckError
(
'
Osoba s daným emailem zatím neexistuje, je nutné uvést její jméno.
'
)
...
@@ -91,10 +97,14 @@ def find_or_create_user(email: str, krestni: Optional[str], prijmeni: Optional[s
...
@@ -91,10 +97,14 @@ def find_or_create_user(email: str, krestni: Optional[str], prijmeni: Optional[s
raise
mo
.
CheckError
(
f
'
Osoba již registrována s odlišným jménem
{
user
.
full_name
()
}
'
)
raise
mo
.
CheckError
(
f
'
Osoba již registrována s odlišným jménem
{
user
.
full_name
()
}
'
)
if
(
user
.
is_admin
or
user
.
is_org
)
!=
is_org
:
if
(
user
.
is_admin
or
user
.
is_org
)
!=
is_org
:
if
is_org
:
if
is_org
:
raise
mo
.
CheckError
(
'
Nelze předefinovat účastníka na organizátora
'
)
if
allow_change_user_to_org
:
change_user_to_org
(
user
,
reason
)
is_change_user_to_org
=
True
else
:
raise
CheckErrorOrgIsUser
(
'
Nelze předefinovat účastníka na organizátora.
'
)
else
:
else
:
raise
mo
.
CheckError
(
'
Nelze předefinovat organizátora na účastníka
'
)
raise
CheckError
(
'
Nelze předefinovat organizátora na účastníka
.
'
)
return
user
,
is_new
return
user
,
is_new
,
is_change_user_to_org
def
find_or_create_participant
(
user
:
db
.
User
,
year
:
int
,
school_id
:
Optional
[
int
],
birth_year
:
Optional
[
int
],
grade
:
Optional
[
str
],
reason
:
str
)
->
Tuple
[
db
.
Participant
,
bool
]:
def
find_or_create_participant
(
user
:
db
.
User
,
year
:
int
,
school_id
:
Optional
[
int
],
birth_year
:
Optional
[
int
],
grade
:
Optional
[
str
],
reason
:
str
)
->
Tuple
[
db
.
Participant
,
bool
]:
...
...
This diff is collapsed.
Click to expand it.
mo/web/org_contest.py
+
1
−
1
View file @
cbe2ef05
...
@@ -1634,7 +1634,7 @@ def org_contest_add_user(ct_id: int, site_id: Optional[int] = None):
...
@@ -1634,7 +1634,7 @@ def org_contest_add_user(ct_id: int, site_id: Optional[int] = None):
if
form
.
validate_on_submit
():
if
form
.
validate_on_submit
():
try
:
try
:
user
,
is_new_user
=
mo
.
users
.
find_or_create_user
(
form
.
email
.
data
,
form
.
first_name
.
data
,
form
.
last_name
.
data
,
False
,
reason
=
'
web
'
)
user
,
is_new_user
,
is_change_user_to_org
=
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
'
)
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
'
)
participation
,
is_new_participation
=
mo
.
users
.
find_or_create_participation
(
user
,
contest
,
form
.
participation_place
.
get_place
(),
reason
=
'
web
'
)
except
mo
.
CheckError
as
e
:
except
mo
.
CheckError
as
e
:
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
sign in
to comment