Skip to content

Commit

Permalink
added check_persone view
Browse files Browse the repository at this point in the history
  • Loading branch information
daniele-andreotti committed Nov 17, 2023
1 parent 9cf044d commit aaaa945
Show file tree
Hide file tree
Showing 3 changed files with 260 additions and 33 deletions.
115 changes: 82 additions & 33 deletions src/design/plone/contenttypes/browser/utils/check_persone.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,15 @@

import io

from Acquisition import aq_inner
from zope.component import getUtility
from zope.intid.interfaces import IIntIds
from zope.security import checkPermission
from zc.relation.interfaces import ICatalog


FLAG = '<i class="fa-solid fa-check"></i>'


class CheckPersone(BrowserView):
cds = None
Expand All @@ -36,12 +45,46 @@ def get_related_objects(self, obj, field):
items.append(summary)
return sorted(items, key=lambda k: k["title"])

def back_references(self, source_object, attribute_name):

catalog = getUtility(ICatalog)
intids = getUtility(IIntIds)
result = []
# import pdb

# pdb.set_trace()
for rel in catalog.findRelations(
dict(
to_id=intids.getId(aq_inner(source_object)),
from_attribute=attribute_name,
)
):
obj = intids.queryObject(rel.from_id)
if obj is not None and checkPermission("zope2.View", obj):
result.append(obj)
return result

def information_dict(self, persona):
relations = self.get_related_objects(persona, "organizzazione_riferimento")
uo_refs = self.back_references(persona, "responsabile")
uo_refs.extend(self.back_references(persona, "persone_struttura"))

incarichi_persona = ""
if persona.incarichi_persona:

relations = self.get_related_objects(persona, "incarichi_persona")
rel_data = relations[0]

if (
rel_data["data_inizio_incarico"]
and rel_data["title"].strip()
and rel_data["tipologia_incarico"]
):
incarichi_persona = FLAG

return {
"title": getattr(persona, "title"),
"has_related_uo": bool(relations),
"organizzazione_riferimento": relations,
"incarichi_persona": incarichi_persona,
"contact_info": getattr(persona, "contact_info", None),
"organizzazione_riferimento": uo_refs,
}

def plone2volto(self, url):
Expand All @@ -54,6 +97,7 @@ def plone2volto(self, url):
return url

def get_persone(self):

if self.is_anonymous():
return []
pc = api.portal.get_tool("portal_catalog")
Expand All @@ -63,7 +107,7 @@ def get_persone(self):
# nel CatalogTool.py
query = {
"portal_type": "Persona",
# "review_state": "published",
"review_state": "published",
}
brains = pc(query, **{"effectiveRange": DateTime()})
results = {}
Expand All @@ -72,7 +116,7 @@ def get_persone(self):

information_dict = self.information_dict(persona)

if not information_dict.get("has_related_uo"):
if all(information_dict.values()):
continue

parent = persona.aq_inner.aq_parent
Expand All @@ -87,30 +131,31 @@ def get_persone(self):
"title": persona.title,
"url": self.plone2volto(persona.absolute_url()),
"data": {
"title": information_dict.get("title"),
"has_related_uo": information_dict.get("has_related_uo", "V"),
"organizzazione_riferimento": information_dict.get(
"organizzazione_riferimento"
),
)
and FLAG
or "",
"incarichi_persona": information_dict.get("incarichi_persona"),
"contact_info": information_dict.get("contact_info")
and FLAG
or "",
},
}
)

results = dict(sorted(results.items()))
for key in results:
results[key]["children"].sort(key=lambda x: x["title"])

return results


class DownloadCheckPersone(CheckPersone):
CT = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"

def __call__(self):
HEADER = [
"Titolo",
"Ha organizzazioni di riferimento",
"Unità org. di riferimento",
]
HEADER = ["Titolo", "Incarichi", "Unità org. di riferimento", "Contatti"]

EMPTY_ROW = [""] * 3

