|
| 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