Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Calendar tile does not work under Plone 5 #633

Closed
hvelarde opened this issue Jul 1, 2016 · 6 comments · Fixed by #906 · May be fixed by #653
Closed

Calendar tile does not work under Plone 5 #633

hvelarde opened this issue Jul 1, 2016 · 6 comments · Fixed by #906 · May be fixed by #653
Assignees

Comments

@hvelarde
Copy link
Member

hvelarde commented Jul 1, 2016

The code of the calendar tile was copied from the calendar portlet and it depends on the portal_calendar tool; this tools was removed in Plone 5:

https://travis-ci.org/collective/collective.cover/jobs/141693521#L1392

We need to refactor this part of the code to allow compatibility.

Some ideas can be taken from #600.

@wesleybl
Copy link
Member

wesleybl commented Feb 3, 2022

@pbauer tried to fix it. But now in master we have the following error:

2022-02-03 10:36:55,349 ERROR   [plone.subrequest:170][waitress-1] Error handling subrequest to http://localhost:8080/Plone/capa/@@collective.cover.calendar/e30ae925-a757-4f44-9ec5-e0bcd9360f4d
Traceback (most recent call last):
  File "/home/user/.buildout/eggs/cp38/Chameleon-3.9.1-py3.8.egg/chameleon/template.py", line 192, in render
    self._render(stream, econtext, rcontext)
  File "/home/user/git/collective.cover/var/cache/8354dca6a444dcac52975b7d1ff4a4fe.py", line 639, in render
    __iterator = _static_140219983632752('path', 'view/getEventsForCalendar', econtext=econtext)(_static_140219983631024(econtext, __zt_tmp))
  File "/home/user/.buildout/eggs/cp38/zope.tales-5.1-py3.8.egg/zope/tales/expressions.py", line 250, in __call__
    return self._eval(econtext)
  File "/home/user/.buildout/eggs/cp38/Zope-4.6.3-py3.8.egg/Products/PageTemplates/Expressions.py", line 225, in _eval
    return render(ob, econtext.vars)
  File "/home/user/.buildout/eggs/cp38/Zope-4.6.3-py3.8.egg/Products/PageTemplates/Expressions.py", line 155, in render
    ob = ob()
  File "/home/user/git/collective.cover/src/collective/cover/tiles/calendar.py", line 76, in getEventsForCalendar
    weeks = self.old_getEventsForCalendar(month, year, path=navigation_root_path)
  File "/home/user/git/collective.cover/src/collective/cover/tiles/calendar.py", line 116, in old_getEventsForCalendar
    calendar.setfirstweekday(first_weekday)
  File "/usr/local/lib/python3.8/calendar.py", line 622, in setfirstweekday
    raise IllegalWeekdayError(firstweekday)
