diff --git a/cms/db/__init__.py b/cms/db/__init__.py index 85a734da77..791be01841 100644 --- a/cms/db/__init__.py +++ b/cms/db/__init__.py @@ -6,6 +6,7 @@ # Copyright © 2010-2012 Matteo Boscariol # Copyright © 2013 Bernard Blackham # Copyright © 2013-2018 Luca Wehrstedt +# Copyright © 2014 Vytis Banaitis # Copyright © 2016 Myungwoo Chun # Copyright © 2016 Masaki Hara # Copyright © 2016 Amir Keivan Mohtashami @@ -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", ] @@ -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() diff --git a/cms/db/contest.py b/cms/db/contest.py index 7543c58d68..da11c0d877 100644 --- a/cms/db/contest.py +++ b/cms/db/contest.py @@ -6,6 +6,7 @@ # Copyright © 2010-2012 Matteo Boscariol # Copyright © 2012-2018 Luca Wehrstedt # Copyright © 2013 Bernard Blackham +# Copyright © 2014 Vytis Banaitis # Copyright © 2016 Myungwoo Chun # Copyright © 2016 Amir Keivan Mohtashami # Copyright © 2018 William Di Luigi @@ -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. diff --git a/cms/db/util.py b/cms/db/util.py index 28fd97ae69..b5897c8480 100644 --- a/cms/db/util.py +++ b/cms/db/util.py @@ -5,6 +5,7 @@ # Copyright © 2010-2012 Stefano Maggiolo # Copyright © 2010-2012 Matteo Boscariol # Copyright © 2013-2018 Luca Wehrstedt +# Copyright © 2014 Vytis Banaitis # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU Affero General Public License as @@ -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. diff --git a/cms/server/admin/handlers/contest.py b/cms/server/admin/handlers/contest.py index 132b6d9ea7..3806e68df6 100644 --- a/cms/server/admin/handlers/contest.py +++ b/cms/server/admin/handlers/contest.py @@ -7,6 +7,7 @@ # Copyright © 2012-2015 Luca Wehrstedt # Copyright © 2014 Artem Iglikov # Copyright © 2014 Fabian Gundlach <320pointsguy@gmail.com> +# Copyright © 2014 Vytis Banaitis # Copyright © 2016 Myungwoo Chun # Copyright © 2016 Amir Keivan Mohtashami # Copyright © 2018 William Di Luigi @@ -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) diff --git a/cms/server/admin/templates/contest.html b/cms/server/admin/templates/contest.html index b667213397..6b78f43f0a 100644 --- a/cms/server/admin/templates/contest.html +++ b/cms/server/admin/templates/contest.html @@ -81,6 +81,13 @@

Contest configuration

+ + + + Active + + +

Logging in

diff --git a/cmscontrib/importing.py b/cmscontrib/importing.py index 1254880967..340206a35c 100644 --- a/cmscontrib/importing.py +++ b/cmscontrib/importing.py @@ -4,6 +4,7 @@ # Copyright © 2010-2013 Giovanni Mascellani # Copyright © 2010-2018 Stefano Maggiolo # Copyright © 2010-2012 Matteo Boscariol +# Copyright © 2014 Vytis Banaitis # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU Affero General Public License as @@ -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)