Skip to content

Commit

Permalink
Pm 3213 utils.get_categorized_elements filters (#9)
Browse files Browse the repository at this point in the history
* Added possibility to filter displayed categorized elements on boolean attributes (to_print, publishable, confidential, to_sign/signed).
See #PM-3213

* Removed ipdb

* Renamed boolean_filters to filters, utils.get_categorized_elements filters parameter may manage any of the value stored in the categorized_elements dict

* Fixed tests

* Use same versions for setuptools and zc.buildout than one defined in .travis.yaml
Use flake8-max-complexity = 18 instead 15

* Added tests for utils.get_categorized_elements `filters` parameter

* Fixed changelog

* Test CategorizedChildInfosView.__call__, especially because parameter "filters" is json

* Use json.dumps for filters parameter

* Added a ZPublisher `:json` suffix type converter.

* isort

* Moved test for json converter to it's own package

* :json type converter was moved to imio.helpers
Rely on imio.helpers because we need the `:json` suffix type converter.

* Enable :json type converter by importing imio.helpers.converters

* Adapted buildout now that we rely on imio.helpers that depends on collective.fingerpointing

* Make code-analysis happy

* Make sure conditions are isolated in if (was working but...)
  • Loading branch information
gbastien committed Mar 17, 2021
1 parent ab45150 commit 26017d8
Show file tree
Hide file tree
Showing 29 changed files with 152 additions and 94 deletions.
7 changes: 5 additions & 2 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,11 @@ Changelog
0.49 (unreleased)
-----------------

- Nothing changed yet.

- Added possibility to filter displayed categorized elements on any attribute
of the categorized element.
[gbastien]
- Rely on imio.helpers because we need the `:json` suffix type converter.
[gbastien]

0.48 (2021-01-19)
-----------------
Expand Down
19 changes: 13 additions & 6 deletions buildout.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ parts +=
develop = .

auto-checkout =

imio.helpers

[instance]
recipe = plone.recipe.zope2instance
Expand All @@ -37,7 +37,7 @@ eggs = createcoverage
recipe = plone.recipe.codeanalysis
directory = ${buildout:directory}/src/collective
flake8-exclude = bootstrap.py,bootstrap-buildout.py,docs,*.egg.,omelette
flake8-max-complexity = 15
flake8-max-complexity = 18
flake8-max-line-length = 120
flake8-extensions =
flake8-blind-except
Expand Down Expand Up @@ -91,11 +91,12 @@ eggs = i18ndude


[remotes]
imio = https://github.com/IMIO
imio = git://github.com/IMIO
imio_push = git@github.com:IMIO


[sources]
imio.helpers = git ${remotes:imio}/imio.helpers.git pushurl=${remotes:imio_push}/imio.helpers.git


[versions]
Expand All @@ -107,6 +108,7 @@ PyYAML = 3.11
argh = 0.26.1
check-manifest = 0.31
collective.elephantvocabulary = 0.2.5
collective.fingerpointing = 1.8.2
collective.fontawesome = 1.1
collective.z3cform.select2 = 2.0.0
coverage = 3.7.1
Expand All @@ -121,16 +123,16 @@ ipython = 3.2.3
mccabe = 0.4.0
natsort = 5.5.0
pathtools = 0.1.2
plone.api = 1.4.11
plone.api = 1.10.4
plone.formwidget.querystring = 1.1.5
plone.recipe.codeanalysis = 2.2
pyflakes = 1.0.0
setuptools =
setuptools = 18.6.1
watchdog = 0.8.3
z3c.jbot = 0.7.2
z3c.json = 0.5.5
z3c.table = 2.0.1
zc.buildout = 2.10.0
zc.buildout = 2.5.3
zc.recipe.egg = 2.0.2

eea.faceted.vocabularies = 6.6
Expand All @@ -146,6 +148,11 @@ ipdb = 0.10.3
# collective.documentviewer==4.1.0
repoze.catalog = 0.8.3

# Required by:
# collective.fingerpointing
zc.lockfile = 1.2.1
file-read-backwards = 1.2.2

# Robot packages
Pygments = 2.0.2
plone.app.robotframework = 1.0.1
Expand Down
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
'collective.fontawesome>=1.1',
'collective.js.tooltipster > 0.1',
'collective.z3cform.select2',
'imio.helpers',
'natsort',
'plone.api>=1.4.11',
'plone.app.contenttypes',
Expand Down
8 changes: 6 additions & 2 deletions src/collective/iconifiedcategory/__init__.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
# -*- coding: utf-8 -*-
"""Init and utils."""
import logging

from zope.i18nmessageid import MessageFactory

# enable :json type converter
import imio.helpers.converters # noqa
import logging


logger = logging.getLogger('collective.iconifiedcategory')

CAT_SEPARATOR = '_-_'
Expand Down
2 changes: 1 addition & 1 deletion src/collective/iconifiedcategory/browser/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@

from collective.iconifiedcategory import utils
from collective.iconifiedcategory.content.category import ICategory
from collective.iconifiedcategory.event import IconifiedCategoryChangedEvent
from collective.iconifiedcategory.event import CategorizedElementsUpdatedEvent
from collective.iconifiedcategory.event import IconifiedCategoryChangedEvent
from plone import api
from Products.Five import BrowserView
from zope.event import notify
Expand Down
3 changes: 1 addition & 2 deletions src/collective/iconifiedcategory/browser/controlpanel.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,9 @@
:license: GPL, see LICENCE.txt for more details.
"""

from plone.app.registry.browser import controlpanel

from collective.iconifiedcategory import _
from collective.iconifiedcategory.interfaces import IIconifiedCategorySettings
from plone.app.registry.browser import controlpanel


class IconifiedCategorySettingsEditForm(controlpanel.RegistryEditForm):
Expand Down
3 changes: 1 addition & 2 deletions src/collective/iconifiedcategory/browser/css.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,8 @@
:license: GPL, see LICENCE.txt for more details.
"""

from Products.Five import BrowserView

from collective.iconifiedcategory import utils
from Products.Five import BrowserView


class IconifiedCategory(BrowserView):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ function categorizedChildsInfos(options={}) {
selector = options.selector || '.tooltipster-childs-infos';
tooltipster_helper(selector=selector,
view_name='@@categorized-childs-infos',
data_parameters=['category_uid']);
data_parameters=['category_uid', 'filters:json']);

}

