-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathreporting.py
More file actions
36 lines (27 loc) · 941 Bytes
/
Copy pathreporting.py
File metadata and controls
36 lines (27 loc) · 941 Bytes
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
from itertools import chain
from django.template.defaultfilters import linebreaksbr, urlize
from django.utils.html import format_html, mark_safe
from feincms3_forms.models import FormFieldBase
def get_loaders(plugins):
return list(
chain.from_iterable(
plugin.get_loaders()
for plugin in plugins
if isinstance(plugin, FormFieldBase)
)
)
def value_default(row, default="Ø"):
return row if row["value"] else (row | {"value": default})
def simple_report(*, contents, data):
def _prettify(row):
return row | {"pretty": linebreaksbr(urlize(row["value"]))}
loaders = get_loaders(contents)
return mark_safe(
"<br>\n".join(
format_html(
"<p><strong>{label}</strong> ({name})</p> <p>{pretty}</p>",
**_prettify(value_default(loader(data))),
)
for loader in loaders
)
)