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 """Container classes are classes that are used to transport data between the
29 model thread and the GUI thread.
30
31 When complex data sets need to be visualized (eg.: charts, intervals), built-in
32 python types don't contain enough information, while dictionary like structures
33 are not self documented. Hence the need of specialized container classes to
34 transport this data between the model and the GUI.
35
36 To use this classes :
37
38 1. On your model class, define properties returning a container class
39 2. In the admin class, add the property to the list of fields to visualize, and
40 specify its delegate
41
42 eg:
43
44 class MyEntity(Entity):
45
46 @property
47 def my_interval(self):
48 return IntervalsContainer()
49
50 class Admin(EntityAdmin):
51 form_display = ['my_interval']
52 field_attributes = dict(my_interval=dict(delegate=IntervalsDelegate))
53
54 """
55
57 """Top level class for all container classes"""
58 pass
59
61 """Helper class for IntervalsContainer, specifications for one interval"""
62
63 - def __init__(self, begin, end, name, color):
68
70 return u'[%s,%s]'%(self.begin, self.end)
71
73 """Containter to hold interval data
74
75 eg : representing the time frame of 8pm till 6am that someone was at work using an hourly
76 precision :
77
78 intervals = IntervalsContainer(0, 24, [Interval(8, 18, 'work')])
79 """
80
81 - def __init__(self, min, max, intervals):
82 """
83 @param min: minimum value that the begin value of an interval is allowed to have
84 @param max: maximum ...
85 @param intervals: list of Interval classes
86 """
87 self.min = min
88 self.max = max
89 self.intervals = intervals
90
92 return u', '.join(unicode(i) for i in self.intervals)
93