def _facetize(item, xml_filename): """ Make an item as faceted navigation """ notify(FacetedWillBeEnabledEvent(item)) alsoProvides(item, IFacetedNavigable) if not IDisableSmartFacets.providedBy(item): alsoProvides(item, IDisableSmartFacets) if not IHidePloneLeftColumn.providedBy(item): alsoProvides(item, IHidePloneLeftColumn) if not IHidePloneRightColumn.providedBy(item): alsoProvides(item, IHidePloneRightColumn) notify(FacetedEnabledEvent(item)) import os.path fpath = os.path.join(os.path.dirname(__file__), 'faceted', xml_filename) with open(fpath) as f: xml = f.read() if not xml.startswith('<?xml version="1.0"'): raise ValueError('Please provide a valid xml file') environ = SnapshotImportContext(item, 'utf-8') importer = queryMultiAdapter((item, environ), IBody) if not importer: raise ValueError('No adapter found') importer.body = xml
def enable(self): """ See IFacetedSubtyper """ if not self.can_enable_heritor: return self._redirect('Faceted inheritance not supported') notify(FacetedWillBeEnabledEvent(self.context)) alsoProvides(self.context, IFacetedHeritor) if not IDisableSmartFacets.providedBy(self.context): alsoProvides(self.context, IDisableSmartFacets) if not IHidePloneLeftColumn.providedBy(self.context): alsoProvides(self.context, IHidePloneLeftColumn) if not IHidePloneRightColumn.providedBy(self.context): alsoProvides(self.context, IHidePloneRightColumn) notify(FacetedEnabledEvent(self.context)) self._redirect('Faceted inheritance enabled')
def enable(self): """ See IFacetedSubtyper """ if not self.can_enable: return self._redirect('Faceted navigation not supported') notify(FacetedWillBeEnabledEvent(self.context)) alsoProvides(self.context, IFacetedNavigable) if not IDisableSmartFacets.providedBy(self.context): alsoProvides(self.context, IDisableSmartFacets) if not IHidePloneLeftColumn.providedBy(self.context): alsoProvides(self.context, IHidePloneLeftColumn) if not IHidePloneRightColumn.providedBy(self.context): alsoProvides(self.context, IHidePloneRightColumn) notify(FacetedEnabledEvent(self.context)) self._redirect(_('Faceted navigation enabled'))
def test_enableFacetedDashboardFor(self): """This method will enable the faceted navigation for a given folder.""" # faceted can be enabled using the default widgets catalog = self.portal.portal_catalog folder2_id = self.portal.invokeFactory('Folder', 'folder2', title='Folder2') folder2 = getattr(self.portal, folder2_id) folder2.reindexObject() folder2UID = folder2.UID() # not enabled for now self.assertFalse(IFacetedNavigable.providedBy(folder2)) self.assertTrue(catalog(UID=folder2UID)) self.assertFalse(catalog(UID=folder2UID, object_provides=IFacetedNavigable.__identifier__)) enableFacetedDashboardFor(folder2) # several things are done : # faceted is enabled self.assertTrue(IFacetedNavigable.providedBy(folder2)) # used faceted layout is 'faceted-table-items' self.assertEquals(IFacetedLayout(folder2).layout, 'faceted-table-items') # left portlets are shown self.assertFalse(IHidePloneLeftColumn.providedBy(folder2)) # folder2 was reindexed, especially provided interfaces self.assertTrue(catalog(UID=folder2UID, object_provides=IFacetedNavigable.__identifier__)) # redirect is swallowed, indeed enabling faceted on a folder redirects to it self.assertEquals(self.portal.REQUEST.RESPONSE.status, 200) # a xmlpath parameter can be passed to use a specific widgets xml file # calling this on an already enabled faceted will do nothing xmlpath = os.path.dirname(__file__) + '/faceted_conf/testing_widgets.xml' enableFacetedDashboardFor(folder2, xmlpath=xmlpath) # only one 'c44' widget in testing_widgets.xml, not added here self.assertFalse(ICriteria(folder2).get('c44')) # create a new folder and apply faceted with xmlpath to it folder3_id = self.portal.invokeFactory('Folder', 'folder3', title='Folder3') folder3 = getattr(self.portal, folder3_id) folder3.reindexObject() # an Exception is raised if xmlpath does not exist wrong_xmlpath = os.path.dirname(__file__) + '/faceted_conf/wrong_testing_widgets.xml' self.assertRaises(Exception, enableFacetedDashboardFor, folder3, wrong_xmlpath) # apply correct xmlpath enableFacetedDashboardFor(folder3, xmlpath=xmlpath) # same things are done except that the widgets are taken from the given xmlpath self.assertEquals(len(ICriteria(folder3).criteria), 1) self.assertTrue(ICriteria(folder3).get('c44'))
def hide_portlets(context): """ As eea.design changed, we need to hide left and right plone portlets columns. This upgrade step is available only in EEA context """ ctool = getToolByName(context, 'portal_catalog') iface = interfaceToName(context, IFacetedNavigable) brains = ctool.unrestrictedSearchResults(object_provides=iface) logger.info('Hiding plone portlets for %s faceted navigable objects', len(brains)) for brain in brains: doc = brain.getObject() if not IHidePloneLeftColumn.providedBy(doc): logger.info('Hidding left portlet for %s', doc.absolute_url()) alsoProvides(doc, IHidePloneLeftColumn) if not IHidePloneRightColumn.providedBy(doc): logger.info('Hidding right portlet for %s', doc.absolute_url()) alsoProvides(doc, IHidePloneRightColumn) logger.info('Hiding plone portlets ... DONE')
def _active_faceted(self): subtyper = getMultiAdapter( (self.portal['relatorios'], self.portal['relatorios'].REQUEST), name=u'faceted_subtyper') subtyper.enable() search = getMultiAdapter( (self.portal['relatorios'], self.portal['relatorios'].REQUEST), name=u'faceted_search_subtyper') search.enable() alsoProvides(self.portal['relatorios'], IFacetedNavigable) if not IDisableSmartFacets.providedBy(self.portal['relatorios']): alsoProvides(self.portal['relatorios'], IDisableSmartFacets) if not IHidePloneLeftColumn.providedBy(self.portal['relatorios']): alsoProvides(self.portal['relatorios'], IHidePloneLeftColumn) if not IHidePloneRightColumn.providedBy(self.portal['relatorios']): alsoProvides(self.portal['relatorios'], IHidePloneRightColumn) self._open_relatorios() self.browser.getLink('Enable faceted navigation').click() self.browser.getControl(name='form.button.confirm').click() transaction.commit()
def hide_portlets(context): """ As eea.design changed, we need to hide left and right plone portlets columns. This upgrade step is available only in EEA context """ ctool = getToolByName(context, 'portal_catalog') iface = interfaceToName(context, IFacetedNavigable) brains = ctool.unrestrictedSearchResults(object_provides=iface) logger.info( 'Hiding plone portlets for %s faceted navigable objects', len(brains)) for brain in brains: doc = brain.getObject() if not IHidePloneLeftColumn.providedBy(doc): logger.info('Hidding left portlet for %s', doc.absolute_url()) alsoProvides(doc, IHidePloneLeftColumn) if not IHidePloneRightColumn.providedBy(doc): logger.info('Hidding right portlet for %s', doc.absolute_url()) alsoProvides(doc, IHidePloneRightColumn) logger.info('Hiding plone portlets ... DONE')
def _enableFacetedDashboardFor(obj, xmlpath=None, show_left_column=True, default_UID=None, enable_faceted=True, update_layout=True): """Enable a faceted view on obj and import a specific xml if given p_xmlpath.""" # already a faceted? if enable_faceted and IFacetedNavigable.providedBy(obj): logger.error("Faceted navigation is already enabled for '%s'" % '/'.join(obj.getPhysicalPath())) return # do not go further if xmlpath does not exist if xmlpath and not path.exists(xmlpath): raise Exception("Specified xml file '%s' doesn't exist" % xmlpath) # .enable() here under will redirect to enabled faceted # we cancel this, safe previous RESPONSE status and location response_status = obj.REQUEST.RESPONSE.getStatus() response_location = obj.REQUEST.RESPONSE.getHeader('location') if enable_faceted: obj.unrestrictedTraverse('@@faceted_subtyper').enable() if update_layout: # use correct layout in the faceted IFacetedLayout(obj).update_layout('faceted-table-items') # show the left portlets if show_left_column and IHidePloneLeftColumn.providedBy(obj): noLongerProvides(obj, IHidePloneLeftColumn) # import configuration if xmlpath: obj.unrestrictedTraverse('@@faceted_exportimport').import_xml( import_file=open(xmlpath)) # define default collection UID if default_UID: _updateDefaultCollectionFor(obj, default_UID) obj.reindexObject() obj.REQUEST.RESPONSE.status = response_status obj.REQUEST.RESPONSE.setHeader('location', response_location or '')
def hide_left_column(self): """ Disable plone portlets left column """ return (IHidePloneLeftColumn.providedBy(self.canonical) or IHidePloneLeftColumn.providedBy(self.context))