Skip to content

Commit

Permalink
Fix code-analysis
Browse files Browse the repository at this point in the history
  • Loading branch information
odelaere committed Jan 19, 2022
1 parent 54b172d commit ddb93cf
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 31 deletions.
1 change: 1 addition & 0 deletions buildout.cfg
Expand Up @@ -41,6 +41,7 @@ directory = ${buildout:directory}/src/collective
flake8-exclude = bootstrap.py,bootstrap-buildout.py,docs,*.egg.,omelette
flake8-max-complexity = 18
flake8-max-line-length = 120
flake8-ignore = W606, B902
flake8-extensions =
flake8-blind-except
flake8-debugger
Expand Down
1 change: 0 additions & 1 deletion src/collective/iconifiedcategory/adapter.py
Expand Up @@ -15,7 +15,6 @@
from collective.iconifiedcategory.content.subcategory import ISubcategory
from collective.iconifiedcategory.interfaces import IIconifiedPreview
from collective.iconifiedcategory.utils import _modified
from datetime import datetime
from plone import api
from plone.app.contenttypes.interfaces import IFile
from plone.app.contenttypes.interfaces import IImage
Expand Down
3 changes: 1 addition & 2 deletions src/collective/iconifiedcategory/browser/views.py
Expand Up @@ -57,8 +57,7 @@ def __call__(self, portal_type=None, show_nothing=True, check_can_view=False):
return super(CategorizedChildView, self).__call__()

def has_elements_to_show(self):
return ('categorized_elements' in self.context.__dict__ and
len(self.categorized_elements) > 0)
return ('categorized_elements' in self.context.__dict__ and len(self.categorized_elements) > 0)

def categories_infos(self):
infos = [(e['category_uid'], {'id': e['category_id'],
Expand Down
2 changes: 2 additions & 0 deletions src/collective/iconifiedcategory/content/category.py
Expand Up @@ -30,6 +30,8 @@ class ICategory(IFolder, ICategorize, IICImageScaleTraversable):
u'could be not optimal.'),
required=True,
)


alsoProvides(ICategory['icon'], IPrimaryField)


Expand Down
3 changes: 1 addition & 2 deletions src/collective/iconifiedcategory/tests/test_setup.py
Expand Up @@ -23,8 +23,7 @@ def test_product_installed(self):

def test_browserlayer(self):
"""Test that ICollectiveIconifiedCategoryLayer is registered."""
from collective.iconifiedcategory.interfaces import (
ICollectiveIconifiedCategoryLayer)
from collective.iconifiedcategory.interfaces import ICollectiveIconifiedCategoryLayer
from plone.browserlayer import utils
self.assertIn(ICollectiveIconifiedCategoryLayer,
utils.registered_layers())
Expand Down
54 changes: 28 additions & 26 deletions src/collective/iconifiedcategory/utils.py
Expand Up @@ -269,6 +269,31 @@ def _categorized_elements(context):
)


def _check_filters(infos, filters):
""" """
keep = True
for k, v in filters.items():
# manage case when stored value is a list or not
stored_value = infos[k]
if not hasattr(stored_value, '__iter__'):
stored_value = (stored_value, )
if v not in stored_value:
keep = False
break
return keep


def _get_adapter(context, obj, adapter):
""" """
if adapter is None:
adapter = getMultiAdapter(
(context, context.REQUEST, obj),
IIconifiedContent)
else:
adapter.categorized_obj = obj
return adapter


def get_categorized_elements(context,
result_type='dict',
portal_type=None,
Expand All @@ -285,29 +310,6 @@ def get_categorized_elements(context,
available filters are values stored in categorized_elements.
If p_check_can_view is True, then the IIconifiedContent.can_view
check will be called."""
def _check_filters(infos):
""" """
keep = True
for k, v in filters.items():
# manage case when stored value is a list or not
stored_value = infos[k]
if not hasattr(stored_value, '__iter__'):
stored_value = (stored_value, )
if v not in stored_value:
keep = False
break
return keep

def _get_adapter(parent, obj, adapter):
""" """
if adapter is None:
adapter = getMultiAdapter(
(context, context.REQUEST, obj),
IIconifiedContent)
else:
adapter.categorized_obj = obj
return adapter

elements = None
if caching:
# in some cases like in tests, request can not be retrieved
Expand All @@ -334,9 +336,9 @@ def _get_adapter(parent, obj, adapter):
for uid, infos in categorized_elements.items():
if (uids and uid not in uids) or \
(portal_type and infos['portal_type'] != portal_type) or \
not _check_filters(infos) or \
(infos['confidential'] and
not set(infos['allowedRolesAndUsers']).intersection(current_user_allowedRolesAndUsers)):
not _check_filters(infos, filters) or \
(infos['confidential'] and not set(infos['allowedRolesAndUsers'])
.intersection(current_user_allowedRolesAndUsers)):
continue

obj = context.get(infos['id'])
Expand Down

0 comments on commit ddb93cf

Please sign in to comment.