1
2
3
4
5
6
7
8
9
10
11
12
13
14 from zephir.utils import trml2pdf
15 from zephir.config import charset
16
18 """Conversion des informations en TRML
19 """
20
22 """Conversion du rml en pdf
23 """
24 return trml2pdf.parseString(rml_string)
25
26 - def page(self, title="", story=""):
27 """Modèle de génération d'une page
28 """
29 return """<?xml version="1.0" encoding="%s" ?>
30 <!DOCTYPE document SYSTEM "rml_1_0.dtd">
31 <document filename="">
32 <template pageSize="(21cm, 29.7cm)"
33 leftMargin="1.5cm"
34 rightMargin="1.5cm"
35 topMargin="1.5cm"
36 bottomMargin="1.5cm"
37 showBoundary="1"
38 allowSplitting="20"
39 >
40 <pageTemplate id="main">
41 <frame id="first" x1="1.5cm" y1="1.5cm" width="19cm" height="25.5cm"/>
42 </pageTemplate>
43 </template>
44
45 <stylesheet>
46
47 <blockTableStyle id="myBlockTableStyle">
48 <blockFont name="Helvetica-BoldOblique" size="10" start="0,0" stop="1,0"/>
49 <blockFont name="Courier-Bold" size="10" start="0,1" stop="-1,-1"/>
50 <lineStyle kind="GRID" colorName="silver"/>
51 </blockTableStyle>
52
53 <paraStyle name="bullet" fontName="Helvetica" fontSize="10" leftIndent="10mm" firstLineIndent="-10mm"/>
54
55 </stylesheet>
56 <story>
57 <title>%s</title>
58 <spacer length="1cm"/>
59 %s
60 </story>
61 </document>
62 """ % (charset,title, story)
63
64
65 - def sect(self, title, content):
66 """Formatage
67 d'une section
68 """
69 return """<h2>%s</h2> <spacer length="15"/> %s """ % (title, content)
70
71 - def page_break(self):
72 """Saut de page
73 """
74 return """<condPageBreak height="200cm"/>"""
75
77 """Formatage
78 d'un paragraphe
79 """
80 return "<para>%s</para>" % str(s)
81
84
87
90
91
92
93
95 """Transforme une liste de dictionnaires python
96 en un tableau TRML
97 """
99 self.list_dict = list_dict
100
102 """Mapping
103 dictionnaire python -> table TRML
104
105 exemple
106 -------
107
108 {'libelle': 'horus', 'id': 13}
109
110 devient :
111
112 <tr><td>horus</td><td>13</td></tr>
113 """
114 l = []
115 l.append("<tr>")
116 for s in d.values():
117 l.append( "<td>%s</td>" % str(s) )
118 l.append("</tr>")
119 return "".join(l)
120
122 """Mapping dictionnaire python -> table head
123 """
124 l = []
125 l.append("<tr>")
126 for s in d.keys():
127 l.append( "<td>%s</td>" % s )
128 l.append("</tr>")
129 return "".join(l)
130
132 """Mapping liste de dictionnaires python -> rml table
133 """
134 l = ["""<blockTable style="myBlockTableStyle">"""]
135
136 l.append(self._dict_to_table_head(list_dict[0]))
137
138 for d in list_dict:
139 l.append(self._dict_to_table_row(d))
140 l.append("""</blockTable><spacer length="15"/>""")
141 return "".join(l)
142
145
147 """Transforme un dictionnaire python en liste rml
148 """
151
153 """Mapping
154 dictionnaire python -> liste RML
155 """
156 l=[]
157 for em,item in dict.items():
158 l.append("""<para style="bullet">- <i> %s </i> : %s </para>""" % (em, item) )
159 return "".join(l)
160
162 return self._dict_to_list(self.dict)
163
165 """Transforme une liste python en une liste RML
166 """
167
170
172 """Mapping
173 liste python -> liste RML
174 """
175 l = []
176
177 for item in list :
178 l.append("""<para style="bullet"> - %s </para>""" % item )
179
180 return "".join(l)
181
184