products/CPSonFive.old

changeset 30:3ee761b550f0

Five 1.2 support.
author lregebro
date Fri, 06 Jan 2006 14:28:54 +0000
parents 69c2e69e46cd
children 1d8b13999dea
files CHANGES __init__.py configure.zcml form/widget.py overrides.zcml
diffstat 5 files changed, 58 insertions(+), 20 deletions(-) [+]
line diff
     1.1 --- a/CHANGES
     1.2 +++ b/CHANGES
     1.3 @@ -1,9 +1,10 @@
     1.4  Requires:
     1.5  ~~~~~~~~~
     1.6 --
     1.7 +- Now requires Five 1.2b or later.
     1.8  New features:
     1.9  ~~~~~~~~~~~~~
    1.10 --
    1.11 +- Marks a CPS site as a local site, enabling the use of local utilities.
    1.12 +- Added a temporary monkey patch for a big in the betas of Five 1.2, 1.3.
    1.13  Bug fixes:
    1.14  ~~~~~~~~~~
    1.15  -
     2.1 --- a/__init__.py
     2.2 +++ b/__init__.py
     2.3 @@ -23,6 +23,7 @@
     2.4  """
     2.5  from types import StringTypes
     2.6  from zope.schema.interfaces import ITitledTokenizedTerm
     2.7 +from zope.i18nmessageid.messageid import MessageID
     2.8  
     2.9  # Zope3.0.0 doesn't translates dropdownboxes (that's a bug)
    2.10  def textForValue(self, term):
    2.11 @@ -33,21 +34,10 @@
    2.12      This can be overridden to support more complex term objects. The token
    2.13      is returned here since it's the only thing known to be a string, or
    2.14      str()able."""
    2.15 -    # XXX: This is how it should be once we start using Five 1.1, with i18n.
    2.16 -    # if ITitledTokenizedTerm.providedBy(term):
    2.17 -    #     return self.translate(term.title)
    2.18 -    # return self.translate(term.token)
    2.19 +    if ITitledTokenizedTerm.providedBy(term):
    2.20 +        return self.translate(term.title)
    2.21 +    return self.translate(term.token)
    2.22  
    2.23 -    # XXX: But with Five 1.0.x we need to call Localizer, and we also need to
    2.24 -    # make sure Localizer gets a string, and not a MessageID
    2.25 -    if ITitledTokenizedTerm.providedBy(term):
    2.26 -        message = term.title
    2.27 -    else:
    2.28 -        message = term.token
    2.29 -
    2.30 -    if type(message) not in StringTypes:
    2.31 -        message = str(message)
    2.32 -    return self.context.context.Localizer.default(message)
    2.33  
    2.34  from zope.i18n.interfaces import IUserPreferredCharsets
    2.35  from zope.interface import implements
    2.36 @@ -123,14 +113,49 @@
    2.37  
    2.38      self.update_status = status
    2.39      return status
    2.40 -    
    2.41 +
    2.42 +# XXX: Five 1.2b and 1.3b and Zope 2.9 betas have a bug the local site 
    2.43 +# configuration, which can result in one class getting listed twice in the 
    2.44 +# list of classes that have a site hook. This monkey avoids that, and can be 
    2.45 +# removed once the final versions have been released:
    2.46 +from Products.Five.site import metaconfigure
    2.47 +from Products.Five.site.localsite import FiveSite
    2.48 +from zope.app.component.interfaces import IPossibleSite
    2.49 +from zope.configuration.exceptions import ConfigurationError
    2.50 +from zope.interface import classImplements
    2.51 +
    2.52 +def installSiteHook(_context, class_, site_class=None):
    2.53 +    if class_ in metaconfigure._localsite_monkies:
    2.54 +        return # This is the workaround
    2.55 +    if site_class is None:
    2.56 +        if not IPossibleSite.implementedBy(class_):
    2.57 +            # This is not a possible site, we need to monkey-patch it so that
    2.58 +            # it is.
    2.59 +            site_class = FiveSite
    2.60 +    else:
    2.61 +        if not IPossibleSite.implementedBy(site_class):
    2.62 +            raise ConfigurationError('Site class does not implement '
    2.63 +                                     'IPossibleClass: %s' % site_class)
    2.64 +    if site_class is not None:
    2.65 +        _context.action(
    2.66 +            discriminator = (class_,),
    2.67 +            callable = metaconfigure.classSiteHook,
    2.68 +            args=(class_, site_class)
    2.69 +            )
    2.70 +        _context.action(
    2.71 +            discriminator = (class_, IPossibleSite),
    2.72 +            callable = classImplements,
    2.73 +            args=(class_, IPossibleSite)
    2.74 +            )
    2.75 +    metaconfigure._localsite_monkies.append(class_)
    2.76 +
    2.77 +metaconfigure.installSiteHook = installSiteHook
    2.78 +
    2.79      
    2.80  def initialize(context):
    2.81  
    2.82      # Zope3monkey
    2.83      from zope.app.form.browser.itemswidgets import ItemsWidgetBase
    2.84      ItemsWidgetBase.textForValue = textForValue
    2.85 -    
    2.86      # Five monkey
    2.87      EditView.update = EditViewUpdate
    2.88 -    
     3.1 --- a/configure.zcml
     3.2 +++ b/configure.zcml
     3.3 @@ -4,4 +4,7 @@
     3.4  
     3.5    <include file="form/configure.zcml" />
     3.6  
     3.7 +  <five:localsite class="Products.CPSDefault.Portal.CPSDefaultSite" />
     3.8 +  <five:traversable class="Products.CPSDefault.Portal.CPSDefaultSite" />
     3.9 +
    3.10  </configure>
     4.1 --- a/form/widget.py
     4.2 +++ b/form/widget.py
     4.3 @@ -29,7 +29,7 @@
     4.4      from zope.i18nmessageid import MessageFactory
     4.5  except ImportError:
     4.6      from zope.i18nmessageid import MessageIDFactory as MessageFactory
     4.7 -_ = MessageFactory("Default")
     4.8 +_ = MessageFactory("calendar")
     4.9  
    4.10  class CPSWidgetInputErrorView(WidgetInputErrorView):
    4.11      """Display an input error as a snippet of text.
     5.1 --- a/overrides.zcml
     5.2 +++ b/overrides.zcml
     5.3 @@ -11,4 +11,13 @@
     5.4        provides="zope.i18n.interfaces.IUserPreferredCharsets"
     5.5        />
     5.6  
     5.7 +  <adapter
     5.8 +      for="zope.publisher.interfaces.http.IHTTPRequest" 
     5.9 +      provides="zope.i18n.interfaces.IUserPreferredLanguages" 
    5.10 +      factory="Products.Five.i18n.LocalizerLanguages"
    5.11 +      />
    5.12 +
    5.13 +  <five:localsite class="Products.CPSDefault.Portal.CPSDefaultSite" />
    5.14 +  <five:traversable class="Products.CPSDefault.Portal.CPSDefaultSite" />
    5.15 +
    5.16  </configure>