Skip to content

Commit bae44fc

Browse files
committed
add pdf features
1 parent 5c939ed commit bae44fc

File tree

4 files changed

+121
-15
lines changed

4 files changed

+121
-15
lines changed

src/iosanita/contenttypes/browser/export_view.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@ class ExportViewDownload(BrowserView):
5050
5151
"""
5252

53+
with_footer = True
54+
5355
def __init__(self, context, request):
5456
super().__init__(context, request)
5557
self.export_type = "csv"
@@ -184,7 +186,8 @@ def pdf_styles(self):
184186
)
185187

186188
def pdf_title(self):
187-
return None
189+
context = self.context.context
190+
return context.Title()
188191

189192
def pdf_description(self):
190193
return None
@@ -203,3 +206,13 @@ def pdf_cell_format(self, column, value):
203206
if re.match(r"^\d{4}-\d{2}-\d{2}T00:00:00$", value):
204207
return {"type": "str", "value": value.split("T")[0]}
205208
return {"type": "str", "value": str(value)}
209+
210+
def pdf_logob64(self):
211+
"""
212+
TODO
213+
"""
214+
return None
215+
216+
def pdf_last_update(self):
217+
# TODO: valutare localizzazione della data
218+
return datetime.now().strftime("%d/%m/%Y %H:%M")

src/iosanita/contenttypes/browser/searchblock.py

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,11 +86,16 @@ def _query_from_facets(self):
8686
}
8787
)
8888
elif facet["type"] == "daterangeFacet":
89+
daterange = self.request.form[facet["field"]["value"]].split(",")
90+
if not daterange[0]:
91+
daterange[0] = "1970-01-01"
92+
if not daterange[1]:
93+
daterange[1] = "2500-01-01"
8994
query.append(
9095
{
9196
"i": facet["field"]["value"],
9297
"o": "plone.app.querystring.operation.date.between",
93-
"v": self.request.form[facet["field"]["value"]].split(","),
98+
"v": daterange,
9499
}
95100
)
96101
elif facet["type"] == "selectFacet" and not facet["multiple"]:
@@ -110,7 +115,7 @@ def _query_from_facets(self):
110115
}
111116
)
112117
else:
113-
logger.warning("DEBUG: filter %s not implemnted", facet)
118+
logger.warning("DEBUG: filter %s not implemented", facet)
114119
query.append(
115120
{
116121
"i": facet["field"]["value"],
@@ -200,3 +205,26 @@ def get_columns(self, data):
200205
return [{"key": "title", "title": _("Titolo")}] + [
201206
{"key": c["field"], "title": c["title"]} for c in columns
202207
]
208+
209+
# TODO: valutare eventuale titolo impostato sul blocco
210+
# def pdf_title(self):
211+
212+
def pdf_description(self):
213+
query = []
214+
searchtext = self._query_from_searchtext()
215+
if searchtext and searchtext[0].get("v"):
216+
# TODO: translate
217+
query.append(f"Ricerca per: {searchtext[0]['v']}")
218+
for facet in self.block_data.get("facets") or []:
219+
if "field" not in facet:
220+
logger.warning("invalid facet %s", facet)
221+
continue
222+
if facet["field"]["value"] in self.request.form:
223+
if self.request.form[facet["field"]["value"]] in ["null"]:
224+
continue
225+
# TODO: tonare la label anzichè il value del campo
226+
# TODO: gestire campi particoolari come: multipli, date, ...
227+
query.append(
228+
f'{facet["field"]["label"]}: {self.request.form[facet["field"]["value"]]}'
229+
)
230+
return ",\n".join(query)

src/iosanita/contenttypes/browser/static/export_pdf.css

Lines changed: 53 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,76 @@
11
@page {
2+
/* size: A4 portrait; */
23
size: landscape;
4+
margin-bottom: 3cm;
5+
@bottom-right {
6+
content: counter(page);
7+
font-size: 75%;
8+
width: 50%;
9+
}
10+
@bottom-left {
11+
content: element(footer);
12+
width: 50%;
13+
}
14+
.description.first-page {
15+
display: none;
16+
}
317
}
418

19+
@page :first {
20+
margin-top: 2cm;
21+
@top-left {
22+
content: element(header);
23+
margin-top: 0;
24+
}
25+
.description.first-page {
26+
display: block;
27+
}
28+
}
29+
530
body {
631
font-family: "Titillium Web", Geneva, Tahoma, sans-serif;
7-
font-size: 16px;
8-
margin: 10px auto;
9-
padding: 0 10px;
32+
font-size: 14px;
1033
color: #1C2024;
1134
}
35+
header {
36+
position: running(header);
37+
margin-left: 1em;
38+
width: 20em;
39+
}
40+
41+
/* header .site_data {
42+
display: flex;
43+
width: 580px;
44+
align-items: center;
45+
justify-content: center;
46+
} */
47+
48+
/* header hr {
49+
display: flex;
50+
width: 580px;
51+
align-items: center;
52+
justify-content: center;
53+
} */
54+
55+
footer {
56+
position: running(footer);
57+
width: 20em;
58+
}
59+
1260
a {
1361
color: #235295
1462
}
1563
h1 {
1664
font-weight: 700;
1765
}
1866

19-
p.description {
67+
/* p.description {
2068
font-size: 1.3333333333rem;
21-
}
69+
} */
2270

2371
table.export-table {
2472
table-layout: fixed;
2573
width: 100%;
26-
margin-bottom: 1rem;
2774
box-sizing: border-box;
2875
border-spacing: 2px;
2976
}

src/iosanita/contenttypes/browser/templates/export_pdf.pt

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,39 @@
22
<html xmlns="http://www.w3.org/1999/xhtml"
33
xmlns:i18n="http://xml.zope.org/namespaces/i18n"
44
xmlns:metal="http://xml.zope.org/namespaces/metal"
5-
xmlns:tal="http://xml.zope.org/namespaces/tal" xml:lang="en" tal:define="
5+
xmlns:tal="http://xml.zope.org/namespaces/tal"
6+
tal:define="
67
rows python: options.get('rows', []);
78
columns python: options.get('columns', []);
8-
">
9+
"
10+
i18n:domain="iosanita.contenttypes"
11+
>
912
<head>
1013
<style tal:content="context/pdf_styles|nothing" />
1114
</head>
1215
<body>
13-
<header class="header" tal:define="title context/pdf_title|nothing" tal:condition="title">
16+
<header class="header"
17+
tal:define="title context/pdf_title|nothing; logob64 context/pdf_logob64|nothing"
18+
tal:condition="title">
19+
<img id="logo" tal:condition="logob64" tal:attributes="src logob64"/>
1420
<h1 class="title">${title}</h1>
1521
</header>
22+
23+
<p class="description first-page"
24+
tal:define="description context/pdf_description|nothing"
25+
tal:condition="description"
26+
>${description}</p>
27+
28+
<!-- il footer deve trovarsi in questa posizione per essere presente in tutte le pagine,
29+
non va spostato in fondo
30+
-->
31+
<footer class="footer" tal:condition="context/with_footer|nothing">
32+
<span i18n:translate="last_update_footer">Ultimo aggiornamento:
33+
<tal:dd i18n:name="date" tal:content="context/pdf_last_update|nothing" />
34+
</span>
35+
</footer>
36+
1637
<section>
17-
<p tal:define="description context/pdf_description|nothing"
18-
tal:condition="description"
19-
class="description">${description}</p>
2038
<table class="export-table">
2139
<thead>
2240
<tr>

0 commit comments

Comments
 (0)