Last active
December 18, 2015 14:38
-
-
Save brunobbbs/5798296 to your computer and use it in GitHub Desktop.
Criação de conteúdo programaticamente no Plone a partir do arquivo setuphandlers.py
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
#-*- coding: utf-8 -*- | |
from Products.CMFCore.utils import getToolByName | |
from Products.CMFCore.WorkflowCore import WorkflowException | |
def create_contents(context, contents): | |
for content in contents: | |
options = None | |
if 'options' in content.keys(): | |
options = content.pop('options') | |
if not hasattr(context, content['id']): | |
context.invokeFactory(**content) | |
if options: | |
folder = getattr(context, content['id']) | |
for opt, val in options.items(): | |
if opt == 'allowed_types': | |
folder.setConstrainTypesMode(True) | |
folder.setLocallyAllowedTypes(val) | |
elif opt == 'do_workflow': | |
try: | |
context.portal_workflow.doActionFor(folder, val) | |
except WorkflowException: | |
print '[Warning] WorkflowException: Can\'t %s %s' % (val, folder.id) | |
elif opt == 'view_template': | |
folder.setLayout(val) | |
elif opt == 'contains': | |
create_contents(folder, val) | |
def setupVarious(context): | |
# Ordinarily, GenericSetup handlers check for the existence of XML files. | |
# Here, we are not parsing an XML file, but we use this text file as a | |
# flag to check that we actually meant for this import step to be run. | |
# The file is found in profiles/default. | |
if context.readDataFile('my.namespace_various.txt') is None: | |
return | |
# Add additional setup code here | |
portal = context.getSite() | |
# Permitindo adicionar conteudo na raiz do Plone Site temporariamente | |
portal_types = getToolByName(portal, 'portal_types') | |
plone_site_type = portal_types.get('Plone Site') | |
plone_site_type.filter_content_types = False | |
defaultAllowedTypes = ('File', 'Image', 'Window', 'Link', 'Folder', 'Topic', 'Document') | |
contents = [ | |
{ | |
'type_name': 'Folder', | |
'id': 'boletim', | |
'title': 'Boletim', | |
'options': { | |
'do_workflow': 'publish', | |
'allowed_types': defaultAllowedTypes, | |
}, | |
}, | |
{ | |
'type_name': 'Folder', | |
'id': 'noticias', | |
'title': 'Notícias', | |
'options': { | |
'do_workflow': 'publish', | |
'allowed_types': ('Folder',), | |
'view_template': 'noticias_view', | |
}, | |
}, | |
{ | |
'type_name': 'Folder', | |
'id': 'mesa-de-negociacao', | |
'title': 'Mesa de Negociação', | |
'options': { | |
'do_workflow': 'publish', | |
'allowed_types': ('Event',) + defaultAllowedTypes, | |
'view_template': 'mesanegociacao_view', | |
'contains': ( | |
{ | |
'type_name': 'Document', | |
'id': 'comissao-de-negociacao', | |
'title': 'Comissão de Negociação', | |
'options': { | |
'do_workflow': 'publish', | |
'view_template': 'mesanegociacaodocument_view', | |
} | |
}, | |
) | |
}, | |
}, | |
{ | |
'type_name': 'Folder', | |
'id': 'pautas', | |
'title': 'Pautas', | |
'options': { | |
'do_workflow': 'publish', | |
'allowed_types': defaultAllowedTypes, | |
}, | |
}, | |
{ | |
'type_name': 'Folder', | |
'id': 'propostas', | |
'title': 'Propostas', | |
'options': { | |
'do_workflow': 'publish', | |
'allowed_types': defaultAllowedTypes, | |
}, | |
}, | |
{ | |
'type_name': 'Folder', | |
'id': 'acordos-coletivos', | |
'title': 'Acordos Coletivos', | |
'options': { | |
'do_workflow': 'publish', | |
'allowed_types': defaultAllowedTypes, | |
}, | |
}, | |
{ | |
'type_name': 'Folder', | |
'id': 'duvidas-frequentes', | |
'title': 'Dúvidas Frequentes', | |
'options': { | |
'do_workflow': 'publish', | |
'allowed_types': defaultAllowedTypes, | |
}, | |
}, | |
{ | |
'type_name': 'Folder', | |
'id': 'banner-principal', | |
'title': 'Banner principal', | |
'excludeFromNav': True, | |
'options': { | |
'do_workflow': 'publish', | |
'allowed_types': defaultAllowedTypes, | |
}, | |
}, | |
] | |
create_contents(portal, contents) | |
plone_site_type.filter_content_types = True |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment