source: publico/ILPortalCasas/trunk/Extensions/AppInstall.py @ 2501

Última Alteração nesse arquivo desde 2501 foi 2501, incluída por rafahelabazzanella, 14 anos atrás

Acrescntados tipos do Prestacao de Contas no portal_factory

File size: 20.1 KB
Linha 
1from Products.CMFCore.utils import getToolByName
2from Products.ExternalMethod.ExternalMethod import manage_addExternalMethod
3from Products.ILPortalCasas.config import *
4from Products.ILPortalCasas.config_install import *
5from Products.ILPortalCasas.Extensions.install_taxonomy import *
6from Products.ILPortalCasas.Previsao import Previsao
7from Acquisition import aq_base
8import sys, os
9
10def install(self):
11    portal = self
12    setupControlPanel(portal)
13    setupWorkflow(portal)
14    setupTING(portal)
15    setupIndex(portal)
16    addTaxonomy(portal)
17    addOuvidoria(portal)
18    setupPortal(portal)
19    setupSlots(portal)
20    deleteAction(portal)
21    deleteAction2(portal)
22    deleteAction3(portal)
23    deleteAction4(portal)
24    deleteCategoria(portal)
25    setupActions(portal)
26    setupCss(portal)
27    setupCssmanager(portal)
28    setupFactory(portal)
29    setupMembership(portal)
30    setupGroups(portal)
31    setupLanguages(portal)
32    setupScripts(portal)
33    setupMetadata(portal)
34    setupProperties(portal)
35    setupPublicatorUtilidades(portal)
36    setupPublicatorDestaque(portal)
37    setupPublicatorNoticia(portal)
38    setupPublicatorBanner(portal)
39    setupRSS(portal)
40    setupSin(portal)
41    setupSkin(portal)
42    setupTipo(portal)
43    addBackup(portal)
44    addScheduler(portal)
45    installPrevisao(portal)
46    customizeBaseProperties(portal)
47
48def setupControlPanel(portal):
49    portal.portal_controlpanel.registerConfiglet(**AJUDA_configlet)
50
51def setupWorkflow(portal):
52    portal_workflow = getToolByName(portal, 'portal_workflow')
53    portal_workflow.setDefaultChain('portal_modelo_workflow')
54    portal_workflow.setChainForPortalTypes( ['CalendarX', 'ATAudio', 'Recordings', 'ATPhoto', 'ATVideo', 'ATAudioFolder', 'ATPhotoAlbum'], "plone_workflow")
55
56def setupTING(portal):
57    portal_catalog = getToolByName(portal, 'portal_catalog')
58    indexes = portal_catalog.getIndexObjects()
59
60    try:
61        portal_catalog.manage_delIndex('SearchableText')
62    except:
63        pass
64
65    encoding = portal.portal_properties.site_properties.default_charset
66    portal_catalog.manage_addIndex('SearchableText', 'TextIndexNG2', extra={'default_encoding' : encoding})
67    portal_catalog.manage_reindexIndex('SearchableText', portal.REQUEST)
68
69def setupIndex(portal):
70    front_page = getattr(portal, 'front-page', None)
71    if front_page is not None:
72        portal._delObject('front-page')
73        portal.manage_changeProperties(default_page='pagina-inicial')
74
75def addTaxonomy(portal):
76    createTaxonomy(portal)
77
78def addOuvidoria(portal):
79    # Configurando lista de opções
80    omb_tool = getToolByName(portal, 'portal_ombudsman')
81    omb_tool.setVocab_sex( ['1;Feminino','2;Masculino'] )
82    omb_tool.setVocab_region( ['AC;Acre','AL;Alagoas','AP;Amapá','AM;Amazonas','BA;Bahia','CE;Ceará',\
83                               'DF;Distrito Federal','ES;Espírito Santo','GO;Goiás','MA;Maranhão',\
84                               'MT;Mato Grosso','MS;Mato Grosso do Sul','MG;Minas Gerais','PA;Pará',\
85                               'PB;Paraíba','PR;Paraná','PE;Pernambuco','PI;Piauí','RJ;Rio de Janeiro',\
86                               'RN;Rio Grande do Norte','RS;Rio Grande do Sul','RO;Rondônia',\
87                               'RR;Roraima','SC;Santa Catarina','SP;São Paulo','SE;Sergipe','TO;Tocantins'] )
88    omb_tool.setVocab_age( ['1;Menos que 15','2;Entre 16 e 20','3;Entre 21 e 30','4;Entre 31 e 40',\
89                            '5;Entre 41 e 50','6;Entre 51 e 60','7;Entre 61 e 70','8;Acima de 71'] )
90    ouvidoria = getattr(portal, 'ouvidoria', None)
91    if ouvidoria is None:
92        portal.invokeFactory('Ombudsman', id='ouvidoria', title='Ouvidoria')
93
94def setupPortal(portal):
95    portal.manage_changeProperties(title='Portal das Casas Legislativas',
96                                   email_from_address='admin-stc@interlegis.gov.br',
97                                   email_from_name= 'Administrador')
98
99def setupSlots(portal):
100    left_slots =  ('here/portlet_navigation/macros/portlet', \
101                   'here/portlet_preferencias/macros/portlet', \
102                   'here/portlet_gazette/macros/portlet', \
103                   'here/sin_tool/macros/Interlegis', \
104                   'here/portlet_recent/macros/portlet',)
105    portal._setPropValue('left_slots', left_slots)
106    right_slots = ('here/portlet_calendar/macros/portlet', \
107                   'here/popoll_slot2/macros/popollBox', \
108                   'here/portlet_review/macros/portlet', \
109                   'here/portlet_utilidades/macros/portlet', \
110                   'here/portlet_previsao/macros/portlet',)
111    portal._setPropValue('right_slots', right_slots)
112
113def deleteAction(portal):
114    portal_actions = getToolByName(portal, 'portal_actions')
115    idx = 0
116    for action in portal_actions.listActions():
117        if action.getId() == 'index_html':
118            portal_actions.deleteActions((idx,))
119            break
120        idx += 1
121
122def deleteAction2(portal):
123    portal_actions = getToolByName(portal, 'portal_actions')
124    idx = 0
125    for action in portal_actions.listActions():
126        if action.getId() == 'sitemap':
127            portal_actions.deleteActions((idx,))
128            break
129        idx += 1
130
131def deleteAction3(portal):
132    portal_actions = getToolByName(portal, 'portal_actions')
133    idx = 0
134    for action in portal_actions.listActions():
135        if action.getId() == 'contact':
136            portal_actions.deleteActions((idx,))
137            break
138        idx += 1
139
140def deleteAction4(portal):
141    portal_actions = getToolByName(portal, 'portal_actions')
142    idx = 0
143    for action in portal_actions.listActions():
144        if action.getId() == 'plone_setup':
145            portal_actions.deleteActions((idx,))
146            break
147        idx += 1
148
149def deleteCategoria(portal):
150    portal_actions = getToolByName(portal, 'portal_actions')
151    idx = 0
152    for actions in portal_actions.listActions():
153        if actions.getCategory() == 'site_actions':
154            portal_actions.deleteActions((idx,))
155            break
156        idx += 1
157
158def setupActions(portal):
159    portal_actions = getToolByName(portal, 'portal_actions')
160    portal_actions.addAction(id='index_html', name='Página Inicial', action='string:$portal_url', condition='', permission='View', category='portal_tabs', visible=1)
161
162    portal_actions.addAction(id='ouvidoria', name='Ouvidoria', action='string:${portal_url}/ouvidoria', condition='', permission='View', category='portal_tabs', visible=1)
163
164    portal_actions.addAction(id='saap', name='SAAP', action='string: ${portal_url}/saap', condition='member', permission='View', category='portal_tabs', visible=1)
165
166    portal_actions.addAction(id='saal', name='SAAL', action='string: ${portal_url}/saal', condition='member', permission='View', category='portal_tabs', visible=0)
167 
168    portal_actions.addAction(id='contact', name='Fale com a Câmara', action='string: ${portal_url}/contact-info', condition='', permission='View', category='portal_tabs', visible=1)
169
170    portal_actions.addAction(id='sitemap', name='Site Map', action='string: ${portal_url}/sitemap', condition='', permission='View', category='portal_tabs', visible=1)
171
172    portal_actions.addAction(id='login_form', name='Acessar', action='string: ${portal_url}/login_form', condition='python:here.portal_membership.isAnonymousUser()', permission='View', category='portal_tabs', visible=1)
173
174def setupCss(portal):
175    css = getToolByName(portal, 'portal_css')
176    css.manage_addStylesheet(id='portalCasas.css', media='all', enabled=True)
177
178def setupCssmanager(portal):
179    cssmanager = getToolByName(portal, 'portal_cssmanager')
180    cssmanager.manage_addToMapping('base_properties','Plone Css')
181
182def setupFactory(portal):
183    portal_factory = getToolByName(portal, 'portal_factory')
184    portal_factory.manage_setPortalFactoryTypes(listOfTypeIds=['Conta', 'Document', 'Event', 'File', 'Folder', 'Image', 'Link', 'News Item', 'Ombudsman', 'OmbudsmanClaim', 'OmbudsmanResponse', 'PrestacaoContas', 'DespesaPessoal', 'DisponibilidadeCaixa', 'Limites', 'RestosPagar', 'Previsao', 'Topic', 'Window', 'Newsletter', 'NewsletterBTree', 'NewsletterReference', 'NewsletterTheme', 'NewsletterTopic', 'Ploneboard', 'PloneboardComment', 'PloneboardConversation', 'PloneboardForum', 'Recordings', 'Subscriber', 'Section', 'ATVideo', 'ATPhotoAlbum', 'ATPhoto', 'ATMediaFile', 'ATAudioFolder', 'ATAudio'])
185
186def setupMembership(portal):
187    portal_membership = getToolByName(portal, 'portal_membership')
188    portal_membership.setMemberareaCreationFlag()
189
190def setupGroups(portal):
191    portal_groups = getToolByName(portal, 'portal_groups')
192    portal_groups.toggleGroupWorkspacesCreation()
193
194def setupLanguages(portal):
195    languages = getToolByName(portal, 'portal_languages')
196    defaultLanguage = 'pt-br'
197    supportedLanguages = ['pt-br']
198    languages.manage_setLanguageSettings(defaultLanguage, supportedLanguages,
199                                         setCookieN=True, setRequestN=False,
200                                         setPathN=True, setForcelanguageUrls=True,
201                                         setAllowContentLanguageFallback=False,
202                                         setUseCombinedLanguageCodes=True,
203                                         startNeutral=True, displayFlags=False)
204
205def setupScripts(portal):
206    scripts = getattr(portal, 'scripts', None)
207    if scripts is None:
208        portal.manage_addProduct['OFSP'].manage_addFolder('scripts')
209        scripts = getattr(portal, 'scripts', None)
210        scripts.manage_addProduct['ExternalMethod'].manage_addExternalMethod('backupFile','Backup zope.conf e products', PROJECTNAME+'.BackupPortalModelo', 'backupFile')
211        scripts.manage_addProduct['ExternalMethod'].manage_addExternalMethod('packDB','Pack Data.fs', PROJECTNAME+'.BackupPortalModelo', 'packDB')
212        scripts.manage_addProduct['ExternalMethod'].manage_addExternalMethod('moveBackup','Move Data.fs para iretorio backup', PROJECTNAME+'.BackupPortalModelo', 'moveBackup')
213        scripts.manage_addProduct['PythonScripts'].manage_addPythonScript('atualizaPrevisao')
214        scripts['atualizaPrevisao'].ZPythonScript_edit('', 'context.portal_previsao.generatePrevisao()')
215
216def installPrevisao(portal):
217    tool_previsao = getToolByName(portal, 'portal_previsao')
218    #gerando a primeira previsao
219    tool_previsao.setUsePrevisao(1);
220    tool_previsao.setURLPrevisao('http://reia.inmet.gov.br/prev_clima_tempo/dbHTMLCapreCid_B.php?cidade=BRASILIA&uf=DF&microreg=BRASILIA')
221    tool_previsao.generatePrevisao()
222
223def setupMetadata(portal):
224    portal_metadata = getToolByName(portal, 'portal_metadata')
225    portal_metadata.updateElementPolicy(
226            element='Subject',
227            content_type='Event',
228            is_required=0,
229            supply_default=0,
230            default_value='',
231            enforce_vocabulary=0,
232            allowed_vocabulary=('Encontro', 'Convenção', 'Reunião', 'Evento Social', 'Trabalho'))
233
234def setupProperties(portal):
235    portal_properties = getToolByName(portal, 'portal_properties')
236    portal_properties.site_properties.allowAnonymousViewAbout = (False)
237    portal_properties.site_properties.default_language = 'pt-br'
238    portal_properties.site_properties.localTimeFormat = '%d/%m/%Y'
239    portal_properties.site_properties.localLongTimeFormat = '%d/%m/%Y %H:%M'
240    portal_properties.site_properties.disable_folder_sections = (True)
241    portal_properties.navtree_properties.includeTop = (False)
242    portal_properties.navtree_properties.idsNotToList = ('Members','portal_ombudsman', 'portal_previsao', 'ouvidoria', 'portal_windowZ', 'news', 'events',)
243    portal_properties.navtree_properties.metaTypesNotToList = ('ATImage', 'ATFile', 'ATEvent', 'ATLink', 'ATNewsItem', 'OmbudsmanClaim', 'OmbudsmanResponse', 'Conta', 'ATPhoto',)
244
245def setupPublicatorUtilidades(portal):
246    portal_url = getToolByName(portal, 'portal_url')
247    url = portal_url(relative_to_portal=1)
248    plone_id = portal_url.getPortalObject().getId()
249    items_utilidades = [{'RemoteUrl':'http://www.interlegis.gov.br', 'Description':'Programa Interlegis', 'Title':'Programa Interlegis', 'NewWindow':'on', 'RelativeURL':'/'+plone_id+'/utilidades/link-interlegis', 'RelativeContentURL':'utilidades/link-interlegis', 'Id':'link-interlegis'}, {'RemoteUrl':'http://www.senado.gov.br', 'Description':'Senado Federal', 'Title':'Senado Federal', 'NewWindow':'on', 'RelativeURL':'/'+plone_id+'/utilidades/link-senado', 'RelativeContentURL':'utilidades/link-senado', 'Id':'link-senado'}, {'RemoteUrl':'http://www.camara.gov.br', 'Description':'Câmara dos Deputados', 'Title':'Câmara dos Deputados', 'NewWindow':'on', 'RelativeURL':'/'+plone_id+'/utilidades/link-camara', 'RelativeContentURL':'utilidades/link-camara', 'Id':'link-camara'}]
250    portal_publicator = getToolByName(portal, 'portal_publicator')   
251    portal_publicator.addPublicationBox(id='links_utilidades',
252                           name='Utilidades',
253                           content_type=['Link'],
254                           n_items=5,
255                           search_states=['published'],
256                           items=items_utilidades)
257
258def setupPublicatorDestaque(portal):
259    portal_publicator = getToolByName(portal, 'portal_publicator')
260    portal_publicator.addPublicationBox(id='destaque',
261                           name='Notícia Destaque',
262                           content_type=['News Item'],
263                           n_items=1,
264                           search_states=['published'])
265
266def setupPublicatorNoticia(portal):
267    portal_publicator = getToolByName(portal, 'portal_publicator')
268    portal_publicator.addPublicationBox(id='noticia',
269                           name='Últimas Notícias',
270                           search_states=['published'],
271                           content_type=['News Item'],
272                           n_items=5)
273
274def setupPublicatorBanner(portal):
275    portal_url = getToolByName(portal, 'portal_url')
276    url = portal_url(relative_to_portal=1)
277    plone_id = portal_url.getPortalObject().getId()
278    items_banners = [{'Description':'Senado Federal', 'Title':'Senado Federal', 'RemoteUrl':'http://www.senado.gov.br', 'RelativeContentURL':'utilidades/link-senado', 'ImageURL':'imagens/banners/banner_senado.jpg', 'NewWindow': 'on', 'RelativeURL':'/'+plone_id+'/utilidades/link-senado', 'Id':'link-senado'}, {'Description':'Programa Interlegis', 'Title':'Programa Interlegis', 'RemoteUrl':'http://www.interlegis.gov.br', 'RelativeContentURL':'utilidades/link-interlegis', 'ImageURL':'imagens/banners/banner_interlegis.jpg', 'RemoteURL':'http://www.camara.gov.br', 'NewWindow': 'on', 'RelativeURL':'/'+plone_id+'/utilidades/link-interlegis', 'Id':'link-interlegis'}, {'Description':'Câmara dos Deputados', 'Title':'Câmara dos Deputados', 'RemoteUrl':'http://www.camara.gov.br', 'RelativeContentURL':'utilidades/link-camara', 'ImageURL':'imagens/banners/banner_camara.jpg', 'NewWindow': 'on', 'RelativeURL':'/'+plone_id+'/utilidades/link-camara', 'Id':'link-camara'}]
279    portal_publicator = getToolByName(portal, 'portal_publicator')
280    portal_publicator.addPublicationBox(id='banners',
281                           name='Banners',
282                           content_type=['Link'],
283                           n_items=5,
284                           search_states=['published'],
285                           with_image=1,
286                           images_folder='imagens/banners',
287                           image_states=['published'],
288                           items=items_banners)
289
290def setupRSS(portal):
291    rss = getToolByName(portal, 'portal_syndication')
292    idx = 0
293    for action in rss.listActions():
294        if action.getId() == 'syndication':
295            rss.deleteActions((idx,))
296            break
297        idx += 1
298
299    rss.addAction('syndication', 'Syndication', 'string:${folder_url}/synPropertiesForm', 'python: folder is object and portal.portal_syndication.isSiteSyndicationAllowed()', 'Manage Properties', 'object', 1)
300    rss.editProperties(isAllowed=1)
301
302    noticias = getattr(portal, 'noticias', None)
303    if noticias.portal_syndication.isSiteSyndicationAllowed():
304        noticias.portal_syndication.enableSyndication(noticias)
305
306def setupSin(portal):
307    sin_tool = getToolByName(portal, 'sin_tool')
308    sin_tool.manage_configSin(submit='Set Config', config=ARQUIVO)   
309
310def setupSkin(portal):
311    portal_skins = getToolByName(portal, 'portal_skins')
312    path = portal_skins.getSkinPath('Plone Default')
313    path = [elem.strip() for elem in path.split(',') if elem != '.svn']
314    path = ','.join(path)
315    portal_skins.addSkinSelection('Portal Casas', path)
316    portal_skins.manage_properties(default_skin = 'Portal Casas',
317                                   request_varname = 'plone_skin',
318                                   del_skin = 0,
319                                   chosen = [] )
320
321def setupTipo(portal):
322    portal_types = getToolByName(portal, 'portal_types')
323    portal_types['Plone Site'].global_allow = False
324    addable_types=['Folder', 'Ombudsman', 'Document']
325    portal_types['Plone Site'].filter_content_types = True
326    portal_types['Plone Site'].allowed_content_types = addable_types
327
328def addBackup(portal):
329    DIR = INSTANCE_HOME
330    BACKUP = INSTANCE_HOME+'/backup'
331    if os.path.exists(BACKUP):
332        pass
333    else:
334        os.system('mkdir %s/backup' % DIR)
335
336def addScheduler(portal):
337    zope_scheduler = getattr(portal, 'zope_scheduler', None)
338    if zope_scheduler is None:
339        portal.manage_addProduct['ZopeScheduler'].manage_addZopeScheduler()
340        zope_scheduler = getattr(portal, 'zope_scheduler', None)
341        zope_scheduler.manage_addTask('scripts/packDB', ('0',), ('22',), [None], [1,3,5], (None))
342        zope_scheduler.manage_addTask('scripts/moveBackup', ('00',), ('23',), [None], [1,3,5], (None))
343        zope_scheduler.manage_addTask('scripts/backupFile', ('20',), ('23',), [None], [1,3,5], (None))
344        zope_scheduler.manage_addTask('scripts/atualizaPrevisao', ('0',), ('1','7','13','19',), [None], [None], (None))
345
346def customizeBaseProperties(portal):
347    skins_tool = getToolByName(portal, 'portal_skins')
348    skin_folder = getattr(skins_tool, 'ILPortalCasas_public')
349    base_prop = getattr(skin_folder, 'base_properties')
350    custom_folder = getattr(skins_tool, 'custom')
351    if base_prop.getId() not in custom_folder.objectIds():
352        base_prop.manage_doCustomize('custom')
353   
354
355
356def uninstall(self):
357    portal = self
358    # the ids of the objects to keep
359    locked_ids = ('historia', 'camara', 'agenda', 'processos-legislativos', 'leis', 'legislacao', 'prestacao-contas', \
360                  'licitacoes', 'editais', 'contabilidade', 'utilidades', 'imagens', 'enquetes', 'newsletters', \
361                  'foruns', 'noticias', 'eventos', 'saap', 'saal', 'scripts_backup', 'zope_scheduler', 'ouvidoria')
362    po = self.portal_quickinstaller.ILPortalCasas.portalobjects
363    for id in locked_ids:
364        if id in po:
365            po.remove(id)
366
367
368    portal._delObject('portal_previsao')
369
370
371    rss = getToolByName(portal, 'portal_syndication')
372    idx = 0
373    for action in rss.listActions():
374        if action.getId() == 'syndication':
375            rss.deleteActions((idx,))
376            break
377        idx += 1
378    noticias = getattr(portal, 'noticias', None)
379    if noticias.portal_syndication.isSiteSyndicationAllowed():
380        noticias.portal_syndication.disableSyndication(noticias)
381
382
383    portal_controlpanel = getToolByName(portal,'portal_controlpanel')
384    portal_controlpanel.unregisterConfiglet('ajuda_portal_casas')
385    portal_controlpanel.unregisterConfiglet(PREVISAO_configlet['id'])
386
387
388    portal_types = getToolByName(portal, 'portal_types')
389    portal_types['Plone Site'].global_allow = True
390    portal_types['Plone Site'].filter_content_types = False
391
392
393    portal_publicator = getToolByName(portal, 'portal_publicator')
394    portal_publicator.deletePublicationBoxes(['banners', 'links_utilidades', 'destaque', 'noticia'])
395
396    events = getattr(portal, 'eventos', None)
397    addable_types = ['Event', 'Topic']
398    if getattr(events.aq_base, 'setConstrainTypesMode', None) is not None:
399        events.setConstrainTypesMode(1)
400        events.setImmediatelyAddableTypes(addable_types)
401        events.setLocallyAllowedTypes(addable_types)
402
403    news = getattr(portal, 'noticias', None)
404    addable_types = ['News Item', 'Topic']
405    if getattr(events.aq_base, 'setConstrainTypesMode', None) is not None:
406        news.setConstrainTypesMode(1)
407        news.setImmediatelyAddableTypes(addable_types)
408        news.setLocallyAllowedTypes(addable_types)
Note: Veja TracBrowser para ajuda no uso do navegador do trac.
 

The contents and data of this website are published under license:
Creative Commons 4.0 Brasil - Atribuir Fonte - Compartilhar Igual.