Skip to content

Commit

Permalink
Added function utils.addFacetedCriteria to ease applying a faceted co…
Browse files Browse the repository at this point in the history
…nf xml that adds extra faceted criteria to an existing dashboard.
  • Loading branch information
gbastien committed May 21, 2019
1 parent 66520fa commit 0f6938d
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 14 deletions.
5 changes: 3 additions & 2 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@ Changelog
0.9 (unreleased)
----------------

- Nothing changed yet.

- Added function utils.addFacetedCriteria to ease applying a faceted conf xml
that adds extra faceted criteria to an existing dashboard.
[gbastien]

0.8 (2019-05-16)
----------------
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?xml version="1.0" encoding="UTF-8"?>
<object name="searches" meta_type="ATFolder"
xmlns:i18n="http://xml.zope.org/namespaces/i18n"
i18n:domain="eea">
<criteria>

<criterion name="c50" i18n:attributes="title">
<property name="widget">text</property>
<property name="title">Search title</property>
<property name="position">center</property>
<property name="section">default</property>
<property name="hidden">False</property>
<property name="index">Title</property>
<property name="default"/>
<property name="onlyallelements">True</property>
<property name="wildcard">True</property>
</criterion>

</criteria>
</object>
22 changes: 15 additions & 7 deletions src/collective/eeafaceted/dashboard/tests/test_utils.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
# -*- coding: utf-8 -*-
import os
from eea.facetednavigation.interfaces import ICriteria
from eea.facetednavigation.interfaces import IFacetedLayout
from eea.facetednavigation.interfaces import IFacetedNavigable
from eea.facetednavigation.interfaces import IHidePloneLeftColumn

from collective.eeafaceted.collectionwidget.interfaces import NoFacetedViewDefinedException

from collective.eeafaceted.dashboard.testing import IntegrationTestCase
from collective.eeafaceted.dashboard.utils import addFacetedCriteria
from collective.eeafaceted.dashboard.utils import enableFacetedDashboardFor
from collective.eeafaceted.dashboard.utils import getCriterionByTitle
from collective.eeafaceted.dashboard.utils import getCriterionByIndex
from collective.eeafaceted.dashboard.utils import getCriterionByTitle
from eea.facetednavigation.interfaces import ICriteria
from eea.facetednavigation.interfaces import IFacetedLayout
from eea.facetednavigation.interfaces import IFacetedNavigable
from eea.facetednavigation.interfaces import IHidePloneLeftColumn

import os


class TestUtils(IntegrationTestCase):
Expand Down Expand Up @@ -60,6 +61,13 @@ def test_enableFacetedDashboardFor(self):
self.assertEquals(len(ICriteria(folder3).criteria), 1)
self.assertTrue(ICriteria(folder3).get('c44'))

def test_addFacetedCriteria(self):
""" """
self.assertFalse(ICriteria(self.folder).get('c50'))
xmlpath = os.path.dirname(__file__) + '/faceted_conf/extra_testing_widgets.xml'
addFacetedCriteria(self.folder, xmlpath)
self.assertTrue(ICriteria(self.folder).get('c50'))

def test_getCriterionByTitle(self):
"""Test method returning criteria matching a given title."""
sort_criterion = getCriterionByTitle(self.folder, 'Sort on')
Expand Down
26 changes: 21 additions & 5 deletions src/collective/eeafaceted/dashboard/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,25 @@ def enableFacetedDashboardFor(obj, xmlpath=None, show_left_column=True, default_
obj.REQUEST.set('enablingFacetedDashboard', False)


def _enableFacetedDashboardFor(obj, xmlpath=None, show_left_column=True, default_UID=None):
def addFacetedCriteria(obj, xmlpath):
"""Helper to add extra faceted criteria to an already faceted enabled dashboard."""
_enableFacetedDashboardFor(obj,
xmlpath,
show_left_column=False,
enable_faceted=False,
update_layout=False)


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 IFacetedNavigable.providedBy(obj):
if enable_faceted and IFacetedNavigable.providedBy(obj):
logger.error("Faceted navigation is already enabled for '%s'" %
'/'.join(obj.getPhysicalPath()))
return
Expand All @@ -40,10 +54,12 @@ def _enableFacetedDashboardFor(obj, xmlpath=None, show_left_column=True, default
# we cancel this, safe previous RESPONSE status and location
response_status = obj.REQUEST.RESPONSE.getStatus()
response_location = obj.REQUEST.RESPONSE.getHeader('location')
obj.unrestrictedTraverse('@@faceted_subtyper').enable()
if enable_faceted:
obj.unrestrictedTraverse('@@faceted_subtyper').enable()

# use correct layout in the faceted
IFacetedLayout(obj).update_layout('faceted-table-items')
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)
Expand Down

0 comments on commit 0f6938d

Please sign in to comment.