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
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Martin Mareš
Odevzdávací Systém MO
Commits
4528ed25
Commit
4528ed25
authored
4 years ago
by
Martin Mareš
Browse files
Options
Downloads
Patches
Plain Diff
Automatické přihlašování účastníků do testovací soutěže
parent
d8419df1
No related branches found
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
etc/config.py.example
+4
-0
4 additions, 0 deletions
etc/config.py.example
mo/web/user.py
+48
-11
48 additions, 11 deletions
mo/web/user.py
with
52 additions
and
11 deletions
etc/config.py.example
+
4
−
0
View file @
4528ed25
...
@@ -47,3 +47,7 @@ JOB_GC_PERIOD = 60
...
@@ -47,3 +47,7 @@ JOB_GC_PERIOD = 60
# Za jak dlouho expiruje dokončená dávka [min]
# Za jak dlouho expiruje dokončená dávka [min]
JOB_EXPIRATION = 5
JOB_EXPIRATION = 5
# Automatické přihlašování účastníků do testovací soutěže
# (kolo aktuální_ročník-T-1, celostátní soutěž)
AUTO_REGISTER_TEST = True
This diff is collapsed.
Click to expand it.
mo/web/user.py
+
48
−
11
View file @
4528ed25
...
@@ -3,9 +3,11 @@ from flask_wtf import FlaskForm
...
@@ -3,9 +3,11 @@ from flask_wtf import FlaskForm
import
flask_wtf.file
import
flask_wtf.file
from
sqlalchemy
import
and_
from
sqlalchemy
import
and_
from
sqlalchemy.orm
import
joinedload
from
sqlalchemy.orm
import
joinedload
from
typing
import
List
,
Tuple
import
werkzeug.exceptions
import
werkzeug.exceptions
import
wtforms
import
wtforms
import
mo
import
mo.config
as
config
import
mo.config
as
config
import
mo.db
as
db
import
mo.db
as
db
import
mo.submit
import
mo.submit
...
@@ -18,9 +20,19 @@ import mo.web.util
...
@@ -18,9 +20,19 @@ import mo.web.util
@app.route
(
'
/user
'
)
@app.route
(
'
/user
'
)
def
user_index
():
def
user_index
():
sess
=
db
.
get_session
()
pcrs
=
load_pcrs
()
if
getattr
(
config
,
'
AUTO_REGISTER_TEST
'
,
False
)
and
not
any
(
round
.
category
==
'
T
'
for
pion
,
contest
,
round
in
pcrs
):
if
register_to_test
():
pcrs
=
load_pcrs
()
return
render_template
(
'
user_index.html
'
,
pions
=
pcrs
,
)
pions
=
(
sess
.
query
(
db
.
Participation
,
db
.
Contest
,
db
.
Round
)
def
load_pcrs
()
->
List
[
Tuple
[
db
.
Participation
,
db
.
Contest
,
db
.
Round
]]:
return
(
db
.
get_session
().
query
(
db
.
Participation
,
db
.
Contest
,
db
.
Round
)
.
select_from
(
db
.
Participation
)
.
select_from
(
db
.
Participation
)
.
join
(
db
.
Contest
,
db
.
Contest
.
master_contest_id
==
db
.
Participation
.
contest_id
)
.
join
(
db
.
Contest
,
db
.
Contest
.
master_contest_id
==
db
.
Participation
.
contest_id
)
.
join
(
db
.
Round
)
.
join
(
db
.
Round
)
...
@@ -29,10 +41,35 @@ def user_index():
...
@@ -29,10 +41,35 @@ def user_index():
.
order_by
(
db
.
Round
.
year
.
desc
(),
db
.
Round
.
category
,
db
.
Round
.
seq
,
db
.
Round
.
part
)
.
order_by
(
db
.
Round
.
year
.
desc
(),
db
.
Round
.
category
,
db
.
Round
.
seq
,
db
.
Round
.
part
)
.
all
())
.
all
())
return
render_template
(
'
user_index.html
'
,
def
register_to_test
()
->
bool
:
pions
=
pions
,
sess
=
db
.
get_session
()
round
=
sess
.
query
(
db
.
Round
).
filter_by
(
year
=
mo
.
current_year
,
category
=
'
T
'
,
seq
=
1
,
part
=
0
).
one_or_none
()
if
not
round
:
app
.
logger
.
error
(
f
'
Nemohu najít kolo
{
mo
.
current_year
}
-T-1
'
)
return
False
if
round
.
level
!=
0
:
app
.
logger
.
error
(
f
'
Kolo
{
round
.
round_code_short
()
}
není na celostátní úrovni
'
)
return
False
contest
=
sess
.
query
(
db
.
Contest
).
filter_by
(
round
=
round
).
limit
(
1
).
one_or_none
()
if
not
contest
:
app
.
logger
.
error
(
f
'
Kolo
{
round
.
round_code_short
()
}
nemá soutěž
'
)
return
False
pion
=
db
.
Participation
(
user
=
g
.
user
,
contest
=
contest
,
place
=
contest
.
place
,
state
=
db
.
PartState
.
registered
)
sess
.
add
(
pion
)
sess
.
flush
()
mo
.
util
.
log
(
type
=
db
.
LogType
.
participant
,
what
=
g
.
user
.
user_id
,
details
=
{
'
action
'
:
'
add-to-contest
'
,
'
new
'
:
db
.
row2dict
(
pion
)},
)
)
sess
.
commit
()
app
.
logger
.
info
(
f
'
Účastník #
{
g
.
user
.
user_id
}
automaticky registrován do soutěže #
{
contest
.
contest_id
}
'
)
return
True
def
get_contest
(
id
:
int
)
->
db
.
Contest
:
def
get_contest
(
id
:
int
)
->
db
.
Contest
:
...
...
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
register
or
sign in
to comment