Skip to content

Commit

Permalink
Corrige navegação entre meses calendário estendido
Browse files Browse the repository at this point in the history
Fecha #82.

Patch foi feito da forma tradicional e não com uso de
collective.monkeypatcher, ver

https://pypi.org/project/collective.monkeypatcher/#patching-module-level-functions
  • Loading branch information
idgserpro committed May 11, 2018
1 parent 453d40e commit 9659348
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 0 deletions.
3 changes: 3 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ Changelog
1.1.3 (unreleased)
^^^^^^^^^^^^^^^^^^

- Corrige (via patch) navegação entre os meses de um calendário estendido. (fecha `#82`_).
[idgserpro]

- Corrige layout do portlet de agenda após atualização de plone.app.contenttypes 1.1.x. (relacionado a `#82`_).
[idgserpro]

Expand Down
4 changes: 4 additions & 0 deletions src/brasil/gov/agenda/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
# -*- coding: utf-8 -*-

from brasil.gov.agenda import patches
from zope.i18nmessageid import MessageFactory


_ = MessageFactory('brasil.gov.agenda')


patches.run()
60 changes: 60 additions & 0 deletions src/brasil/gov/agenda/patches.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
# -*- coding: utf-8 -*-

from brasil.gov.agenda.logger import logger
from plone.app.portlets import utils
from plone.app.portlets.storage import PortletAssignmentMapping
from plone.app.portlets.storage import UserPortletAssignmentMapping
from plone.portlets.constants import CONTEXT_CATEGORY
from plone.portlets.constants import USER_CATEGORY
from plone.portlets.interfaces import IPortletAssignmentMapping
from plone.portlets.interfaces import IPortletManager
from Products.CMFCore.utils import getToolByName
from zope.component import getMultiAdapter
from zope.component import getUtility


def assignment_mapping_from_key():
# Customização obtida de
# https://github.com/plone/plone.app.portlets/blob/2.5.6/plone/app/portlets/utils.py#L55
def patched_assignment_mapping_from_key(context, manager_name, category, key, create=False):
"""Given the name of a portlet manager, the name of a category, and a
key in that category, return the IPortletAssignmentMapping.
Raise a KeyError if it cannot be found.
"""
manager = getUtility(IPortletManager, manager_name)

if category == CONTEXT_CATEGORY:
path = key
portal = getToolByName(context, 'portal_url').getPortalObject()
portal_path = '/'.join(portal.getPhysicalPath())
if path == portal_path:
# there may be problem if PloneSite id is 'plone'.
# restrictedTraverse traverses to @@plone BrowserView which
# is wrong
obj = portal
else:
if path.startswith(portal_path + '/'):
path = path[len(portal_path)+1:] # NOQA
while path.startswith('/'):
path = path[1:]
# INICIO CUSTOMIZAÇÃO
obj = portal.restrictedTraverse(str(path), None)
# FIM CUSTOMIZAÇÃO
if obj is None:
raise KeyError, "Cannot find object at path %s" % path # NOQA
return getMultiAdapter((obj, manager), IPortletAssignmentMapping)
else:
mapping = manager[category]
if key not in mapping and create:
if category == USER_CATEGORY:
mapping[key] = UserPortletAssignmentMapping()
else:
mapping[key] = PortletAssignmentMapping()
return mapping[key]

setattr(utils, 'assignment_mapping_from_key', patched_assignment_mapping_from_key)
logger.info('Patched plone.app.portlets.utils.assignment_mapping_from_key')


def run():
assignment_mapping_from_key()

0 comments on commit 9659348

Please sign in to comment.