Skip to content

Commit

Permalink
added criteria, indexers and vocabularies
Browse files Browse the repository at this point in the history
  • Loading branch information
daniele-andreotti committed Jul 5, 2024
1 parent 5ec45b2 commit 75b4b9a
Show file tree
Hide file tree
Showing 16 changed files with 583 additions and 29 deletions.
26 changes: 0 additions & 26 deletions src/iosanita/contenttypes/behaviors/argomenti.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,20 +31,6 @@ class IArgomentiSchema(model.Schema):
required=False,
default=[],
)
correlato_in_evidenza = RelationList(
title=_("correlato_in_evidenza_label", default="Correlato in evidenza"),
description=_(
"correlato_in_evidenza_help",
default="Seleziona un correlato da mettere in evidenza per questo"
" contenuto.",
),
value_type=RelationChoice(
title=_("Correlato in evidenza"),
vocabulary="plone.app.vocabularies.Catalog",
),
required=False,
default=[],
)

form.widget(
"tassonomia_argomenti",
Expand All @@ -54,12 +40,6 @@ class IArgomentiSchema(model.Schema):
"selectableTypes": ["Pagina Argomento"],
},
)
form.widget(
"correlato_in_evidenza",
RelatedItemsFieldWidget,
vocabulary="plone.app.vocabularies.Catalog",
pattern_options={"maximumSelectionSize": 1},
)

textindexer.searchable("tassonomia_argomenti")

Expand All @@ -68,12 +48,6 @@ class IArgomentiSchema(model.Schema):
class IArgomenti(IArgomentiSchema):
""" """

model.fieldset(
"correlati",
label=_("correlati_label", default="Contenuti collegati"),
fields=["correlato_in_evidenza"],
)


@provider(IFormFieldProvider)
class IArgomentiEvento(IArgomentiSchema):
Expand Down
Empty file.
229 changes: 229 additions & 0 deletions src/iosanita/contenttypes/events/common.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,229 @@
# -*- coding: utf-8 -*-
from design.plone.contenttypes.interfaces import IDesignPloneContenttypesLayer
from design.plone.contenttypes.utils import create_default_blocks
from plone import api
from Products.CMFPlone.interfaces import ISelectableConstrainTypes


SUBFOLDERS_MAPPING = {
"Bando": {
"content": [
{"id": "documenti", "title": "Documenti", "type": "Bando Folder Deepening"},
{
"id": "comunicazioni",
"title": "Comunicazioni",
"type": "Bando Folder Deepening",
},
{"id": "esiti", "title": "Esiti", "type": "Bando Folder Deepening"},
],
},
"Documento": {
"content": [
{
"id": "multimedia",
"title": "Multimedia",
"type": "Document",
"allowed_types": ("Image",),
},
],
},
"Event": {
"content": [
{
"id": "immagini",
"title": "Immagini",
"allowed_types": ("Image", "Link"),
"publish": True,
},
{
"id": "video",
"title": "Video",
"allowed_types": ("Link",),
"publish": True,
},
{
"id": "sponsor_evento",
"title": "Sponsor Evento",
"allowed_types": ("Link",),
"publish": True,
},
{
"id": "documenti",
"title": "Allegati",
"allowed_types": ("File",),
"publish": True,
},
],
},
"Incarico": {
"content": [
{"id": "compensi-file", "title": "Compensi", "allowed": ("File",)},
{
"id": "importi-di-viaggio-e-o-servizi",
"title": "Importi di viaggio e/o servizi",
"allowed_types": ("File",),
},
],
"allowed_types": [],
},
"Venue": {
"content": [
{
"id": "multimedia",
"title": "Multimedia",
"type": "Folder",
"allowed_types": (
"Image",
"Link",
),
"publish": True,
}
],
},
"News Item": {
"content": [
{
"id": "multimedia",
"title": "Multimedia",
"allowed_types": (
"Image",
"Link",
),
},
{
"id": "documenti-allegati",
"title": "Documenti allegati",
"allowed_types": (
"File",
"Image",
),
},
],
},
"Persona": {
"content": [
{
"id": "foto-e-attivita-politica",
"title": "Foto e attività politica",
"allowed_types": ("Image",),
},
{
"id": "curriculum-vitae",
"title": "Curriculum vitae",
"allowed_types": ("File",),
},
{
"id": "situazione-patrimoniale",
"title": "Situazione patrimoniale",
"allowed_types": ("File",),
},
{
"id": "dichiarazione-dei-redditi",
"title": "Dichiarazione dei redditi",
"allowed_types": ("File",),
},
{
"id": "spese-elettorali",
"title": "Spese elettorali",
"allowed_types": ("File",),
},
{
"id": "variazione-situazione-patrimoniale",
"title": "Variazione situazione patrimoniale",
"allowed_types": ("File",),
},
{
"id": "altre-cariche",
"title": "Altre cariche",
"allowed_types": ("File",),
},
{"id": "incarichi", "title": "Incarichi", "allowed_types": ("Incarico",)},
{
"id": "altri-documenti",
"title": "Altri documenti",
"allowed_types": ("File", "Image", "Link"),
},
],
"allowed_types": [],
},
"Pratica": {
"content": [
{
"id": "allegati",
"title": "Allegati",
"type": "Folder",
"allowed_types": ("File",),
}
],
},
"Servizio": {
"content": [
{
"id": "modulistica",
"title": "Modulistica",
"allowed_types": ("Link",),
},
{"id": "allegati", "title": "Allegati", "allowed_types": ("File", "Link")},
],
},
"UnitaOrganizzativa": {
"content": [
{"id": "allegati", "title": "Allegati", "allowed_types": ("File",)},
],
},
}


