Utility can't find REQUEST

Ross Patterson me at rpatterson.net
Thu Aug 30 06:43:07 UTC 2007


sirgarr <georgeleejr at gmail.com> writes:

> I am trying to code a utility as follows, but on runtime the call of
> toLocalizedTime raises an AttributeError of REQUEST.  I thought that there
> was a REQUEST somehow built in and lurking in the background when this code
> got called -- for instance, doesn't getUtility know about the request and
> use it to find the closest site manager?  How would I fix this code?
>
>
>
> class DateRangeDisplayer(object):
>     implements(IDateRangeDisplayer)
>
>     def range_as_string(self, start, end):
>         portal = getUtility(ISiteRoot)
>         portal_properties = getUtility(IPropertiesTool)
>         site_properties = portal_properties.site_properties
>
>         if start.Date() != end.Date():
>             return '%s to %s' % (
>               portal.toLocalizedTime(start, long_format=1),
>               portal.toLocalizedTime(end, long_format=1)
>               )

Only acquisition wrapped objects can access self.REQUEST.  Utilities are
not wrapped.  Either pass in the request or use a tool.

Ross





More information about the Product-Developers mailing list