Expand Down
5 changes: 2 additions & 3 deletions src/collective/iconifiedcategory/browser/subtyper.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,12 @@
"""

from Acquisition import aq_base
from Products.Five import BrowserView
from zope.interface import implements

from collective.iconifiedcategory.content.base import ICategorize
from collective.iconifiedcategory.content.categoryconfiguration import ICategoryConfiguration
from collective.iconifiedcategory.content.categorygroup import ICategoryGroup
from collective.iconifiedcategory.interfaces import IIconifiedCategorySubtyper
from Products.Five import BrowserView
from zope.interface import implements


class IconifiedCategoryPublicSubtyper(BrowserView):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
tal:attributes="href string:#${element/id}_${context/UID|context/getId};
title element/title;
data-category_uid string:${element/uid};
data-base_url string:${context/absolute_url};">
data-base_url string:${context/absolute_url};
data-filters:json string:${view/_filters_json};">
<span tal:content="element/counts"></span>
<img src=""
alt=""
Expand Down
31 changes: 19 additions & 12 deletions src/collective/iconifiedcategory/browser/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
from zope.component import getMultiAdapter
from zope.component.interfaces import ComponentLookupError

import json


class CategorizedChildView(BrowserView):
""" """
Expand All @@ -32,10 +34,20 @@ def __init__(self, context, request):
super(CategorizedChildView, self).__init__(context, request)
self.portal_url = api.portal.get().absolute_url()

@property
def _filters(self):
"""Overridable method to define custom filters."""
return {}

def _filters_json(self):
"""Filters are stored in template as json."""
return json.dumps(self._filters)

def update(self):
self.categorized_elements = get_categorized_elements(
self.context,
portal_type=self.portal_type,
filters=self._filters
)

def __call__(self, portal_type=None, show_nothing=True):
Expand Down Expand Up @@ -72,21 +84,16 @@ def __init__(self, context, request):
self.have_details_to_show = False

def update(self):
uids = self._find_uids()
self.categorized_elements = get_categorized_elements(self.context,
uids=uids)

def _find_uids(self):
""" """
uids = []
for k, v in getattr(self.context, 'categorized_elements', {}).items():
if v['category_uid'] == self.category_uid:
uids.append(k)
return uids
filters = self.filters
filters['category_uid'] = self.category_uid
self.categorized_elements = get_categorized_elements(
self.context,
filters=self.filters)

def __call__(self, category_uid):
def __call__(self, category_uid, filters):
""" """
self.category_uid = category_uid
self.filters = filters
self.update()
return super(CategorizedChildInfosView, self).__call__()

Expand Down
5 changes: 2 additions & 3 deletions src/collective/iconifiedcategory/content/categorygroup.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,14 @@
:license: GPL, see LICENCE.txt for more details.
"""

from collective.iconifiedcategory import _
from plone.app.contenttypes.interfaces import IFolder
from plone.autoform import directives as form
from plone.dexterity.content import Container
from plone.dexterity.schema import DexteritySchemaPolicy
from z3c.form.browser.radio import RadioFieldWidget
from zope.interface import implements
from zope import schema

from collective.iconifiedcategory import _
from zope.interface import implements


