forked from global-pulse/HunchWorks
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhunchworks_enums.py
188 lines (144 loc) · 3.71 KB
/
hunchworks_enums.py
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
#!/usr/bin/env python
"""Enums used throughout Hunchworks."""
__author__ = ('Leah',)
__license__ = 'GPLv3'
import inspect
class Error(Exception):
pass
class EnumException(Error):
pass
class Enum(object):
"""Class representing an enum in Python."""
##This has been commented out because leaving it as a global variable
## means that it is never reassigned when another class calls GetValues
## so your options are always the same. Map is now individually assigned
## in each class (redundant, but nessecary atm)
#MAP = {}
VALUE_LOOKUP = {}
@classmethod
def GetChoices(cls):
"""Returns a tuple representing the enum.
Returns:
A nested tuple, where each child tuple contains:
(enum_value, user_facing_enum_value,)
"""
enum_values = cls.GetEnumValues().items()
return [(x[1], cls.GetValue(x[0]),) for x in enum_values]
@classmethod
def GetValue(cls, lookup):
"""Returns the user facing representation of an enum value.
Args:
lookup: The enum value to lookup.
Returns:
The user facing representation of the enum value.
Raises:
EnumException: Raised if the supplied value doesn't exist on the enum.
"""
try:
assert(lookup in cls.GetEnumValues().keys())
except AssertionError:
raise EnumException(
'The supplied lookup value does not exist on the Enum')
try:
return cls.VALUE_LOOKUP[lookup]
except KeyError:
return lookup.title()
@classmethod
def GetEnumValues(cls):
"""Get's the Enum values as a dictionary.
Returns:
A dictionary wrapping the Enum values.
"""
if not cls.MAP:
# This is a bit of a hack - if the enum is defined in a module called
# directly from the command line, it also has a __module__ attribute,
# which the dummy object won't have.
standard_attrs = ['__module__'] + dir(type('dummy', (object,), {}))
class_attrs = inspect.getmembers(cls)
for item in class_attrs:
if (item[0] not in standard_attrs and
not inspect.isroutine(item[1]) and
not isinstance(item[1], (list, dict,))):
cls.MAP[item[0]] = item[1]
return cls.MAP
class ConnectionStatus(Enum):
"""Enum representing the possible statuses a user connection can take."""
MAP = {}
BLOCKED = 0
FRIEND = 1
ACCEPTED = 2
class UserTitle(Enum):
"""Enum representing the possible titles users can use."""
MAP = {}
MR = 0
MRS = 1
MS = 2
FIELD_LOOKUP = {
MR: 'Mr.',
MRS: 'Mrs.',
MS: 'Ms.',
}
class PrivacyLevel(Enum):
"""Enum representing the various privacy levels available to users."""
MAP = {}
HIDDEN = 0
CLOSED = 1
OPEN = 2
FIELD_LOOKUP = {
HIDDEN: 'Hidden',
CLOSED: 'Closed',
OPEN: 'Open',
}
class GroupType(Enum):
"""Enum representing the types of groups that can be made"""
MAP = {}
AD_HOC = 0
ALUMNI = 1
COMPLEMENT = 2
CORPORATE = 3
INTEREST = 4
NON_PROFIT = 5
FIELD_LOOKUP = {
AD_HOC: 'Ad-Hoc',
ALUMNI: 'Alumni',
COMPLEMENT: 'Complement',
CORPORATE: 'Corporate',
INTEREST: 'Interest',
NON_PROFIT: 'Non-Profit',
}
class GroupPrivilege(Enum):
ADMIN = 0
MEMBER = 1
class LanguageOptions(Enum):
MAP = {}
ENGLISH = 0
SPANISH = 1
GERMAN = 2
FRENCH = 3
MANDARIN = 4
FIELD_LOOKUP = {
ENGLISH: 'English',
SPANISH: 'Spanish',
FRENCH: 'French',
GERMAN: 'German',
MANDARIN: 'Mandarin',
}
class MessangerServices(Enum):
MAP = {}
AIM = 0
YAHOO = 1
MSN = 2
IRC = 3
MEEBO = 4
FIELD_LOOKUP = {
AIM: 'AIM',
YAHOO: 'YAHOO',
MSN: 'MSN',
IRC: 'IRC',
MEEBO: 'MEEBO',
}
ATTACHMENT_TYPES = (
('Photo', 'Photo'),
('Link', 'Link'),
('Video', 'Video'),
)