Expand Down Expand Up @@ -162,17 +207,19 @@ def __call__(self):
sheet.column_dimensions[column_letter].width = 35

for persona in category_data["children"]:
organizzazioni = "\n".join(
[
f"{x.get('title')} - {self.plone2volto(x.get('@id'))}"
for x in persona["data"]["organizzazione_riferimento"]
]
) # noqa
# organizzazioni = "\n".join(
# [
# f"{x.get('title')} - {self.plone2volto(x.get('@id'))}"
# for x in persona["data"]["organizzazione_riferimento"]
# ]
# ) # noqa
title_url = persona["url"]
dati_persona = [
persona["title"],
"X" if persona["data"]["has_related_uo"] else "",
organizzazioni,
"X" if persona["data"]["incarichi_persona"] else "",
"X" if persona["data"]["organizzazione_riferimento"] else "",
"X" if persona["data"]["contact_info"] else "",
# organizzazioni,
]
row = dati_persona
sheet.append(row)
Expand All @@ -184,17 +231,19 @@ def __call__(self):
title_cell.font = link_font
column_letter_unit = get_column_letter(title_cell.column)
sheet.column_dimensions[column_letter_unit].width = 60
max_index = sheet.max_row
for org in organizzazioni.split("\n"):
org_title, org_url = org.split(" - ")
org_link = f'=HYPERLINK("{org_url}", "{org_title}")'
org_cell = sheet.cell(row=max_index, column=3)
org_cell.value = org_link
org_cell.font = link_font
org_cell.alignment = org_cell.alignment.copy(horizontal="left")
column_letter_unit = get_column_letter(org_cell.column)
sheet.column_dimensions[column_letter_unit].width = 80
max_index += 1
# max_index = sheet.max_row

# if organizzazioni:
# for org in organizzazioni.split("\n"):
# org_title, org_url = org.split(" - ")
# org_link = f'=HYPERLINK("{org_url}", "{org_title}")'
# org_cell = sheet.cell(row=max_index, column=3)
# org_cell.value = org_link
# org_cell.font = link_font
# org_cell.alignment = org_cell.alignment.copy(horizontal="left")
# column_letter_unit = get_column_letter(org_cell.column)
# sheet.column_dimensions[column_letter_unit].width = 80
# max_index += 1

sheet.append(EMPTY_ROW)
sheet.append(EMPTY_ROW)
Expand Down
9 changes: 9 additions & 0 deletions src/design/plone/contenttypes/browser/utils/configure.zcml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,15 @@
class=".check_servizi.DownloadCheckServizi"
permission="zope2.Public"
/>

<browser:page
name="check-persone"
for="*"
class=".check_persone.CheckPersone"
template="templates/check_persone.pt"
permission="zope2.Public"
/>

<browser:page
name="download-check-persone"
for="*"
Expand Down
169 changes: 169 additions & 0 deletions src/design/plone/contenttypes/browser/utils/templates/check_persone.pt
Original file line number Diff line number Diff line change
@@ -0,0 +1,169 @@
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:i18n="http://xml.zope.org/namespaces/i18n"
xmlns:metal="http://xml.zope.org/namespaces/metal"
xmlns:tal="http://xml.zope.org/namespaces/tal"
lang="en"
metal:use-macro="context/prefs_main_template/macros/master"
xml:lang="en"
i18n:domain="plone"
>

<body>
<metal:block fill-slot="javascript_head_slot">

</metal:block>
<metal:block fill-slot="style_slot">
<link crossorigin="anonymous"
href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css"
integrity="sha512-iecdLmaskl7CVkqkXNQ/ZH/XLlvWZOJyj7Yy7tcenmpD1ypASozpmT/E0iPtmFIB46ZmdtAc9eNBvH0H/ZpiBw=="
referrerpolicy="no-referrer"
rel="stylesheet"
/>
<style>
li.categoria{margin-bottom:2em}
#content-header,
#mainnavigation-wrapper,
#above-content-wrapper{display:none}
.container{margin-top:2em}

