from Products.CMFCore.utils import getToolByName from Products.ExternalMethod.ExternalMethod import manage_addExternalMethod from StringIO import StringIO from Products.ILPortal.vocabularies import VOCABULARIOS from Products.ILPortal.config import * from Products.CMFPlone.migrations.migration_util import safeEditProperty from Acquisition import aq_base INDEX_HTML = '''
''' def install(self): out = StringIO() portal = getToolByName(self, 'portal_url').getPortalObject() setupPortal(portal) setupSlots(portal) deleteAction(portal) replaceIndex(portal) deletePastas(portal) extMethodSetupPastas(portal) # addPastas(portal) # addNewsletters(portal) # addForuns(portal) # addEnquetes(portal) # addImagens(portal) # addChats(portal) # setupPublicatorDestaques(portal) # setupPublicatorProdutos(portal) # setupPublicatorChamadas(portal) # setupPublicatorOpiniao(portal) # setupPublicatorMelhoresPraticas(portal) addJavaScript(portal) addCSS(portal) setupActions(portal) setupTipo(portal) setupMemberdata(portal) setupMailHost(portal) setILPortalProperties(portal) setupSkin(portal) setupMetadata(portal) setupTextIndexNG3(portal) addRoles(portal) setupWorkflow(portal) setupBusca(portal) setupConfiguracao(portal) setPloneProperties(self, portal, out) return 'Feito!' def setupPortal(portal): portal.manage_changeProperties(title='Portal Interlegis', email_from_address='paulovieira@interlegis.gov.br', email_from_name= 'Administrador') def setupSlots(portal): left_slots = ('here/portlet_navigation/macros/portlet', ) portal._setPropValue('left_slots', left_slots) right_slots = ('here/portlet_review/macros/portlet', \ 'here/global_personalbar/macros/portlet', ) portal._setPropValue('right_slots', right_slots) def deleteAction(portal): portal_actions = getToolByName(portal, 'portal_actions') idx = 0 for action in portal_actions.listActions(): if action.getId() == 'index_html': portal_actions.deleteActions((idx,)) break idx += 1 def replaceIndex(portal): if 'front-page' in portal.objectIds(): portal.manage_delObjects('front-page') portal.manage_addProduct['PageTemplates'].manage_addPageTemplate('index_html', '', INDEX_HTML) def deletePastas(portal): if 'news' in portal.objectIds(): portal.manage_delObjects('news') if 'events' in portal.objectIds(): portal.manage_delObjects('events') def extMethodSetupPastas(portal): manage_addExternalMethod(portal, 'Setup_pastas', 'Cria e configura as pastas do Portal', 'ILPortal.setup_pastas', 'setup_pastas') def addPastas(portal): if 'chamadas' not in portal.objectIds(): portal.invokeFactory('Folder', id='chamadas', title='Chamadas', excludeFromNav=0) if 'opiniao' not in portal.objectIds(): portal.invokeFactory('Folder', id='opiniao', title='Opinião', excludeFromNav=0) if 'melhores_praticas' not in portal.objectIds(): portal.invokeFactory('Folder', id='melhores_praticas', title='Melhores Práticas', excludeFromNav=0) if 'produtos' not in portal.objectIds(): portal.invokeFactory('Folder', id='produtos', title='Produtos', excludeFromNav=0) def addNewsletters(portal): if 'boletins' not in portal.objectIds(): portal.invokeFactory('Folder', id='boletins', title='Boletins', excludeFromNav=0) newsletters = getattr(aq_base(portal), 'boletins') addable_types = ['Subscriber','NewsletterTheme'] if getattr(newsletters.aq_base, 'setConstrainTypesMode', None) is not None: newsletters.setConstrainTypesMode(1) newsletters.setImmediatelyAddableTypes(addable_types) newsletters.setLocallyAllowedTypes(addable_types) def addForuns(portal): if 'foruns' not in portal.objectIds(): portal.invokeFactory('Ploneboard', id='foruns', title='Fóruns') def addChats(portal): if 'chats' not in portal.objectIds(): portal.invokeFactory('Folder', id='chats', title='Chats', excludeFromNav=0) chat = getattr(aq_base(portal), 'chats') addable_types = ['PloneChat'] if getattr(chat.aq_base, 'setConstrainTypesMode', None) is not None: chat.setConstrainTypesMode(1) chat.setImmediatelyAddableTypes(addable_types) chat.setLocallyAllowedTypes(addable_types) def addEnquetes(portal): if 'enquetes' not in portal.objectIds(): portal.invokeFactory('Folder', id='enquetes', title='Enquetes', excludeFromNav=0) enquete = getattr(aq_base(portal), 'enquetes') addable_types = ['PlonePopoll'] if getattr(enquete.aq_base, 'setConstrainTypesMode', None) is not None: enquete.setConstrainTypesMode(1) enquete.setImmediatelyAddableTypes(addable_types) enquete.setLocallyAllowedTypes(addable_types) def addImagens(portal): if 'imagens' not in portal.objectIds(): portal.invokeFactory('Folder', id='imagens', title='Imagens', excludeFromNav=0) imagem = getattr(aq_base(portal), 'imagens') addable_types = ['Image','Folder'] if getattr(imagem.aq_base, 'setConstrainTypesMode', None) is not None: imagem.setConstrainTypesMode(1) imagem.setImmediatelyAddableTypes(addable_types) imagem.setLocallyAllowedTypes(addable_types) def setupPublicatorDestaques(portal): portal_publicator = getToolByName(portal,'portal_publicator') if not portal_publicator.listPublicationBoxes(): portal_publicator.addPublicationBox(id='destaques', name='Destaques', content_type=['Document','News Item'], n_items=2, with_image=1, image_states=['published'],) for actions in portal_publicator.listActions(): portal_publicator.deleteActions((0,)) portal_publicator.addAction(id='edit_publications_global', name='Publications', action='string:${portal_url}/portal_publicator/publicator_edit_form', condition='member', permission='Review portal content', category='user', visible=0) portal_publicator.addAction(id='edit_publications_global', name='Publications', action='python:object.portal_publicator.absolute_url()+"/publicator_edit_form"', condition='python:member and folder.portal_publicator.absolute_url()==folder.absolute_url()+"/portal_publicator"', permission='Review portal content', category='folder', visible=1) def setupPublicatorProdutos(portal): portal.produtos.manage_addProduct['CMFPublicator'].manage_addTool('CMF Publicator', None) portal_publicator = getattr(portal.produtos,'portal_publicator') if not portal_publicator.listPublicationBoxes(): portal_publicator.addPublicationBox(id='produtos', name='Produtos', content_type=['File'], n_items=2, with_image=1, image_states=['published'],) def setupPublicatorChamadas(portal): portal.chamadas.manage_addProduct['CMFPublicator'].manage_addTool('CMF Publicator', None) portal_publicator = getattr(portal.chamadas,'portal_publicator') if not portal_publicator.listPublicationBoxes(): portal_publicator.addPublicationBox(id='chamadas', name='Chamadas', content_type=['Document'], n_items=1, with_image=0, image_states=['published'],) def setupPublicatorOpiniao(portal): portal.opiniao.manage_addProduct['CMFPublicator'].manage_addTool('CMF Publicator', None) portal_publicator = getattr(portal.opiniao,'portal_publicator') if not portal_publicator.listPublicationBoxes(): portal_publicator.addPublicationBox(id='opiniao', name='Opinião', content_type=['Document','News Item'], n_items=2, with_image=1, image_states=['published'],) def setupPublicatorMelhoresPraticas(portal): portal.melhores_praticas.manage_addProduct['CMFPublicator'].manage_addTool('CMF Publicator', None) portal_publicator = getattr(portal.melhores_praticas,'portal_publicator') if not portal_publicator.listPublicationBoxes(): portal_publicator.addPublicationBox(id='melhores_praticas', name='Melhores Práticas', content_type=['Document','News Item'], n_items=5, with_image=0, image_states=['published'],) def setPloneProperties(self, portal, out): print >>out, 'Customizando o Plone para o ILPortal...' portal_properties = getToolByName(portal, 'portal_properties') site_properties = getattr(portal_properties, 'site_properties') safeEditProperty(site_properties, 'localTimeFormat', '%d/%m/%Y', 'string') safeEditProperty(site_properties, 'localLongTimeFormat', '%d/%m/%Y %H:%M', 'string') safeEditProperty(site_properties, 'default_language', 'pt-br', 'string') safeEditProperty(site_properties, 'calendar_starting_year', 1900, 'int') portal_properties.site_properties.disable_folder_sections = (True) portal_properties.navtree_properties.includeTop = (False) portal_properties.navtree_properties.idsNotToList = ('Members',) portal_properties.navtree_properties.enable_wf_state_filtering = (True) portal_properties.navtree_properties.wf_states_to_show = ('published',) print >>out, 'Plone para ILPortal customizado!\n' def setILPortalProperties(portal): portal_properties = getToolByName(portal, 'portal_properties') if not hasattr(portal_properties,'ilportal_properties'): portal_properties.manage_addPropertySheet('ilportal_properties','Propriedades do Portal Interlegis') for vocab in VOCABULARIOS.keys(): if not portal_properties.ilportal_properties.hasProperty(vocab): portal_properties.ilportal_properties._setProperty(vocab, VOCABULARIOS[vocab], 'lines') def setILPortalProperties2(portal): portal_properties = getToolByName(portal, 'portal_properties') if not hasattr(portal_properties,'ilportal_properties'): portal_properties.manage_addPropertySheet('ilportal_properties','Propriedades do Portal Interlegis') if not portal_properties.ilportal_properties.hasProperty('sexo'): sexos = ['M;Masculino', 'F;Feminino'] portal_properties.ilportal_properties._setProperty('sexo', sexos, 'lines') if not portal_properties.ilportal_properties.hasProperty('tip_casa_interlegis'): tipos = ['AL;Assembléia Legislativa', 'CD;Câmara dos Deputados', 'CM;Câmara Municipal', 'CT;Câmara Legislativa', 'OI;Outras Instituições', 'SF;Senado Federal',] portal_properties.ilportal_properties._setProperty('tip_casa_interlegis', tipos, 'lines') if not portal_properties.ilportal_properties.hasProperty('status'): status = ['1;Ativo', '2;Afastado'] portal_properties.ilportal_properties._setProperty('status', status, 'lines') if not portal_properties.ilportal_properties.hasProperty('suplencia'): suplencia = ['1;Suplente', '2;Titular'] portal_properties.ilportal_properties._setProperty('suplencia', status, 'lines') if not portal_properties.ilportal_properties.hasProperty('estado'): estados = ['AC;Acre', 'AL;Alagoas', 'AP;Amapá', 'AM;Amazonas', 'BA;Bahia', 'CE;Ceará', 'DF;Distrito Federal', 'ES;Espírito Santo', 'GO;Goiás', 'MA;Maranhão', 'MT;Mato Grosso', 'MS;Mato Grosso do Sul', 'MG;Minas Gerais', 'PA;Pará', 'PB;Paraíba', 'PR;Paraná', 'PE;Pernambuco', 'PI;Piauí', 'RJ;Rio de Janeiro', 'RN;Rio Grande do Norte', 'RS;Rio Grande do Sul', 'RO;Rondônia', 'RR;Roraima', 'SC;Santa Catarina', 'SP;São Paulo', 'SE;Sergipe', 'TO;Tocantins'] portal_properties.ilportal_properties._setProperty('estado', estados, 'lines') if not portal_properties.ilportal_properties.hasProperty('escolaridade'): escolaridades = ['1;1º Grau Incompleto', '2;1º Grau Completo', '3;2º Grau Incompleto', '4;2º Grau Completo', '5;3º Grau Incompleto', '6;3º Grau Completo', '7;Especialização', '8;Mestrado', '9;Doutorado'] portal_properties.ilportal_properties._setProperty('escolaridade', escolaridades, 'lines') if not portal_properties.ilportal_properties.hasProperty('cargo_mesa_diretora'): cargos_mesa_diretora = ['P;Presidente', 'VP;Vice-Presidente', '1VP;1º Vice-Presidente', '2VP;2º Vice-Presidente', '1SE;1º Secretário', '2SE;2º Secretário', '3SE;3º Secretário', '4SE;4º Secretário', '1SU;1º Suplente', '2SU;2º Suplente', '3SU;3º Suplente', 'SS;Suplente de Secretário', '1SS;1º Suplente de Secretário', '2SS;2º Suplente de Secretário', '3SS;3º Suplente de Secretário', '4SS;4º Suplente de Secretário'] portal_properties.ilportal_properties._setProperty('cargo_mesa_diretora', cargos_mesa_diretora, 'lines') if not portal_properties.ilportal_properties.hasProperty('partido'): partidos = ['PAN;PAN - Partido dos Aposentados da Nação', 'PCO;PCO - Partido da Causa Operaria', 'PCB;PCB - Partido Comunista Brasileiro', 'PCdoB;PC do B - Partido Comunista do Brasil', 'PDT;PDT - Partido Democrático Trabalhista', 'PFL;PFL - Partido da Frente Liberal', 'PHS;PHS - Partido Humanista da Solidariedade', 'PL;PL - Partido Liberal', 'PMN;PMN - Partido da Mobilização Nacional', 'PMDB;PMDB - Partido do Movimento Democrático Brasileiro', 'PP;PP - Partido Progressista', 'PPS;PPS - Partido Popular Socialista', 'PRONA;PRONA - Partido da Reedificação da Ordem Nacional', 'PRTB;PRTB - Partido Renovador Trabalhista Brasileiro', 'PSB;PSB - Partido Socialista Brasileiro', 'PSC;PSC - Partido Socialista Cristão', 'PSDB;PSDB - Partido da Social Democracia Brasileira', 'PSDC;PSDC - Partido Social Democrata Cristão', 'PSL;PSL - Partido Social Liberal', 'PSTU;PSTU - Partido Socialista dos Trabalhadores Unificado', 'PT;PT - Partido dos Trabalhadores', 'PTdoB;PT do B - Partido Trabalhista do Brasil', 'PTB;PTB - Partido Trabalhista Brasileiro', 'PTN;PTN - Partido Trabalhista Nacional', 'PV;PV - Partido Verde'] portal_properties.ilportal_properties._setProperty('partido', partidos, 'lines') def setupActions(portal): portal_actions = getToolByName(portal, 'portal_actions') idx = 0 for actions in portal_actions.listActions(): if actions.getCategory() == 'site_actions': portal_actions.deleteActions((idx,)) idx-=1 idx += 1 portal_actions.addAction(id='login', name='Log in', action='string:${portal_url}/login_form', condition='not: member', permission='View', category='site_actions', visible=1) portal_actions.addAction(id='join', name='Join', action='string:${portal_url}/join_form', condition='not: member', permission='Add portal member', category='site_actions', visible=1) portal_actions.addAction(id='contact', name='Contact', action='string: ${portal_url}/contact-info', condition='', permission='View', category='site_actions', visible=1) portal_actions.addAction(id='sitemap', name='Site Map', action='string:$portal_url/sitemap', condition='', permission='View', category='site_actions', visible=1) portal_actions.addAction(id='plone_setup', name='Site Setup', action='string: ${portal_url}/plone_control_panel', condition='', permission='Manage portal', category='site_actions', visible=1) def setupTipo(portal): portal_types = getToolByName(portal, 'portal_types') portal_types['Plone Site'].global_allow = False addable_types=['Folder'] portal_types['Plone Site'].filter_content_types = True portal_types['Plone Site'].allowed_content_types = addable_types for action in portal_types['MesaDiretora'].listActions(): if action.getId()=='view': action.setActionExpression('string:${object_url}/mesa_view') break for action in portal_types['CasaLegislativa'].listActions(): if action.getId()=='view': action.setActionExpression('string:${object_url}/casa_view') break def addJavaScript(portal): portal.portal_javascripts.manage_addScript(id='menu_superior.js', expression='', inline=False, enabled=True, cookable=True, REQUEST=None,) def addCSS(portal): portal.portal_css.manage_addStylesheet(id='menu_superior.css', expression='', media='screen', rel='sylesheet', title='', rendering='import', enabled=True, cookable=True, REQUEST=None,) def setupMemberdata(portal): portal_memberdata = getToolByName(portal, 'portal_memberdata') if not portal_memberdata.hasProperty('sexo'): portal_memberdata._setProperty('sexo', '', 'string') if not portal_memberdata.hasProperty('endereco'): portal_memberdata._setProperty('endereco', '', 'string') if not portal_memberdata.hasProperty('cidade'): portal_memberdata._setProperty('cidade', '', 'string') if not portal_memberdata.hasProperty('estado'): portal_memberdata._setProperty('estado', '', 'string') if not portal_memberdata.hasProperty('cep'): portal_memberdata._setProperty('cep', '', 'string') if not portal_memberdata.hasProperty('ddd'): portal_memberdata._setProperty('ddd', '', 'string') if not portal_memberdata.hasProperty('telefone'): portal_memberdata._setProperty('telefone', '', 'string') if not portal_memberdata.hasProperty('empresa'): portal_memberdata._setProperty('empresa', '', 'string') if not portal_memberdata.hasProperty('cargo'): portal_memberdata._setProperty('cargo', '', 'string') if not portal_memberdata.hasProperty('escolaridade'): portal_memberdata._setProperty('escolaridade', '', 'string') def setupMailHost(portal): MailHost = getToolByName(portal, 'MailHost') MailHost.manage_makeChanges(title='Interlegis', smtp_host='smtp.interlegis.gov.br', smtp_port=25, smtp_userid='', smtp_pass='') def setupSkin(portal): portal_skins = getToolByName(portal, 'portal_skins') path = portal_skins.getSkinPath('Plone Default') path = [elem.strip() for elem in path.split(',') if elem != '.svn'] path = ','.join(path) portal_skins.addSkinSelection('Portal Interlegis', path) portal_skins.manage_properties(default_skin = 'Portal Interlegis', request_varname = 'plone_skin', del_skin = 0, chosen = []) def setupMetadata(portal): portal_metadata = getToolByName(portal, 'portal_metadata') portal_metadata.updateElementPolicy( element='Subject', content_type='Event', is_required=0, supply_default=0, default_value='', enforce_vocabulary=0, allowed_vocabulary=('Encontro', 'Convenção', 'Reunião', 'Evento Social', 'Trabalho')) def setupTextIndexNG3(portal): catalog = getToolByName(portal,'portal_catalog') for idx in ('SearchableText', 'Title', 'Description'): catalog._removeIndex(idx) catalog.manage_addIndex('SearchableText', 'TextIndexNG3', extra={'default_encoding':'utf-8', 'languages':('pt-br','en',), 'splitter_casefolding':1, 'dedicated_storage':0, 'index_unknown_languages':1, 'use_stemmer':0, 'use_normalizer':0, } ) catalog.manage_addIndex('Title', 'TextIndexNG3', extra={'default_encoding':'utf-8', 'languages':('pt-br','en'), 'splitter_casefolding':1, 'dedicated_storage':0, 'index_unknown_languages':1, 'use_stemmer':0, 'use_normalizer':0, } ) catalog.manage_addIndex('Description', 'TextIndexNG3', extra={'default_encoding':'utf-8', 'languages':('pt-br','en'), 'splitter_casefolding':1, 'dedicated_storage':0, 'index_unknown_languages':1, 'use_stemmer':0, 'use_normalizer':0, } ) catalog.manage_reindexIndex(['Title','Description','SearchableText']) def addRoles(portal): portal._addRole(role='Autor') portal._addRole(role='Editor') # permissions = [] # for perm in portal.aq_parent.permissionsOfRole('Owner'): # if perm.get('selected') != '': # permissions.append(perm.get('name')) # for perm in portal.permissionsOfRole('Owner'): # if perm.get('selected') != '' and perm.get('name') not in permissions: # permissions.append(perm.get('name')) # print permissions permissions = ['ATContentTypes: Add Document', 'ATContentTypes: Add Event', 'ATContentTypes: Add Favorite', 'ATContentTypes: Add File', 'ATContentTypes: Add Folder', 'ATContentTypes: Add Image', 'ATContentTypes: Add Large Plone Folder', 'ATContentTypes: Add Link', 'ATContentTypes: Add News Item', 'Add CasaLegislativa Content', 'Add MembroMesaDiretora Content', 'Add MesaDiretora Content', 'Add Parlamentar Content', 'Add PlonePopolls', 'Add Telefone Content', 'Add portal content', 'Add portal events', 'Add portal folders', 'Change local roles', 'Change portal events', 'Change portal topics', 'Edit PlonePopoll', 'List folder contents', 'Modify constrain types', 'Modify view template', 'PNL Add Subscriber', 'PNL Change Newsletter', 'PNL Change Newsletter Theme', 'PNL Change Subscriber', 'Ploneboard: Add Ploneboard', 'Ploneboard: Notify Retracted', 'PortalTransport: Allow Subscription', 'Request review', 'Set Group Ownership', 'Take ownership', 'View Groups', 'Vote for a PlonePopoll', 'WebDAV Lock items', 'WebDAV Unlock items', 'Access inactive portal content', 'Add PloneChat objects', 'Chat moderatedly', 'Chat unmoderatedly', 'Delete objects', 'Edit PloneChats', 'FTP access', 'Manage properties', 'Undo changes', 'View management screens'] portal.manage_role(role_to_manage='Autor', permissions=permissions) # permissions = [] # for perm in portal.permissionsOfRole('Reviewer'): # if perm.get('selected') != '': # permissions.append(perm.get('name')) permissions += ['Access future portal content', 'Moderate PloneChats', 'Review portal content'] portal.manage_role(role_to_manage='Editor', permissions=permissions) portal._delRoles(roles=['Reviewer']) def setupWorkflow(portal): portal_workflow = getToolByName(portal, 'portal_workflow') portal_workflow.setDefaultChain('ilportal_workflow') def setupBusca(portal): portal_properties=getToolByName(portal, 'portal_properties') portaltypes = ['CasaLegislativa','Event','PloneChat','PlonePopoll','File','Folder','Image','Link','News Item', 'Document', 'Parlamentar'] allTypes = portal.getPortalTypes() blacklistedTypes = [t for t in allTypes if t not in portaltypes] portal_properties.site_properties.manage_changeProperties(types_not_searched=blacklistedTypes) def setupConfiguracao(portal): portal.portal_controlpanel.registerConfiglet(**prefs_portal_configlet) def uninstall(self): try: self.portal_controlpanel.unregisterApplication(PROJECTNAME) except: pass