calendar.IllegalWeekdayError: bad weekday number 7; must be 0 (Monday) to 6 (Sunday)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/user/.buildout/eggs/cp38/plone.subrequest-1.9.3-py3.8.egg/plone/subrequest/__init__.py", line 154, in subrequest
    result = mapply(
  File "/home/user/.buildout/eggs/cp38/Zope-4.6.3-py3.8.egg/ZPublisher/mapply.py", line 87, in mapply
    return object(*args)
  File "/home/user/.buildout/eggs/cp38/plone.tiles-2.3.1-py3.8.egg/plone/tiles/esi.py", line 87, in __call__
    return self.index(*args, **kwargs)
  File "/home/user/.buildout/eggs/cp38/Zope-4.6.3-py3.8.egg/Products/Five/browser/pagetemplatefile.py", line 126, in __call__
    return self.__func__(__self__, *args, **kw)
  File "/home/user/.buildout/eggs/cp38/Zope-4.6.3-py3.8.egg/Products/Five/browser/pagetemplatefile.py", line 58, in __call__
    s = self.pt_render(
  File "/home/user/.buildout/eggs/cp38/zope.pagetemplate-4.5.0-py3.8.egg/zope/pagetemplate/pagetemplate.py", line 133, in pt_render
    return self._v_program(
  File "/home/user/.buildout/eggs/cp38/Zope-4.6.3-py3.8.egg/Products/PageTemplates/engine.py", line 378, in __call__
    return template.render(**kwargs)
  File "/home/user/.buildout/eggs/cp38/z3c.pt-3.3.0-py3.8.egg/z3c/pt/pagetemplate.py", line 176, in render
    return base_renderer(**context)
  File "/home/user/.buildout/eggs/cp38/Chameleon-3.9.1-py3.8.egg/chameleon/zpt/template.py", line 302, in render
    return super(PageTemplate, self).render(**_kw)
  File "/home/user/.buildout/eggs/cp38/Chameleon-3.9.1-py3.8.egg/chameleon/template.py", line 215, in render
    raise_with_traceback(exc, tb)
  File "/home/user/.buildout/eggs/cp38/Chameleon-3.9.1-py3.8.egg/chameleon/utils.py", line 53, in raise_with_traceback
    raise exc
  File "/home/user/.buildout/eggs/cp38/Chameleon-3.9.1-py3.8.egg/chameleon/template.py", line 192, in render
    self._render(stream, econtext, rcontext)
  File "/home/user/git/collective.cover/var/cache/8354dca6a444dcac52975b7d1ff4a4fe.py", line 639, in render
    __iterator = _static_140219983632752('path', 'view/getEventsForCalendar', econtext=econtext)(_static_140219983631024(econtext, __zt_tmp))
  File "/home/user/.buildout/eggs/cp38/zope.tales-5.1-py3.8.egg/zope/tales/expressions.py", line 250, in __call__
    return self._eval(econtext)
  File "/home/user/.buildout/eggs/cp38/Zope-4.6.3-py3.8.egg/Products/PageTemplates/Expressions.py", line 225, in _eval
    return render(ob, econtext.vars)
  File "/home/user/.buildout/eggs/cp38/Zope-4.6.3-py3.8.egg/Products/PageTemplates/Expressions.py", line 155, in render
    ob = ob()
  File "/home/user/git/collective.cover/src/collective/cover/tiles/calendar.py", line 76, in getEventsForCalendar
    weeks = self.old_getEventsForCalendar(month, year, path=navigation_root_path)
  File "/home/user/git/collective.cover/src/collective/cover/tiles/calendar.py", line 116, in old_getEventsForCalendar
    calendar.setfirstweekday(first_weekday)
  File "/usr/local/lib/python3.8/calendar.py", line 622, in setfirstweekday
    raise IllegalWeekdayError(firstweekday)
calendar.IllegalWeekdayError: calendar.IllegalWeekdayError: bad weekday number 7; must be 0 (Monday) to 6 (Sunday)

 - Expression: "view/getEventsForCalendar"
 - Filename:   ... e.cover/src/collective/cover/tiles/templates/calendar.pt
 - Location:   (line 59: col 33)
 - Source:     <tr tal:repeat="week view/getEventsForCalendar">
                                    ^^^^^^^^^^^^^^^^^^^^^^^^^
 - Arguments:  template: <Products.Five.browser.pagetemplatefile.ViewPageTemplateFile object at 0x7f877df1ea00>
               options: {}
               args: ()
               nothing: None
               modules: <Products.PageTemplates.ZRPythonExpr._SecureModuleImporter object at 0x7f87862bb6a0>
               request: <WSGIRequest, URL=http://localhost:8080/Plone/capa/@@collective.cover.calendar/e30ae925-a757-4f44-9ec5-e0bcd9360f4d>
               view: <Products.Five.browser.metaconfigure.CalendarTile object at 0x7f876e191e80>
               context: <Cover at /Plone/capa>
               views: <Products.Five.browser.pagetemplatefile.ViewMapper object at 0x7f876dec3af0>
               here: <Cover at /Plone/capa>
               container: <Cover at /Plone/capa>
               root: <Application at >
               traverse_subpath: []
               user: <PropertiedUser 'admin'>
               default: <DEFAULT>
               repeat: <Products.PageTemplates.engine.RepeatDictWrapper object at 0x7f877e48eb40>
               loop: {'weekday': <Products.PageTemplates.engine.RepeatItem object at 0x7f876dec3d00>}
               target_language: None
               translate: <function BaseTemplate.render.<locals>.translate at 0x7f876dddcaf0>
               attrs: {}
               navigation_root_url: 'http://localhost:8080/Plone'
               query_string: ''
               url_quote_plus: <function quote_plus at 0x7f878f9c7700>
               showPrevMonth: True
               showNextMonth: True
               year: 2022
2022-02-03 10:36:55,350 ERROR   [plone.app.blocks:72][waitress-1] There was an error while resolving the tile: http://localhost:8080/Plone/capa/@@collective.cover.calendar/e30ae925-a757-4f44-9ec5-e0bcd9360f4d
Traceback (most recent call last):
  File "/home/user/.buildout/eggs/cp38/Chameleon-3.9.1-py3.8.egg/chameleon/template.py", line 192, in render
    self._render(stream, econtext, rcontext)
  File "/home/user/git/collective.cover/var/cache/8354dca6a444dcac52975b7d1ff4a4fe.py", line 639, in render
    __iterator = _static_140219983632752('path', 'view/getEventsForCalendar', econtext=econtext)(_static_140219983631024(econtext, __zt_tmp))
  File "/home/user/.buildout/eggs/cp38/zope.tales-5.1-py3.8.egg/zope/tales/expressions.py", line 250, in __call__
    return self._eval(econtext)
  File "/home/user/.buildout/eggs/cp38/Zope-4.6.3-py3.8.egg/Products/PageTemplates/Expressions.py", line 225, in _eval
    return render(ob, econtext.vars)
  File "/home/user/.buildout/eggs/cp38/Zope-4.6.3-py3.8.egg/Products/PageTemplates/Expressions.py", line 155, in render
    ob = ob()
  File "/home/user/git/collective.cover/src/collective/cover/tiles/calendar.py", line 76, in getEventsForCalendar
    weeks = self.old_getEventsForCalendar(month, year, path=navigation_root_path)
  File "/home/user/git/collective.cover/src/collective/cover/tiles/calendar.py", line 116, in old_getEventsForCalendar
    calendar.setfirstweekday(first_weekday)
  File "/usr/local/lib/python3.8/calendar.py", line 622, in setfirstweekday
    raise IllegalWeekdayError(firstweekday)
calendar.IllegalWeekdayError: bad weekday number 7; must be 0 (Monday) to 6 (Sunday)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/user/.buildout/eggs/cp38/plone.subrequest-1.9.3-py3.8.egg/plone/subrequest/__init__.py", line 154, in subrequest
    result = mapply(
  File "/home/user/.buildout/eggs/cp38/Zope-4.6.3-py3.8.egg/ZPublisher/mapply.py", line 87, in mapply
    return object(*args)
  File "/home/user/.buildout/eggs/cp38/plone.tiles-2.3.1-py3.8.egg/plone/tiles/esi.py", line 87, in __call__
    return self.index(*args, **kwargs)
  File "/home/user/.buildout/eggs/cp38/Zope-4.6.3-py3.8.egg/Products/Five/browser/pagetemplatefile.py", line 126, in __call__
    return self.__func__(__self__, *args, **kw)
  File "/home/user/.buildout/eggs/cp38/Zope-4.6.3-py3.8.egg/Products/Five/browser/pagetemplatefile.py", line 58, in __call__
    s = self.pt_render(
  File "/home/user/.buildout/eggs/cp38/zope.pagetemplate-4.5.0-py3.8.egg/zope/pagetemplate/pagetemplate.py", line 133, in pt_render
    return self._v_program(
  File "/home/user/.buildout/eggs/cp38/Zope-4.6.3-py3.8.egg/Products/PageTemplates/engine.py", line 378, in __call__
    return template.render(**kwargs)
  File "/home/user/.buildout/eggs/cp38/z3c.pt-3.3.0-py3.8.egg/z3c/pt/pagetemplate.py", line 176, in render
    return base_renderer(**context)
  File "/home/user/.buildout/eggs/cp38/Chameleon-3.9.1-py3.8.egg/chameleon/zpt/template.py", line 302, in render
    return super(PageTemplate, self).render(**_kw)
  File "/home/user/.buildout/eggs/cp38/Chameleon-3.9.1-py3.8.egg/chameleon/template.py", line 215, in render
    raise_with_traceback(exc, tb)
  File "/home/user/.buildout/eggs/cp38/Chameleon-3.9.1-py3.8.egg/chameleon/utils.py", line 53, in raise_with_traceback
    raise exc
  File "/home/user/.buildout/eggs/cp38/Chameleon-3.9.1-py3.8.egg/chameleon/template.py", line 192, in render
    self._render(stream, econtext, rcontext)
  File "/home/user/git/collective.cover/var/cache/8354dca6a444dcac52975b7d1ff4a4fe.py", line 639, in render
    __iterator = _static_140219983632752('path', 'view/getEventsForCalendar', econtext=econtext)(_static_140219983631024(econtext, __zt_tmp))
  File "/home/user/.buildout/eggs/cp38/zope.tales-5.1-py3.8.egg/zope/tales/expressions.py", line 250, in __call__
    return self._eval(econtext)
  File "/home/user/.buildout/eggs/cp38/Zope-4.6.3-py3.8.egg/Products/PageTemplates/Expressions.py", line 225, in _eval
    return render(ob, econtext.vars)
  File "/home/user/.buildout/eggs/cp38/Zope-4.6.3-py3.8.egg/Products/PageTemplates/Expressions.py", line 155, in render
    ob = ob()
  File "/home/user/git/collective.cover/src/collective/cover/tiles/calendar.py", line 76, in getEventsForCalendar
    weeks = self.old_getEventsForCalendar(month, year, path=navigation_root_path)
  File "/home/user/git/collective.cover/src/collective/cover/tiles/calendar.py", line 116, in old_getEventsForCalendar
    calendar.setfirstweekday(first_weekday)
  File "/usr/local/lib/python3.8/calendar.py", line 622, in setfirstweekday
    raise IllegalWeekdayError(firstweekday)
calendar.IllegalWeekdayError: calendar.IllegalWeekdayError: bad weekday number 7; must be 0 (Monday) to 6 (Sunday)

 - Expression: "view/getEventsForCalendar"
 - Filename:   ... e.cover/src/collective/cover/tiles/templates/calendar.pt
 - Location:   (line 59: col 33)
 - Source:     <tr tal:repeat="week view/getEventsForCalendar">
                                    ^^^^^^^^^^^^^^^^^^^^^^^^^
 - Arguments:  template: <Products.Five.browser.pagetemplatefile.ViewPageTemplateFile object at 0x7f877df1ea00>
               options: {}
               args: ()
               nothing: None
               modules: <Products.PageTemplates.ZRPythonExpr._SecureModuleImporter object at 0x7f87862bb6a0>
               request: <WSGIRequest, URL=None>
               view: <Products.Five.browser.metaconfigure.CalendarTile object at 0x7f876e191e80>
               context: <Cover at /Plone/capa>
               views: <Products.Five.browser.pagetemplatefile.ViewMapper object at 0x7f876dec3af0>
               here: <Cover at /Plone/capa>
               container: <Cover at /Plone/capa>
               root: <Application at >
               traverse_subpath: []
               user: <PropertiedUser 'admin'>
               default: <DEFAULT>
               repeat: <Products.PageTemplates.engine.RepeatDictWrapper object at 0x7f877e48eb40>
               loop: {'weekday': <Products.PageTemplates.engine.RepeatItem object at 0x7f876dec3d00>}
               target_language: None
               translate: <function BaseTemplate.render.<locals>.translate at 0x7f876dddcaf0>
               attrs: {}
               navigation_root_url: 'http://localhost:8080/Plone'
               query_string: ''
               url_quote_plus: <function quote_plus at 0x7f878f9c7700>
               showPrevMonth: True
               showNextMonth: True
               year: 2022

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/user/.buildout/eggs/cp38/plone.app.blocks-5.0.0-py3.8.egg/plone/app/blocks/utils.py", line 70, in resolve
    resolved = resolveResource(url)
  File "/home/user/.buildout/eggs/cp38/plone.app.blocks-5.0.0-py3.8.egg/plone/app/blocks/utils.py", line 136, in resolveResource
    response = subrequest(url, exception_handler=subresponse_exception_handler)
  File "/home/user/.buildout/eggs/cp38/plone.subrequest-1.9.3-py3.8.egg/plone/subrequest/__init__.py", line 172, in subrequest
    exception_handler(response, e)
  File "/home/user/.buildout/eggs/cp38/plone.app.blocks-5.0.0-py3.8.egg/plone/app/blocks/utils.py", line 109, in subresponse_exception_handler
    return response.exception()
  File "/home/user/.buildout/eggs/cp38/Zope-4.6.3-py3.8.egg/ZPublisher/HTTPResponse.py", line 953, in exception
    b + self._traceback(t, '(see above)', tb, 0)),
  File "/home/user/.buildout/eggs/cp38/Zope-4.6.3-py3.8.egg/ZPublisher/HTTPResponse.py", line 807, in _traceback
    tb = format_exception(t, v, tb, as_html=as_html)
  File "/home/user/.buildout/eggs/cp38/zExceptions-4.1-py3.8.egg/zExceptions/ExceptionFormatter.py", line 251, in format_exception
    return fmt.formatException(t, v, tb, limit=limit)
  File "/home/user/.buildout/eggs/cp38/zExceptions-4.1-py3.8.egg/zExceptions/ExceptionFormatter.py", line 198, in formatException
    exc_line = self.formatExceptionOnly(etype, value)
  File "/home/user/.buildout/eggs/cp38/zExceptions-4.1-py3.8.egg/zExceptions/ExceptionFormatter.py", line 177, in formatExceptionOnly
    traceback.format_exception_only(etype, value))
  File "/usr/local/lib/python3.8/traceback.py", line 140, in format_exception_only
    return list(TracebackException(etype, value, None).format_exception_only())
  File "/usr/local/lib/python3.8/traceback.py", line 479, in __init__
    if (exc_value and exc_value.__cause__ is not None
AttributeError: 'str' object has no attribute '__cause__'

@pbauer
Copy link
Member

pbauer commented Feb 3, 2022

The calendar tile worked in my tests but I'll try to reproduce and fix the issue tomorrow.

@wesleybl
Copy link
Member

wesleybl commented Feb 3, 2022

@pbauer the problem is that first_weekday on this line:

first_weekday = api.portal.get_registry_record("plone.first_weekday") + 1

is getting the value 7. But the calendar library only accepts 0 to 6.

Why are you using the registry there? It couldn't be done like is done in CalendarTool:

https://github.com/plone/Products.CMFPlone/blob/b5c6edfc52b663b080ceed88b44d39b8401adb50/Products/CMFPlone/CalendarTool.py#L50

@wesleybl
Copy link
Member

wesleybl commented Feb 3, 2022

Why are you using the registry there? It couldn't be done like is done in CalendarTool

uh even in CalendarTool this was configurable.

@wesleybl
Copy link
Member

wesleybl commented Feb 3, 2022

The calendar tile worked in my tests

@pbauer plone.first_weekday depends on locales:

https://github.com/plone/Products.CMFPlone/blob/df6d7041f02a9d64a1e7034daafede940f7105a8/Products/CMFPlone/setuphandlers.py#L213-L215

Maybe that's why it worked for you and not me.

@wesleybl
Copy link
Member

wesleybl commented Feb 3, 2022

@pbauer see that CalendarTool doesn't add +1 to firstweekday:

https://github.com/zopefoundation/Products.CMFCalendar/blob/master/Products/CMFCalendar/CalendarTool.py#L109

like you did in:

first_weekday = api.portal.get_registry_record("plone.first_weekday") + 1

The calendar probably looks weird to you, but you should change the plone.first_weekday record instead of adding +1 in the code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
4 participants