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
32d5abf6
Project 'mj/mo-submit' was moved to 'mo-p/osmo'. Please update any links and bookmarks that may still have the old path.
Commit
32d5abf6
authored
Mar 18, 2023
by
Martin Mareš
Browse files
Options
Downloads
Patches
Plain Diff
Abstrahován mechanismus zakládání soutěží
parent
f6d771fb
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
mo/contests.py
+66
-0
66 additions, 0 deletions
mo/contests.py
mo/web/org_round.py
+6
-61
6 additions, 61 deletions
mo/web/org_round.py
mo/web/user.py
+2
-1
2 additions, 1 deletion
mo/web/user.py
with
74 additions
and
62 deletions
mo/contests.py
0 → 100644
+
66
−
0
View file @
32d5abf6
# Pomocné funkce pro práci se soutěžemi
from
typing
import
Optional
import
mo.db
as
db
from
mo.rights
import
Right
,
Gatekeeper
import
mo.util
class
ContestError
(
RuntimeError
):
pass
def
add_contest
(
master_round
:
db
.
Round
,
place
:
db
.
Place
,
reason
:
str
,
gatekeeper
:
Optional
[
Gatekeeper
]
=
None
):
# Počáteční stav soutěže
if
master_round
.
state
!=
db
.
RoundState
.
delegate
:
state
=
master_round
.
state
else
:
state
=
db
.
RoundState
.
preparing
# Soutěž vytvoříme vždy v hlavním kole
contest
=
db
.
Contest
(
round
=
master_round
,
place
=
place
,
state
=
state
)
if
gatekeeper
is
not
None
:
rr
=
gatekeeper
.
rights_for_contest
(
contest
)
if
not
rr
.
have_right
(
Right
.
add_contest
):
raise
ContestError
(
f
'
Vaše role nedovoluje vytvořit soutěž
{
place
.
name_locative
()
}
'
)
sess
=
db
.
get_session
()
sess
.
add
(
contest
)
sess
.
flush
()
contest
.
master_contest_id
=
contest
.
contest_id
sess
.
add
(
contest
)
sess
.
flush
()
mo
.
util
.
log
(
type
=
db
.
LogType
.
contest
,
what
=
contest
.
contest_id
,
details
=
{
'
action
'
:
'
add
'
,
'
contest
'
:
db
.
row2dict
(
contest
),
'
reason
'
:
reason
},
)
mo
.
util
.
logger
.
info
(
f
"
{
reason
.
title
()
}
: Soutěž #
{
contest
.
contest_id
}
založena:
{
db
.
row2dict
(
contest
)
}
"
)
create_subcontests
(
master_round
,
contest
,
reason
)
def
create_subcontests
(
master_round
:
db
.
Round
,
master_contest
:
db
.
Contest
,
reason
:
str
):
if
master_round
.
part
==
0
:
return
sess
=
db
.
get_session
()
subrounds
=
master_round
.
get_group_rounds
()
for
subround
in
subrounds
:
subcontest
=
db
.
Contest
(
round_id
=
subround
.
round_id
,
master_contest_id
=
master_contest
.
contest_id
,
place_id
=
master_contest
.
place_id
,
state
=
master_contest
.
state
,
)
sess
.
add
(
subcontest
)
sess
.
flush
()
mo
.
util
.
log
(
type
=
db
.
LogType
.
contest
,
what
=
subcontest
.
contest_id
,
details
=
{
'
action
'
:
'
add
'
,
'
contest
'
:
db
.
row2dict
(
subcontest
),
'
reason
'
:
reason
},
)
mo
.
util
.
logger
.
info
(
f
"
{
reason
.
title
()
}
: Podsoutěž #
{
subcontest
.
contest_id
}
založena:
{
db
.
row2dict
(
subcontest
)
}
"
)
This diff is collapsed.
Click to expand it.
mo/web/org_round.py
+
6
−
61
View file @
32d5abf6
...
...
@@ -17,6 +17,7 @@ from wtforms import validators
from
wtforms.widgets
import
NumberInput
import
mo.config
as
config
import
mo.contests
import
mo.db
as
db
import
mo.imports
import
mo.jobs.notify
...
...
@@ -103,7 +104,10 @@ def add_contest(round: db.Round, form: AddContestForm) -> bool:
flash
(
f
'
Pro
{
place
.
type_name
()
}
{
place
.
name
}
už toto kolo existuje
'
,
'
danger
'
)
return
False
if
not
do_add_contest
(
round
.
master
,
place
,
True
):
try
:
mo
.
contests
.
add_contest
(
round
.
master
,
place
,
reason
=
'
web
'
,
gatekeeper
=
g
.
gatekeeper
)
except
mo
.
contests
.
ContestError
as
e
:
flash
(
str
(
e
),
'
danger
'
)
return
False
sess
.
commit
()
...
...
@@ -111,64 +115,6 @@ def add_contest(round: db.Round, form: AddContestForm) -> bool:
return
True
def
do_add_contest
(
master_round
:
db
.
Round
,
place
:
db
.
Place
,
check_rights
:
bool
)
->
bool
:
# Počáteční stav soutěže
if
master_round
.
state
!=
db
.
RoundState
.
delegate
:
state
=
master_round
.
state
else
:
state
=
db
.
RoundState
.
preparing
# Soutěž vytvoříme vždy v hlavním kole
contest
=
db
.
Contest
(
round
=
master_round
,
place
=
place
,
state
=
state
)
if
check_rights
:
rr
=
g
.
gatekeeper
.
rights_for_contest
(
contest
)
if
not
rr
.
have_right
(
Right
.
add_contest
):
flash
(
f
'
Vaše role nedovoluje vytvořit soutěž
{
place
.
name_locative
()
}
'
,
'
danger
'
)
return
False
sess
=
db
.
get_session
()
sess
.
add
(
contest
)
sess
.
flush
()
contest
.
master_contest_id
=
contest
.
contest_id
sess
.
add
(
contest
)
sess
.
flush
()
mo
.
util
.
log
(
type
=
db
.
LogType
.
contest
,
what
=
contest
.
contest_id
,
details
=
{
'
action
'
:
'
add
'
,
'
contest
'
:
db
.
row2dict
(
contest
)},
)
app
.
logger
.
info
(
f
"
Soutěž #
{
contest
.
contest_id
}
založena:
{
db
.
row2dict
(
contest
)
}
"
)
create_subcontests
(
master_round
,
contest
)
return
True
# XXX: Používá se i v registraci účastníků
def
create_subcontests
(
master_round
:
db
.
Round
,
master_contest
:
db
.
Contest
):
if
master_round
.
part
==
0
:
return
sess
=
db
.
get_session
()
subrounds
=
master_round
.
get_group_rounds
()
for
subround
in
subrounds
:
subcontest
=
db
.
Contest
(
round_id
=
subround
.
round_id
,
master_contest_id
=
master_contest
.
contest_id
,
place_id
=
master_contest
.
place_id
,
state
=
master_contest
.
state
,
)
sess
.
add
(
subcontest
)
sess
.
flush
()
mo
.
util
.
log
(
type
=
db
.
LogType
.
contest
,
what
=
subcontest
.
contest_id
,
details
=
{
'
action
'
:
'
add
'
,
'
contest
'
:
db
.
row2dict
(
subcontest
)},
)
app
.
logger
.
info
(
f
"
Podsoutěž #
{
subcontest
.
contest_id
}
založena:
{
db
.
row2dict
(
subcontest
)
}
"
)
@dataclass
class
ContestStat
:
region
:
db
.
Place
...
...
@@ -696,8 +642,7 @@ def org_round_create_contests(round_id: int):
form
=
CreateContestsForm
()
if
form
.
validate_on_submit
():
for
place
in
new_places
:
ok
=
do_add_contest
(
round
,
place
,
False
)
assert
ok
mo
.
contests
.
add_contest
(
round
,
place
,
reason
=
'
web
'
)
sess
.
commit
()
flash
(
inflect_with_number
(
len
(
new_places
),
'
Založena %s soutěž.
'
,
'
Založeny %s soutěže.
'
,
'
Založeno %s soutěží.
'
),
'
success
'
)
return
redirect
(
ctx
.
url_for
(
'
org_round
'
))
...
...
This diff is collapsed.
Click to expand it.
mo/web/user.py
+
2
−
1
View file @
32d5abf6
...
...
@@ -12,6 +12,7 @@ import werkzeug.exceptions
import
wtforms
from
wtforms.validators
import
DataRequired
import
mo.contests
import
mo.config
as
config
import
mo.email
import
mo.db
as
db
...
...
@@ -208,7 +209,7 @@ def join_create_contest(round: db.Round, pant: db.Participant) -> db.Contest:
details
=
{
'
action
'
:
'
created
'
,
'
reason
'
:
'
user-join
'
},
)
mo
.
web
.
org_round
.
create_subcontests
(
round
,
c
)
mo
.
contests
.
create_subcontests
(
round
,
c
,
reason
=
'
user-join
'
)
return
c
...
...
This diff is collapsed.
Click to expand it.
Martin Mareš
@mj
mentioned in issue
#372 (closed)
·
Jan 27, 2024
mentioned in issue
#372 (closed)
mentioned in issue #372
Toggle commit list
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