class ICategoryGroup(IFolder):
Expand Down
3 changes: 1 addition & 2 deletions src/collective/iconifiedcategory/content/subcategory.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,12 @@
:license: GPL, see LICENCE.txt for more details.
"""

from collective.iconifiedcategory.content.base import ICategorize
from plone.app.contenttypes.interfaces import IFolder
from plone.dexterity.content import Item
from plone.dexterity.schema import DexteritySchemaPolicy
from zope.interface import implements

from collective.iconifiedcategory.content.base import ICategorize


class ISubcategory(IFolder, ICategorize):
pass
Expand Down
2 changes: 1 addition & 1 deletion src/collective/iconifiedcategory/event.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
"""

from collective.iconifiedcategory.interfaces import ICategorizedElementsUpdatedEvent
from collective.iconifiedcategory.interfaces import IIconifiedCategoryChangedEvent
from collective.iconifiedcategory.interfaces import IIconifiedAttrChangedEvent
from collective.iconifiedcategory.interfaces import IIconifiedCategoryChangedEvent
from collective.iconifiedcategory.interfaces import IIconifiedModifiedEvent
from zope.component.interfaces import ObjectEvent
from zope.interface import implements
Expand Down
7 changes: 3 additions & 4 deletions src/collective/iconifiedcategory/indexes.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
# -*- coding: utf-8 -*-

from Products.PluginIndexes.common.UnIndex import _marker
from plone.dexterity.interfaces import IDexterityContent
from plone.indexer import indexer

from collective.iconifiedcategory import utils
from collective.iconifiedcategory.content.base import ICategorize
from plone.dexterity.interfaces import IDexterityContent
from plone.indexer import indexer
from Products.PluginIndexes.common.UnIndex import _marker


@indexer(ICategorize)
Expand Down
4 changes: 2 additions & 2 deletions src/collective/iconifiedcategory/interfaces.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
# -*- coding: utf-8 -*-
"""Module where all interfaces, events and exceptions live."""

from collective.iconifiedcategory import _
from plone.namedfile.interfaces import IImageScaleTraversable
from zope import schema
from zope.component.interfaces import IObjectEvent
from zope.interface import Attribute
from zope.interface import Interface
from zope.publisher.interfaces.browser import IDefaultBrowserLayer
from plone.namedfile.interfaces import IImageScaleTraversable
from collective.iconifiedcategory import _


class ICollectiveIconifiedCategoryLayer(IDefaultBrowserLayer):
Expand Down
7 changes: 3 additions & 4 deletions src/collective/iconifiedcategory/tests/base.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
# -*- coding: utf-8 -*-

import os
import unittest

from collective.iconifiedcategory import testing
from plone import api
from plone import namedfile
from plone.app.testing import login

from collective.iconifiedcategory import testing
import os
import unittest


class BaseTestCase(unittest.TestCase):
Expand Down
11 changes: 5 additions & 6 deletions src/collective/iconifiedcategory/tests/test_actionview.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
# -*- coding: utf-8 -*-

from AccessControl import Unauthorized
from Products.CMFCore.permissions import ModifyPortalContent
from z3c.json.interfaces import IJSONReader
from zope.component import getUtility

from plone import api
from collective.documentviewer.config import CONVERTABLE_TYPES
from collective.documentviewer.settings import GlobalSettings
from collective.iconifiedcategory.browser.actionview import BaseView
from collective.iconifiedcategory import utils
from collective.iconifiedcategory.browser.actionview import BaseView
from collective.iconifiedcategory.tests.base import BaseTestCase
from plone import api
from Products.CMFCore.permissions import ModifyPortalContent
from z3c.json.interfaces import IJSONReader
from zope.component import getUtility


class TestBaseView(BaseTestCase):
Expand Down
23 changes: 10 additions & 13 deletions src/collective/iconifiedcategory/tests/test_adapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,6 @@
:license: GPL, see LICENCE.txt for more details.
"""

from time import sleep

from zope.annotation import IAnnotations
from zope.component import getMultiAdapter
from zope.event import notify
from zope.lifecycleevent import ObjectModifiedEvent

from plone.app.contenttypes.interfaces import IFile
from plone.app.contenttypes.interfaces import IImage
from plone.app.contenttypes.interfaces import ILink
from plone.namedfile.utils import stream_data
from zope.interface import alsoProvides

from collective.documentviewer.async import queueJob
from collective.documentviewer.config import CONVERTABLE_TYPES
from collective.documentviewer.settings import GlobalSettings
Expand All @@ -28,6 +15,16 @@
from collective.iconifiedcategory.interfaces import IIconifiedContent
from collective.iconifiedcategory.tests.base import BaseTestCase
from collective.iconifiedcategory.utils import get_category_object
from plone.app.contenttypes.interfaces import IFile
from plone.app.contenttypes.interfaces import IImage
from plone.app.contenttypes.interfaces import ILink
from plone.namedfile.utils import stream_data
from time import sleep
from zope.annotation import IAnnotations
from zope.component import getMultiAdapter
from zope.event import notify
from zope.interface import alsoProvides
from zope.lifecycleevent import ObjectModifiedEvent


class TestCategorizedObjectInfoAdapter(BaseTestCase):
Expand Down
Loading

0 comments on commit 26017d8

Please sign in to comment.