blob: 1241340ed637a2b497e99190b3617cbb4a121049 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
|
#!/usr/bin/python
#
# Copyright (C) 2013 Simo Sorce <simo@redhat.com>
#
# see file 'COPYING' for use and warranty information
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
from util import data
class Site(object):
def __init__(self, value):
# implement lookup of sites id for link/name
self.link = value
self.name = value
class User(object):
def __init__(self, username):
if username is None:
self.name = None
self._userdata = dict()
else:
self._userdata = self._get_user_data(username)
self.name = username
def _get_user_data(self, username):
store = data.Store()
return store._get_user_preferences(username)
@property
def is_admin(self):
if 'is_admin' in self._userdata:
if self._userdata['is_admin'] == '1':
return True
return False
@is_admin.setter
def is_admin(self, value):
if value is True:
self._userdata['is_admin'] = '1'
else:
self._userdata['is_admin'] = '0'
@property
def fullname(self):
if 'fullname' in self._userdata:
return self._userdata['fullname']
else:
return self.name
@fullname.setter
def fullname(self, value):
self._userdata['fullname'] = value
@property
def sites(self):
if 'sites' in self._userdata:
d = []
for site in self._userdata['sites']:
d.append(Site(site))
else:
return []
@sites.setter
def sites(self):
#TODO: implement setting sites via the user object ?
raise AttributeError
|