Skip to content

Commit

Permalink
Add an "active" flag on contests.
Browse files Browse the repository at this point in the history
  • Loading branch information
vytisb committed Feb 20, 2024
1 parent cd632ab commit 244e4ba
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 2 deletions.
5 changes: 3 additions & 2 deletions cms/db/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
# Copyright © 2010-2012 Matteo Boscariol <[email protected]>
# Copyright © 2013 Bernard Blackham <[email protected]>
# Copyright © 2013-2018 Luca Wehrstedt <[email protected]>
# Copyright © 2014 Vytis Banaitis <[email protected]>
# Copyright © 2016 Myungwoo Chun <[email protected]>
# Copyright © 2016 Masaki Hara <[email protected]>
# Copyright © 2016 Amir Keivan Mohtashami <[email protected]>
Expand Down Expand Up @@ -75,7 +76,7 @@
# util
"test_db_connection", "get_contest_list", "is_contest_id",
"ask_for_contest", "get_submissions", "get_submission_results",
"get_datasets_to_judge", "enumerate_files"
"get_datasets_to_judge", "enumerate_files", "get_active_contest_list",
]


Expand Down Expand Up @@ -110,7 +111,7 @@

from .util import test_db_connection, get_contest_list, is_contest_id, \
ask_for_contest, get_submissions, get_submission_results, \
get_datasets_to_judge, enumerate_files
get_datasets_to_judge, enumerate_files, get_active_contest_list


configure_mappers()
Expand Down
7 changes: 7 additions & 0 deletions cms/db/contest.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
# Copyright © 2010-2012 Matteo Boscariol <[email protected]>
# Copyright © 2012-2018 Luca Wehrstedt <[email protected]>
# Copyright © 2013 Bernard Blackham <[email protected]>
# Copyright © 2014 Vytis Banaitis <[email protected]>
# Copyright © 2016 Myungwoo Chun <[email protected]>
# Copyright © 2016 Amir Keivan Mohtashami <[email protected]>
# Copyright © 2018 William Di Luigi <[email protected]>
Expand Down Expand Up @@ -258,6 +259,12 @@ class Contest(Base):
nullable=False,
default=0)

# Whether this contest should be handled by CMS services.
active = Column(
Boolean,
nullable=False,
default=False)

# These one-to-many relationships are the reversed directions of
# the ones defined in the "child" classes using foreign keys.

Expand Down
20 changes: 20 additions & 0 deletions cms/db/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
# Copyright © 2010-2012 Stefano Maggiolo <[email protected]>
# Copyright © 2010-2012 Matteo Boscariol <[email protected]>
# Copyright © 2013-2018 Luca Wehrstedt <[email protected]>
# Copyright © 2014 Vytis Banaitis <[email protected]>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
Expand Down Expand Up @@ -76,6 +77,25 @@ def get_contest_list(session=None):
return session.query(Contest).all()


def get_active_contest_list(session=None):
"""Return all active contest objects available on the database.
session (Session): if specified, use such session for connecting
to the database; otherwise, create a temporary one and discard
it after the operation (this means that no further expansion
of lazy properties of the returned Contest objects will be
possible).
return ([Contest]): the list of active contests in the DB.
"""
if session is None:
with SessionGen() as session:
return get_active_contest_list(session)

return session.query(Contest).filter_by(active=True).all()


def is_contest_id(contest_id):
"""Return if there is a contest with the given id in the database.
Expand Down
3 changes: 3 additions & 0 deletions cms/server/admin/handlers/contest.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
# Copyright © 2012-2015 Luca Wehrstedt <[email protected]>
# Copyright © 2014 Artem Iglikov <[email protected]>
# Copyright © 2014 Fabian Gundlach <[email protected]>
# Copyright © 2014 Vytis Banaitis <[email protected]>
# Copyright © 2016 Myungwoo Chun <[email protected]>
# Copyright © 2016 Amir Keivan Mohtashami <[email protected]>
# Copyright © 2018 William Di Luigi <[email protected]>
Expand Down Expand Up @@ -127,6 +128,8 @@ def post(self, contest_id):
self.get_datetime(attrs, "analysis_start")
self.get_datetime(attrs, "analysis_stop")

self.get_bool(attrs, "active")

# Update the contest.
contest.set_attrs(attrs)

Expand Down
7 changes: 7 additions & 0 deletions cms/server/admin/templates/contest.html
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,13 @@ <h1>Contest configuration</h1>
</td>
<td><input type="text" name="score_precision" value="{{ contest.score_precision }}"></td>
</tr>
<tr>
<td>
<span class="info" title="Whether this contest should be handled by CMS services."></span>
Active
</td>
<td><input type="checkbox" name="active" {{ "checked" if contest.active else "" }}></td>
</tr>

<tr><td colspan=2><h2>Logging in</h2></td></tr>
<tr>
Expand Down
3 changes: 3 additions & 0 deletions cmscontrib/importing.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
# Copyright © 2010-2013 Giovanni Mascellani <[email protected]>
# Copyright © 2010-2018 Stefano Maggiolo <[email protected]>
# Copyright © 2010-2012 Matteo Boscariol <[email protected]>
# Copyright © 2014 Vytis Banaitis <[email protected]>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
Expand Down Expand Up @@ -304,4 +305,6 @@ def update_contest(old_contest, new_contest, parent=None):
# must be handled differently.
Contest.tasks: False,
Contest.participations: False,
# Active flag is not managed by the loader.
Contest.active: False,
}, parent=parent)

0 comments on commit 244e4ba

Please sign in to comment.