table.people{
border: 1px solid #ddd;
padding: 8px;
}
table.people tr:nth-child(even){background-color: #f2f2f2;}
table.people tr:hover {background-color: #ddd;}
table.people th {
text-align: left;
background-color: #ccc;
color: #000;
padding: 10px;
}
table.people td{
padding: 10px;
}
table.people th{
position: -webkit-sticky;
position: sticky;
top: 0;
z-index: 2;
}
table.people thead tr th.person_title{
width: 250px;
}
.forms{
margin-top: 1em;
margin-bottom: 1em;
text-align:center;
}
.forms button,
.forms input{
border: none; /* Remove borders */
color: white; /* Add a text color */
padding: 14px 28px; /* Add some padding */
cursor: pointer; /* Add a pointer cursor on mouse-over */
background-color: #2196F3;
border-radius: 4px;
}
.forms input:hover{
background: #0b7dda;
}
.download_button{
margin-top: 1em;
margin-bottom: 1em;
text-align:right;
}
</style>
</metal:block>
<tal:main metal:fill-slot="prefs_configlet_wrapper">

<tal:main metal:fill-slot="prefs_configlet_main">
<h1>Verifica dello stato delle persone</h1>
<div tal:condition="view/is_anonymous">
Non hai i permessi per vedere questo elenco di informazioni. Se pensi
che questo non sia corretto verifica di essere autenticato oppure rivolgiti
agli amministratori del sito.
</div>

<div class="lista_persone"
tal:define="
persone view/get_persone;
"
tal:condition="not:view/is_anonymous"
>
<p class="lead"
tal:condition="persone"
>
La lista seguente elenca tutte quelle persone per le quali non sono
ancora stati aggiunti i campi che AGID indica come obbligatori.
Ogni redattore pu&ograve; vedere in questa lista tutte le persone e,
cliccando su ognuna, andare alla vista di dettaglio della persona,
editarla e compilare tutti i campi obbligatori.</p>
<p class="lead"
tal:condition="persone"
>Si fa notare, infine, che la seguente lista di persone
presenta tutte quelle persone in stato pubblicato e
<strong>non scadute</strong>
secondo
le logiche di pubblicazione del CMS Plone, ovvero con una data di scadenza ancora da raggiugnere.</p>

<div class="forms">
<div class="download_button">
<form action="${context/absolute_url}/@@download-check-persone">
<!-- <input type="Submit" value="Download" /> -->
<button class="download-button"
type="submit"
>
<i class="fas fa-download"></i>
Download persone
</button>
</form>
</div>
</div>

<ul>
<li class="categoria"
tal:repeat="categoria persone"
>
<tal:block tal:define="
categoria_url python:persone[categoria]['url'];
">
<h2><a href="${categoria_url}"
target="_blank"
>${categoria}</a></h2>
<ul tal:condition="nothing">
<li class="persona"
tal:repeat="persona python:persone[categoria]['children']"
>
<h5><a href="${persona/url}"
target="_blank"
>${persona/title}</a></h5>
</li>
</ul>
<table class="people">
<thead>
<tr>
<th class="person_title"><span>Titolo</span></th>
<th><span>Organizzazione di riferimento</span></th>
<th><span>Incarichi</span></th>
<th><span>Contatti</span></th>
</tr>
</thead>
<tbody>
<tr tal:repeat="persona python:persone[categoria]['children']">
<td><a href="${persona/url}"
target="_blank"
>${persona/title}</a></td>
<td><span tal:content="structure persona/data/organizzazione_riferimento"></span></td>
<td><span tal:content="structure persona/data/incarichi_persona"></span></td>
<td><span tal:content="structure persona/data/contact_info"></span></td>
</tr>
</tbody>
</table>
</tal:block>
</li>
</ul>
</div>
</tal:main>
</tal:main>
</body>
</html>

0 comments on commit aaaa945

Please sign in to comment.