-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added criteria, indexers and vocabularies
- Loading branch information
1 parent
5ec45b2
commit 75b4b9a
Showing
16 changed files
with
583 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
Oops, something went wrong.