Skip to content

Commit

Permalink
Merge e8e06db into ab45150
Browse files Browse the repository at this point in the history
  • Loading branch information
gbastien committed Mar 16, 2021
2 parents ab45150 + e8e06db commit 1978391
Show file tree
Hide file tree
Showing 29 changed files with 166 additions and 87 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]
- Added a ZPublisher `:json` suffix type converter.
[gbastien]

0.48 (2021-01-19)
-----------------
Expand Down
6 changes: 3 additions & 3 deletions buildout.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -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 @@ -125,12 +125,12 @@ plone.api = 1.4.11
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 Down
14 changes: 13 additions & 1 deletion src/collective/iconifiedcategory/__init__.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,23 @@
# -*- coding: utf-8 -*-
"""Init and utils."""
import logging
from zope.i18nmessageid import MessageFactory
from ZPublisher.Converters import type_converters

import json
import logging


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

CAT_SEPARATOR = '_-_'
CSS_SEPARATOR = '-'

_ = MessageFactory('collective.iconifiedcategory')


# create type converter for json
if 'field2json' not in type_converters:
def field2json(v):
v = json.loads(v)
return v
type_converters['json'] = field2json
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
2 changes: 1 addition & 1 deletion src/collective/iconifiedcategory/tests/test_behaviors.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@
from collective.iconifiedcategory.utils import calculate_category_id
from collective.iconifiedcategory.utils import get_category_object
from plone import api
from z3c.form import validator
from zope.event import notify
from zope.lifecycleevent import ObjectModifiedEvent
from z3c.form import validator
from ZPublisher.HTTPRequest import FileUpload

import cgi
Expand Down
6 changes: 2 additions & 4 deletions src/collective/iconifiedcategory/tests/test_browser_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,11 @@
:license: GPL, see LICENCE.txt for more details.
"""

from collective.iconifiedcategory.interfaces import IIconifiedCategoryChangedEvent
from collective.iconifiedcategory.tests.base import BaseTestCase
from zope.component import adapter
from zope.component import getGlobalSiteManager

from collective.iconifiedcategory.interfaces import \
IIconifiedCategoryChangedEvent
from collective.iconifiedcategory.tests.base import BaseTestCase


SUBSCRIBED_ELEMENTS = []

Expand Down
24 changes: 24 additions & 0 deletions src/collective/iconifiedcategory/tests/test_converters.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# -*- coding: utf-8 -*-

from collective.iconifiedcategory.tests.base import BaseTestCase
from ZPublisher.tests.testHTTPRequest import HTTPRequestTests


class TestConverters(BaseTestCase, HTTPRequestTests):

def test_iconifiedcategory_json_converter(self):
inputs = (
('data:json', '{"key1": "value1", "key2": "value2"}'),
('data2:json', '{"key3": "value3", "key4": "value4"}'), )
req = self._processInputs(inputs)
self.assertEqual(req.form,
{'data': {u'key2': u'value2', u'key1': u'value1'},
'data2': {u'key3': u'value3', u'key4': u'value4'}})


def test_suite():
from unittest import TestSuite, makeSuite
suite = TestSuite()
# change prefix to avoid executing every tests of HTTPRequestTests
suite.addTest(makeSuite(TestConverters, prefix='test_iconifiedcategory_'))
return suite

0 comments on commit 1978391

Please sign in to comment.