1
|
|
#!/usr/bin/env python3
|
2
|
|
|
3
|
|
# Contest Management System - http://cms-dev.github.io/
|
4
|
|
# Copyright © 2011-2013 Luca Wehrstedt <luca.wehrstedt@gmail.com>
|
5
|
|
#
|
6
|
|
# This program is free software: you can redistribute it and/or modify
|
7
|
|
# it under the terms of the GNU Affero General Public License as
|
8
|
|
# published by the Free Software Foundation, either version 3 of the
|
9
|
|
# License, or (at your option) any later version.
|
10
|
|
#
|
11
|
|
# This program is distributed in the hope that it will be useful,
|
12
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
14
|
|
# GNU Affero General Public License for more details.
|
15
|
|
#
|
16
|
|
# You should have received a copy of the GNU Affero General Public License
|
17
|
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
18
|
|
|
19
|
1
|
from cmsranking.Entity import Entity, InvalidData
|
20
|
|
|
21
|
|
|
22
|
1
|
class Team(Entity):
|
23
|
|
"""The entity representing a team.
|
24
|
|
|
25
|
|
It consists of the following properties:
|
26
|
|
- name (unicode): the human-readable name of the team
|
27
|
|
|
28
|
|
"""
|
29
|
1
|
def __init__(self):
|
30
|
|
"""Set the properties to some default values.
|
31
|
|
|
32
|
|
"""
|
33
|
0
|
Entity.__init__(self)
|
34
|
0
|
self.name = None
|
35
|
|
|
36
|
1
|
@staticmethod
|
37
|
|
def validate(data):
|
38
|
|
"""Validate the given dictionary.
|
39
|
|
|
40
|
|
See if it contains a valid representation of this entity.
|
41
|
|
|
42
|
|
"""
|
43
|
0
|
try:
|
44
|
0
|
assert isinstance(data, dict), \
|
45
|
|
"Not a dictionary"
|
46
|
0
|
assert isinstance(data['name'], str), \
|
47
|
|
"Field 'name' isn't a string"
|
48
|
0
|
except KeyError as exc:
|
49
|
0
|
raise InvalidData("Field %s is missing" % exc)
|
50
|
0
|
except AssertionError as exc:
|
51
|
0
|
raise InvalidData(str(exc))
|
52
|
|
|
53
|
1
|
def set(self, data):
|
54
|
0
|
self.validate(data)
|
55
|
0
|
self.name = data['name']
|
56
|
|
|
57
|
1
|
def get(self):
|
58
|
0
|
result = self.__dict__.copy()
|
59
|
0
|
del result['key']
|
60
|
0
|
return result
|