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
|
# -*- coding: utf-8 -*-
# date: 23 Mai 2009
class Priority:
def __init__(self, name, id, color=None):
self.name = name.__str__()
self.id = id
if color is not None:
self.color = color
else:
self.color = id
def getId(self):
return self.id
def getName(self):
return self.name
def getColor(self):
return self.color
def __str__(self):
return self.getName()
class Priorities:
__shared_state = {}
priorities = {}
prioritiesMap = {}
def __init__(self):
self.__dict__ = self.__shared_state
if len(self.priorities) == 0:
self.__add__(Priority('Low', -100))
self.__add__(Priority('Normal', 0))
self.__add__(Priority('High', 100))
def __getitem__(self, id):
return self.priorities[id]
def __setitem__(self, id, priority):
self.priorities[id] = priority
self.prioritiesMap[priority.getName()] = priority
def __delitem__(self, id):
priority = prioritie[key]
del(self.priorities[key])
del(self.prioritiesMap[priority.getName()])
def remove(self, priority):
del(self.priorities[key])
del(self.prioritiesMap[priority.getName()])
def __contians__(self, priority):
return (priority in self.priorities)
def append(self, priority):
self.__setitem__(priority.getId(), priority)
def __add__(self, priority):
self.__setitem__(priority.getId(), priority)
return self
def __iter__(self):
return self.priorities.__iter__()
def getPriority(self, id=None, name=None):
try:
if id is not None:
return self[id]
if name is not None:
return self.prioritiesMap[name]
except(KeyError):
if name is None:
name = id
if id is None:
id = name
priority = Priority(id, name)
self.__add__(priority)
return priority
return None
|