-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathSectionItems.py
More file actions
167 lines (135 loc) · 5 KB
/
SectionItems.py
File metadata and controls
167 lines (135 loc) · 5 KB
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
# -*- coding: utf-8 -*-
""" Items Section of the Document
Contains:
* Header Tags
* Item Rows
"""
from .helpers import escape_tex
from .TemplateElement import TemplateElement
GUIA_DESPACHO_TYPES = {
1: "OPERACIÓN CONSTITUYE VENTA",
2: "VENTA POR EFECTUAR",
3: "CONSIGNACION",
4: "ENTREGA GRATUITA",
5: "TRASLADO INTERNO",
6: "OTRO TRASLADOS NO VENTA",
7: "GUÍA DE DEVOLUCIÓN",
8: "TRASLADO PARA EXPORTACIÓN. (NO VENTA)",
9: "VENTA PARA EXPORTACIÓN"
}
class SectionItems(TemplateElement):
"""
%%%% -----------------------------------------------------------------
%%%% SECTION - Items
%%%% -----------------------------------------------------------------
{
%%%% ITEM TABLE
\\begin{longtabu}{%s}
%%%% HEADER
\\rowfont{\\%s}
\\everyrow{\\rowfont{\\%s}}
%s
\\firsthline[1mm]
%%%% CONTENT
%s
\\end{longtabu}
%s
}
"""
def __init__(self, column_layout, table_margins=False, draft=False, provider=False):
""" Before using this Object you need to determine how the Columns are named, aligned and
if they are expanding or not.
You do that by providing the `column_layout` argument in the following Format:
(
{'name': 'Colname1', 'align': 'left'|'right'|'center', expand: True|False},
{'name': 'Colname2', 'align': 'left'|'right'|'center', expand: True|False},
{'name': 'Colname3', 'align': 'left'|'right'|'center', expand: True|False},
...
)
For proper LaTeX results it is recomended to make all but one Column non-expanding. This
way the expanding one will take up as much space as possible without making spacing look
ugly, but also ensuring everything looks not so overy spread (specially the numeric
columns)
"""
self._colsettings = column_layout
self._items = []
self._table_margins = table_margins
self._draft = draft
self._provider = provider
self.__doc__ = self.__doc__ % (
self._build_tablecols(),
'%s', '%s', '%s', '%s', '%s'
)
def append_row(self, row):
""" Expecting the column tuple to be in the expected order the column layout was set up at
init time.
"""
if len(row) != len(self._colsettings):
raise ValueError(
"Rows have to provide one value per set up Column:\n"
">{0}<\n"
">{1}<".format(
', '.join([col for col in row]),
', '.join([col['name'] for col in self._colsettings])
)
)
else:
self._items.append(row)
@property
def carta(self):
return self.__doc__ % (
'small', 'footnotesize',
self._build_headers(),
self._build_rows(),
self._build_disclaimer()
)
@property
def oficio(self):
return self.__doc__ % (
'small', 'footnotesize',
self._build_headers(),
self._build_rows(),
self._build_disclaimer()
)
@property
def thermal80mm(self):
return self.__doc__ % (
'scriptsize', 'scriptsize',
self._build_headers(),
self._build_rows(),
self._build_disclaimer()
)
def _build_tablecols(self):
cols = []
cols.append('' if self._table_margins else '@{}')
for coldef in self._colsettings:
setstr = 'X['
setstr += {True: '', False: '-1'}[coldef['expand']]
setstr += {'left': 'l', 'center': 'c', 'right': 'r'}[coldef['align']]
setstr += ']'
cols.append(setstr)
cols.append('' if self._table_margins else '@{}')
return ' '.join(cols)
def _build_headers(self):
cols = ['\\textbf{%s}' % escape_tex(col['name']) for col in self._colsettings]
tex = (' & \n' + ' ' * 4 * 3).join(cols)
tex += ' \\\\\n'
return tex
def _build_rows(self):
rows = []
for row in self._items:
stringed = (str(col) for col in row)
escaped = (escape_tex(colstr) for colstr in stringed)
rows.append(' & '.join(escaped) + ' \\\\')
return '\n'.join(rows)
def _build_disclaimer(self):
assert self.__document__, "Have not been yet registered onto a Document"
disclaimers = []
doc_gd_type = self.__document__.doc_gd_type
if doc_gd_type:
disclaimers.append('\\centerline{\\textbf{\\large --- %s ---}}' % GUIA_DESPACHO_TYPES[doc_gd_type])
if self._draft:
disclaimers.append('\\centerline{\\textbf{\\large --- %s ---}}' % "BORRADOR")
if self._provider:
disclaimers.append('\\centerline{\\textbf{\\large --- %s ---}}' % "DOCUMENTO PROVEEDOR")
return "\n".join(disclaimers)