def _update(self, portal): portal_properties = portal.getPropertiesTool() global_subobjects = set(portal.adt_meta_types) all_nyfolders = ofs_walk(portal, [INyFolder], [IFolder]) patched = 0 customized = 0 for nyfolder in all_nyfolders: if global_subobjects != set(nyfolder.folder_meta_types): # subobjects are different, they were prev. modified # keep the folder_meta_types list as it is customized += 1 else: # same with global, mark it with `Uses default` (None) fmt = FolderMetaTypes(nyfolder) fmt.set_values(None) patched += 1 self.log.info(("%d folders now use default subobjects setting, " "%d folders have subobject customizations") % (patched, customized)) if not add_admin_entry(self, portal, ("""<li tal:condition="canPublish"><a """ """tal:attributes="href string:${site_url}/""" """admin_folder_subobjects_html" title""" """="Portal comments" i18n:attributes="title" """ """i18n:translate="">Folder subobjects</a></li>"""), '${site_url}/admin_maintopics_html"'): self.log.error("MANUAL action: Insert link html in admin portlet") return False else: return True return True
def update_subobjects(self, portal): """ Update allowed subobject in Naaya Folders if Naaya Extended File is present in this list Required arguments: portal -- Naaya Site instance """ # Subobjects meta_types = portal.adt_meta_types[:] changed = False if 'Naaya Extended File' in meta_types: meta_types.remove('Naaya Extended File') changed = True if 'Naaya Blob File' not in meta_types: meta_types.append('Naaya Blob File') changed = True if changed: self.log.debug('Updating portal %s subobjects = %s', portal.absolute_url(1), meta_types) portal.portal_properties.manageSubobjects(subobjects=meta_types) brains = portal.portal_catalog(meta_type='Naaya Folder') for brain in brains: doc = brain.getObject() if not doc: continue self.log.debug("Replacing object %s", doc.absolute_url()) folder_meta_types = FolderMetaTypes(doc) meta_types = folder_meta_types.get_values() changed = False if 'Naaya Extended File' in meta_types: meta_types.remove('Naaya Extended File') changed = True if 'Naaya Blob File' not in meta_types: meta_types.append('Naaya Blob File') changed = True if changed: self.log.debug('Updating folder %s subobjects = %s', doc.absolute_url(1), meta_types) folder_meta_types.set_values(meta_types)
def update_subobjects(self, portal): """ Update allowed subobject in Naaya Folders if Naaya Extended File is present in this list Required arguments: portal -- Naaya Site instance """ # Subobjects meta_types = portal.adt_meta_types[:] changed = False if 'Naaya Extended File' in meta_types: meta_types.remove('Naaya Extended File') changed = True if 'Naaya Blob File' not in meta_types: meta_types.append('Naaya Blob File') changed = True if changed: self.log.debug('Updating portal %s subobjects = %s', portal.absolute_url(1), meta_types) portal.portal_properties.manageSubobjects(subobjects=meta_types) brains = portal.portal_catalog(meta_type='Naaya Folder') for brain in brains: doc = brain.getObject() if not doc: continue self.log.debug("Replacing object %s", doc.absolute_url()) folder_meta_types = FolderMetaTypes(doc) meta_types = folder_meta_types.get_values() changed = False if 'Naaya Extended File' in meta_types: meta_types.remove('Naaya Extended File') changed = True if 'Naaya Blob File' not in meta_types: meta_types.append('Naaya Blob File') changed = True if changed: self.log.debug('Updating folder %s subobjects = %s', doc.absolute_url(1), meta_types) folder_meta_types.set_values(meta_types)
def _update(self, portal): portal_properties = portal.getPropertiesTool() global_subobjects = set(portal.adt_meta_types) all_nyfolders = ofs_walk(portal, [INyFolder], [IFolder]) patched = 0 customized = 0 for nyfolder in all_nyfolders: if global_subobjects != set(nyfolder.folder_meta_types): # subobjects are different, they were prev. modified # keep the folder_meta_types list as it is customized += 1 else: # same with global, mark it with `Uses default` (None) fmt = FolderMetaTypes(nyfolder) fmt.set_values(None) patched += 1 self.log.info( ("%d folders now use default subobjects setting, " "%d folders have subobject customizations") % (patched, customized) ) if not add_admin_entry( self, portal, ( """<li tal:condition="canPublish"><a """ """tal:attributes="href string:${site_url}/""" """admin_folder_subobjects_html" title""" """="Portal comments" i18n:attributes="title" """ """i18n:translate="">Folder subobjects</a></li>""" ), '${site_url}/admin_maintopics_html"', ): self.log.error("MANUAL action: Insert link html in admin portlet") return False else: return True return True
def addNyInfoFolder(self, id='', REQUEST=None, contributor=None, **kwargs): """ Create an infofolder type of object. """ #process parameters if REQUEST is not None: schema_raw_data = dict(REQUEST.form) else: schema_raw_data = kwargs _lang = schema_raw_data.pop('_lang', schema_raw_data.pop('lang', None)) _folder_meta_types = schema_raw_data.pop('folder_meta_types', '') id = make_id(self, id=id, title=schema_raw_data.get('title', ''), prefix='infofolder') if contributor is None: contributor = self.REQUEST.AUTHENTICATED_USER.getUserName() ob = _create_NyInfoFolder_object(self, id, contributor) ob.info_type = 'enterprises' ob.set_categories() _releasedate = DateTime() form_errors = ob.process_submitted_form(schema_raw_data, _lang, _override_releasedate=_releasedate) if form_errors: if REQUEST is None: raise ValueError(form_errors.popitem()[1]) # pick a random error else: import transaction transaction.abort( ) # because we already called _crete_NyZzz_object ob._prepare_error_response(REQUEST, form_errors, schema_raw_data) return REQUEST.RESPONSE.redirect('%s/infofolder_add_html' % self.absolute_url()) return site = self.getSite() #extra settings ob_meta_types = FolderMetaTypes(ob) parent_meta_types = FolderMetaTypes(self) if _folder_meta_types == '': #inherit allowd meta types from the parent if self.meta_type == site.meta_type: ob_meta_types.set_values(site.adt_meta_types) else: if not parent_meta_types.has_custom_value: # if parent uses defaults, so should `ob` ob_meta_types.set_values(None) else: ob_meta_types.set_values(parent_meta_types.get_values()) else: ob_meta_types.set_values(self.utConvertToList(_folder_meta_types)) if self.glCheckPermissionPublishObjects(): approved, approved_by = 1, self.REQUEST.AUTHENTICATED_USER.getUserName( ) else: approved, approved_by = 0, None ob.approveThis(approved, approved_by) ob.submitThis() #Process extra fields (categories, extra_properties) if ob.discussion: ob.open_for_comments() self.recatalogNyObject(ob) notify(NyContentObjectAddEvent(ob, contributor, schema_raw_data)) #log post date auth_tool = self.getAuthenticationTool() auth_tool.changeLastPost(contributor) #redirect if case if REQUEST is not None: #l_referer = REQUEST['HTTP_REFERER'].split('/')[-1] #if l_referer == 'infofolder_manage_add' or l_referer.find('infofolder_manage_add') != -1: #return self.manage_main(self, REQUEST, update_menu=1) #elif l_referer == 'infofolder_add_html': #self.setSession('referer', self.absolute_url()) #return ob.object_submitted_message(REQUEST) #REQUEST.RESPONSE.redirect('%s/messages_html' % self.absolute_url()) REQUEST.RESPONSE.redirect('%s/%s/edit_html' % (self.absolute_url(), id)) return ob.getId()
def loadDefaultData(self): """ """ #set default 'Naaya' configuration NySite.__dict__['createPortalTools'](self) NySite.__dict__['loadDefaultData'](self) #remove Naaya default content layout_tool = self.getLayoutTool() naaya_skins = [skin.getId() for skin in layout_tool.objectValues('Naaya Skin')] logos = [image.getId() for image in layout_tool.objectValues('Image')] layout_tool.manage_delObjects(naaya_skins + logos) self.manage_delObjects('info') #load site skeleton - configuration self.loadSkeleton(ENVIROWINDOWS_PRODUCT_PATH) #custom indexes try: self.getCatalogTool().manage_addIndex('resource_area', 'TextIndexNG2', extra={'default_encoding': 'utf-8', 'splitter_single_chars': 1}) except: pass try: self.getCatalogTool().manage_addIndex('resource_focus', 'TextIndexNG2', extra={'default_encoding': 'utf-8', 'splitter_single_chars': 1}) except: pass try: self.getCatalogTool().manage_addIndex('resource_area_exp', 'TextIndexNG2', extra={'default_encoding': 'utf-8', 'splitter_single_chars': 1}) except: pass try: self.getCatalogTool().manage_addIndex('resource_focus_exp', 'TextIndexNG2', extra={'default_encoding': 'utf-8', 'splitter_single_chars': 1}) except: pass try: self.getCatalogTool().manage_addIndex('resource_country', 'TextIndexNG2', extra={'default_encoding': 'utf-8', 'splitter_single_chars': 1}) except: pass #default RDF Calendar settings manage_addRDFCalendar(self, id=ID_RDFCALENDAR, title=TITLE_RDFCALENDAR, week_day_len=1) rdfcalendar_ob = self._getOb(ID_RDFCALENDAR) #adding local_events Script (Python) manage_addPythonScript(rdfcalendar_ob, 'local_events') local_events_ob = rdfcalendar_ob._getOb('local_events') local_events_ob._params = 'year=None, month=None, day=None' local_events_ob.write(open(os.path.dirname(__file__) + '/skel/others/local_events.py', 'r').read()) #Adding custom SchemaTool properties schema_tool = self.getSchemaTool() naaya_folder_schema = schema_tool.getSchemaForMetatype(METATYPE_FOLDER) widget_args = dict( label='Allow users enrolment here?', data_type='bool', widget_type='Checkbox', localized=True, ) naaya_folder_schema.addWidget('show_contributor_request_role', **widget_args) naaya_consultation_schema = schema_tool.getSchemaForMetatype( 'Naaya Consultation') if naaya_consultation_schema: naaya_consultation_schema.addWidget('show_contributor_request_role', **widget_args) naaya_simple_consultation_schema = schema_tool.getSchemaForMetatype( 'Naaya Simple Consultation') if naaya_simple_consultation_schema: naaya_simple_consultation_schema.addWidget( 'show_contributor_request_role', **widget_args) #add survey tool try: from Products.NaayaSurvey.SurveyTool import manage_addSurveyTool manage_addSurveyTool(self) except: pass self._install_link_checker() addNyFolder(self, id='events', title='Events', publicinterface=1) folder_meta_types = FolderMetaTypes(self._getOb('events')) folder_meta_types.set_values(['Naaya Event']) event_folder_custom_index = ( "<metal:block use-macro=\"python:here.getFormsTool()." "getForm('event_folder_index').macros['page']\" />") self['events']['index'].pt_edit(text=event_folder_custom_index, content_type='')
def addNyInfoFolder(self, id='', REQUEST=None, contributor=None, **kwargs): """ Create an infofolder type of object. """ #process parameters if REQUEST is not None: schema_raw_data = dict(REQUEST.form) else: schema_raw_data = kwargs _lang = schema_raw_data.pop('_lang', schema_raw_data.pop('lang', None)) _folder_meta_types = schema_raw_data.pop('folder_meta_types', '') id = make_id(self, id=id, title=schema_raw_data.get('title', ''), prefix='infofolder') if contributor is None: contributor = self.REQUEST.AUTHENTICATED_USER.getUserName() ob = _create_NyInfoFolder_object(self, id, contributor) ob.info_type = 'enterprises' ob.set_categories() _releasedate = DateTime() form_errors = ob.process_submitted_form(schema_raw_data, _lang, _override_releasedate=_releasedate) if form_errors: if REQUEST is None: raise ValueError(form_errors.popitem()[1]) # pick a random error else: import transaction; transaction.abort() # because we already called _crete_NyZzz_object ob._prepare_error_response(REQUEST, form_errors, schema_raw_data) return REQUEST.RESPONSE.redirect('%s/infofolder_add_html' % self.absolute_url()) return site = self.getSite() #extra settings ob_meta_types = FolderMetaTypes(ob) parent_meta_types = FolderMetaTypes(self) if _folder_meta_types == '': #inherit allowd meta types from the parent if self.meta_type == site.meta_type: ob_meta_types.set_values(site.adt_meta_types) else: if not parent_meta_types.has_custom_value: # if parent uses defaults, so should `ob` ob_meta_types.set_values(None) else: ob_meta_types.set_values(parent_meta_types.get_values()) else: ob_meta_types.set_values(self.utConvertToList(_folder_meta_types)) if self.glCheckPermissionPublishObjects(): approved, approved_by = 1, self.REQUEST.AUTHENTICATED_USER.getUserName() else: approved, approved_by = 0, None ob.approveThis(approved, approved_by) ob.submitThis() #Process extra fields (categories, extra_properties) if ob.discussion: ob.open_for_comments() self.recatalogNyObject(ob) notify(NyContentObjectAddEvent(ob, contributor, schema_raw_data)) #log post date auth_tool = self.getAuthenticationTool() auth_tool.changeLastPost(contributor) #redirect if case if REQUEST is not None: #l_referer = REQUEST['HTTP_REFERER'].split('/')[-1] #if l_referer == 'infofolder_manage_add' or l_referer.find('infofolder_manage_add') != -1: #return self.manage_main(self, REQUEST, update_menu=1) #elif l_referer == 'infofolder_add_html': #self.setSession('referer', self.absolute_url()) #return ob.object_submitted_message(REQUEST) #REQUEST.RESPONSE.redirect('%s/messages_html' % self.absolute_url()) REQUEST.RESPONSE.redirect('%s/%s/edit_html' % (self.absolute_url(), id)) return ob.getId()