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

Última Alteração nesse arquivo foi 3600, incluída por jacsonsilva, 11 anos atrás

adicionado script que seta as propriedades iniciais do portlet de previo do tempo Weather forecast

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