def onModify(context, event):
for description in event.descriptions:
if "IBasic.title" in getattr(
description, "attributes", []
) or "IDublinCore.title" in getattr(description, "attributes", []):
for child in context.listFolderContents():
child.reindexObject(idxs=["parent"])


def createSubfolders(context, event):
"""
Create subfolders structure based on a portal_type mapping
"""
if not IDesignPloneContenttypesLayer.providedBy(context.REQUEST):
return

subfolders_mapping = SUBFOLDERS_MAPPING.get(context.portal_type, [])
if not subfolders_mapping:
return

for mapping in subfolders_mapping.get("content", {}):
if mapping["id"] not in context.keys():
portal_type = mapping.get("type", "Document")
child = api.content.create(
container=context,
type=portal_type,
title=mapping["title"],
id=mapping["id"],
)
if portal_type == "Document":
create_default_blocks(context=child)

if portal_type in ["Folder", "Document"]:
child.exclude_from_search = True
child.reindexObject(idxs=["exclude_from_search"])
# select constraints
if mapping.get("allowed_types", ()):
constraints_child = ISelectableConstrainTypes(child)
constraints_child.setConstrainTypesMode(1)
constraints_child.setLocallyAllowedTypes(mapping["allowed_types"])

if mapping.get("publish", False):
with api.env.adopt_roles(["Reviewer"]):
api.content.transition(obj=child, transition="publish")

allowed_types = subfolders_mapping.get("allowed_types", None)
if allowed_types is not None and not isinstance(allowed_types, list):
raise ValueError("Subfolder map is not well formed")

if isinstance(allowed_types, list):
constraints_context = ISelectableConstrainTypes(context)
constraints_context.setConstrainTypesMode(1)
constraints_context.setLocallyAllowedTypes(allowed_types)
25 changes: 25 additions & 0 deletions src/iosanita/contenttypes/events/configure.zcml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<configure
xmlns="http://namespaces.zope.org/zope"
xmlns:plone="http://namespaces.zope.org/plone"
xmlns:zcml="http://namespaces.zope.org/zcml"
i18n_domain="iosanita.contenttypes"
>

<!-- common -->
<subscriber
for="plone.dexterity.interfaces.IDexterityContent
zope.lifecycleevent.interfaces.IObjectModifiedEvent"
handler=".common.onModify"
/>
<subscriber
for="plone.dexterity.interfaces.IDexterityContent
zope.lifecycleevent.interfaces.IObjectAddedEvent"
handler=".common.createSubfolders"
/>
<subscriber
for="plone.app.contenttypes.interfaces.IEvent
zope.lifecycleevent.interfaces.IObjectModifiedEvent"
handler=".events.EventModified"
/>

</configure>
8 changes: 8 additions & 0 deletions src/iosanita/contenttypes/events/events.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
from Acquisition import aq_inner, aq_parent


def EventModified(dx_event, event):
parent = aq_parent(aq_inner(dx_event))
if parent.portal_type == "Event":
parent.reindexObject(idxs=["rassegna"])
return
Empty file.
43 changes: 43 additions & 0 deletions src/iosanita/contenttypes/indexers/common.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# -*- coding: utf-8 -*-
from plone.dexterity.interfaces import IDexterityContent
from plone.indexer.decorator import indexer


@indexer(IDexterityContent)
def tassonomia_argomenti(context, **kw):
return [
x.to_object.Title()
for x in getattr(context.aq_base, "tassonomia_argomenti", [])
if x.to_object
]


@indexer(IDexterityContent)
def tassonomia_argomenti_uid(context, **kw):
return [
x.to_object.UID()
for x in getattr(context.aq_base, "tassonomia_argomenti", [])
if x.to_object
]


@indexer(IDexterityContent)
def ufficio_responsabile(context, **kw):
uffici = getattr(context.aq_base, "ufficio_responsabile", [])
return [ufficio.UID() for ufficio in filter(bool, [x.to_object for x in uffici])]


@indexer(IDexterityContent)
def parent(context):
obj_parent = context.aq_parent
return {
"title": obj_parent.Title(),
"UID": obj_parent.UID(),
"@id": obj_parent.absolute_url(),
"@type": obj_parent.portal_type,
}


@indexer(IDexterityContent)
def exclude_from_search(context):
return getattr(context.aq_base, "exclude_from_search", False)
34 changes: 34 additions & 0 deletions src/iosanita/contenttypes/indexers/configure.zcml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<configure xmlns="http://namespaces.zope.org/zope">

<adapter
factory=".events.event_location"
name="event_location"
/>
<adapter
factory=".common.tassonomia_argomenti"
name="tassonomia_argomenti"
/>
<adapter
factory=".common.tassonomia_argomenti_uid"
name="tassonomia_argomenti_uid"
/>
<adapter
factory=".common.ufficio_responsabile"
name="ufficio_responsabile"
/>
<adapter
factory=".common.parent"
name="parent"
/>
<adapter
factory=".common.exclude_from_search"
name="exclude_from_search"
/>
<adapter
factory=".events.rassegna"
name="rassegna"
/>

<!-- only metadata -->

</configure>
Loading

0 comments on commit 75b4b9a

Please sign in to comment.