Skip to content

Commit 6848f57

Browse files
committed
Add delay_time
1 parent 4b1cb4c commit 6848f57

8 files changed

Lines changed: 72 additions & 4 deletions

File tree

cms/db/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@
7676

7777
# Instantiate or import these objects.
7878

79-
version = 11
79+
version = 12
8080

8181

8282
engine = create_engine(config.database, echo=config.database_debug,

cms/db/contest.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,7 @@ class Contest(Base):
157157
# Max contest time for each user in seconds.
158158
per_user_time = Column(
159159
Interval,
160+
CheckConstraint("per_user_time >= '0 seconds'"),
160161
nullable=True)
161162

162163
# Maximum number of submissions or user_tests allowed for each user

cms/db/user.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
# Copyright © 2010-2012 Giovanni Mascellani <mascellani@poisson.phc.unipi.it>
66
# Copyright © 2010-2012 Stefano Maggiolo <s.maggiolo@gmail.com>
77
# Copyright © 2010-2012 Matteo Boscariol <boscarim@hotmail.com>
8-
# Copyright © 2012 Luca Wehrstedt <luca.wehrstedt@gmail.com>
8+
# Copyright © 2012-2014 Luca Wehrstedt <luca.wehrstedt@gmail.com>
99
#
1010
# This program is free software: you can redistribute it and/or modify
1111
# it under the terms of the GNU Affero General Public License as
@@ -30,7 +30,8 @@
3030

3131
from datetime import timedelta
3232

33-
from sqlalchemy.schema import Column, ForeignKey, UniqueConstraint
33+
from sqlalchemy.schema import Column, ForeignKey, CheckConstraint, \
34+
UniqueConstraint
3435
from sqlalchemy.types import Boolean, Integer, String, Unicode, DateTime, \
3536
Interval
3637
from sqlalchemy.orm import relationship, backref
@@ -131,9 +132,18 @@ class User(Base):
131132
DateTime,
132133
nullable=True)
133134

135+
# A shift in the time interval during which the user is allowed to
136+
# submit.
137+
delay_time = Column(
138+
Interval,
139+
CheckConstraint("delay_time >= '0 seconds'"),
140+
nullable=False,
141+
default=timedelta())
142+
134143
# An extra amount of time allocated for this user.
135144
extra_time = Column(
136145
Interval,
146+
CheckConstraint("extra_time >= '0 seconds'"),
137147
nullable=False,
138148
default=timedelta())
139149

cms/server/AdminWebServer.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1763,6 +1763,7 @@ def post(self, user_id):
17631763

17641764
self.get_string(attrs, "timezone", empty=None)
17651765
self.get_datetime(attrs, "starting_time")
1766+
self.get_timedelta_sec(attrs, "delay_time")
17661767
self.get_timedelta_sec(attrs, "extra_time")
17671768

17681769
self.get_bool(attrs, "hidden")
@@ -1803,6 +1804,7 @@ def post(self, contest_id):
18031804

18041805
self.get_string(attrs, "timezone", empty=None)
18051806
self.get_datetime(attrs, "starting_time")
1807+
self.get_timedelta_sec(attrs, "delay_time")
18061808
self.get_timedelta_sec(attrs, "extra_time")
18071809

18081810
self.get_bool(attrs, "hidden")

cms/server/ContestWebServer.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,7 @@ def render_params(self):
304304
res = compute_actual_phase(
305305
self.timestamp, self.contest.start, self.contest.stop,
306306
self.contest.per_user_time, self.current_user.starting_time,
307-
timedelta(), self.current_user.extra_time)
307+
self.current_user.delay_time, self.current_user.extra_time)
308308

309309
ret["actual_phase"], ret["current_phase_begin"], \
310310
ret["current_phase_end"], ret["valid_phase_begin"], \

cms/server/templates/admin/add_user.html

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,10 @@ <h2 id="title_general_info" class="toggling_on">General information</h2>
4242
<td>First login time during contest</td>
4343
<td><input type="text" name="starting_time" value=""></td>
4444
</tr>
45+
<tr>
46+
<td>Delay time (in seconds)</td>
47+
<td><input type="text" name="delay_time" value="0"></td>
48+
</tr>
4549
<tr>
4650
<td>Extra time (in seconds)</td>
4751
<td><input type="text" name="extra_time" value="0"></td>

cms/server/templates/admin/user.html

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,10 @@ <h2 id="title_general_info" class="toggling_on">General Information</h2>
192192
<td>First login time during contest (in UTC)</td>
193193
<td><input type="text" name="starting_time" value="{{ str(selected_user.starting_time) if selected_user.starting_time is not None else "" }}"></td>
194194
</tr>
195+
<tr>
196+
<td>Delay (in seconds)</td>
197+
<td><input type="text" name="delay_time" value="{{ int(selected_user.delay_time.total_seconds()) }}"></td>
198+
</tr>
195199
<tr>
196200
<td>Extra time (in seconds)</td>
197201
<td><input type="text" name="extra_time" value="{{ int(selected_user.extra_time.total_seconds()) }}"></td>

cmscontrib/updaters/update_12.py

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
#!/usr/bin/env python2
2+
# -*- coding: utf-8 -*-
3+
4+
# Contest Management System - http://cms-dev.github.io/
5+
# Copyright © 2014 Luca Wehrstedt <luca.wehrstedt@gmail.com>
6+
#
7+
# This program is free software: you can redistribute it and/or modify
8+
# it under the terms of the GNU Affero General Public License as
9+
# published by the Free Software Foundation, either version 3 of the
10+
# License, or (at your option) any later version.
11+
#
12+
# This program is distributed in the hope that it will be useful,
13+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15+
# GNU Affero General Public License for more details.
16+
#
17+
# You should have received a copy of the GNU Affero General Public License
18+
# along with this program. If not, see <http://www.gnu.org/licenses/>.
19+
20+
"""A class to update a dump created by CMS.
21+
22+
Used by ContestImporter and DumpUpdater.
23+
24+
This adapts the dump to some changes in the model introduced in the
25+
commit that created this same file.
26+
27+
"""
28+
29+
from __future__ import absolute_import
30+
from __future__ import unicode_literals
31+
from __future__ import print_function
32+
33+
34+
class Updater(object):
35+
36+
def __init__(self, data):
37+
assert data["_version"] == 11
38+
self.objs = data
39+
40+
def run(self):
41+
for k, v in self.objs.iteritems():
42+
if k.startswith("_"):
43+
continue
44+
if v["_class"] == "User":
45+
v["delay_time"] = 0
46+
47+
return self.objs

0 commit comments

Comments
 (0)