1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 """Micro reports objects.
19
20 A micro report is a tree of layout and content objects.
21 """
22 __docformat__ = "restructuredtext en"
23
24 from logilab.common.tree import VNode
25
26 from six import string_types
27
29 """base report component
30
31 attributes
32 * id : the component's optional id
33 * klass : the component's optional klass
34 """
35 - def __init__(self, id=None, klass=None):
38
40 """base container node
41
42 attributes
43 * BaseComponent attributes
44 * children : components in this table (i.e. the table's cells)
45 """
46 - def __init__(self, children=(), **kwargs):
53
55 """overridden to detect problems easily"""
56 assert child not in self.parents()
57 VNode.append(self, child)
58
60 """return the ancestor nodes"""
61 assert self.parent is not self
62 if self.parent is None:
63 return []
64 return [self.parent] + self.parent.parents()
65
66 - def add_text(self, text):
67 """shortcut to add text data"""
68 self.children.append(Text(text))
69
70
71
72
73 -class Text(BaseComponent):
74 """a text portion
75
76 attributes :
77 * BaseComponent attributes
78 * data : the text value as an encoded or unicode string
79 """
80 - def __init__(self, data, escaped=True, **kwargs):
81 super(Text, self).__init__(**kwargs)
82
83
84 assert isinstance(data, string_types), data.__class__
85 self.escaped = escaped
86 self.data = data
87
88 -class VerbatimText(Text):
89 """a verbatim text, display the raw data
90
91 attributes :
92 * BaseComponent attributes
93 * data : the text value as an encoded or unicode string
94 """
95
96 -class Link(BaseComponent):
97 """a labelled link
98
99 attributes :
100 * BaseComponent attributes
101 * url : the link's target (REQUIRED)
102 * label : the link's label as a string (use the url by default)
103 """
104 - def __init__(self, url, label=None, **kwargs):
105 super(Link, self).__init__(**kwargs)
106 assert url
107 self.url = url
108 self.label = label or url
109
110
111 -class Image(BaseComponent):
112 """an embedded or a single image
113
114 attributes :
115 * BaseComponent attributes
116 * filename : the image's filename (REQUIRED)
117 * stream : the stream object containing the image data (REQUIRED)
118 * title : the image's optional title
119 """
120 - def __init__(self, filename, stream, title=None, **kwargs):
121 super(Image, self).__init__(**kwargs)
122 assert filename
123 assert stream
124 self.filename = filename
125 self.stream = stream
126 self.title = title
127
128
129
130
132 """a section
133
134 attributes :
135 * BaseLayout attributes
136
137 a title may also be given to the constructor, it'll be added
138 as a first element
139 a description may also be given to the constructor, it'll be added
140 as a first paragraph
141 """
142 - def __init__(self, title=None, description=None, **kwargs):
148
150 """a title
151
152 attributes :
153 * BaseLayout attributes
154
155 A title must not contains a section nor a paragraph!
156 """
157
158 -class Span(BaseLayout):
159 """a title
160
161 attributes :
162 * BaseLayout attributes
163
164 A span should only contains Text and Link nodes (in-line elements)
165 """
166
168 """a simple text paragraph
169
170 attributes :
171 * BaseLayout attributes
172
173 A paragraph must not contains a section !
174 """
175
177 """some tabular data
178
179 attributes :
180 * BaseLayout attributes
181 * cols : the number of columns of the table (REQUIRED)
182 * rheaders : the first row's elements are table's header
183 * cheaders : the first col's elements are table's header
184 * title : the table's optional title
185 """
186 - def __init__(self, cols, title=None,
187 rheaders=0, cheaders=0, rrheaders=0, rcheaders=0,
188 **kwargs):
189 super(Table, self).__init__(**kwargs)
190 assert isinstance(cols, int)
191 self.cols = cols
192 self.title = title
193 self.rheaders = rheaders
194 self.cheaders = cheaders
195 self.rrheaders = rrheaders
196 self.rcheaders = rcheaders
197
198 -class List(BaseLayout):
199 """some list data
200
201 attributes :
202 * BaseLayout attributes
203 """
204