Skip to content

Commit 5e48afe

Browse files
Add updater for admin in questions, announcements, messages
1 parent 964431c commit 5e48afe

2 files changed

Lines changed: 54 additions & 1 deletion

File tree

cms/db/__init__.py

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

8989
# Instantiate or import these objects.
9090

91-
version = 38
91+
version = 39
9292

9393
engine = create_engine(config.database, echo=config.database_debug,
9494
pool_timeout=60, pool_recycle=120)

cmscontrib/updaters/update_39.py

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
#!/usr/bin/env python
2+
# -*- coding: utf-8 -*-
3+
4+
# Contest Management System - http://cms-dev.github.io/
5+
# Copyright © 2018 Stefano Maggiolo <s.maggiolo@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 DumpImporter and DumpUpdater.
23+
24+
Add default values (null) to the new admin field in questions, messages and
25+
announcements.
26+
27+
"""
28+
29+
from __future__ import absolute_import
30+
from __future__ import division
31+
from __future__ import print_function
32+
from __future__ import unicode_literals
33+
from future.builtins.disabled import * # noqa
34+
from future.builtins import * # noqa
35+
from six import iteritems
36+
37+
38+
class Updater(object):
39+
40+
def __init__(self, data):
41+
assert data["_version"] == 38
42+
self.objs = data
43+
44+
def run(self):
45+
for k, v in iteritems(self.objs):
46+
if k.startswith("_"):
47+
continue
48+
if v["_class"] == "Question" \
49+
or v["_class"] == "Message" \
50+
or v["_class"] == "Announcement":
51+
v["admin"] = None
52+
53+
return self.objs

0 commit comments

Comments
 (0)