products/CPSonFive.old

changeset 48:303778c396aa 1.6.0

Updated the "Updated on" translation patch to work with Five 1.3.
author lregebro
date Mon, 09 Oct 2006 16:55:13 +0000
parents 9a8611195d6e
children 5899cb5e77cb 7391875c547a
files CHANGES __init__.py
diffstat 2 files changed, 21 insertions(+), 16 deletions(-) [+]
line diff
     1.1 --- a/CHANGES
     1.2 +++ b/CHANGES
     1.3 @@ -3,10 +3,11 @@
     1.4  -
     1.5  New features:
     1.6  ~~~~~~~~~~~~~
     1.7 --
     1.8 +- Now made for Five 1.3 and later. 
     1.9  Bug fixes:
    1.10  ~~~~~~~~~~
    1.11 --
    1.12 +- The "Updated on" text had stopped working, so I changed it for Five 1.3
    1.13 +  support.
    1.14  New internal features:
    1.15  ~~~~~~~~~~~~~~~~~~~~~~
    1.16  -
     2.1 --- a/__init__.py
     2.2 +++ b/__init__.py
     2.3 @@ -57,11 +57,8 @@
     2.4          '''See interface IUserPreferredCharsets'''
     2.5          return ['iso-8859-15']
     2.6  
     2.7 -
     2.8 -try: # Five 1.1
     2.9 -    from Products.Five.form import EditView, Update, applyWidgetsChanges
    2.10 -except ImportError: # Five 1.0
    2.11 -    from Products.Five.browser import EditView, Update
    2.12 +from zope.event import notify
    2.13 +from Products.Five.form import EditView, Update, applyWidgetsChanges
    2.14  from zope.app.form.interfaces import WidgetsError
    2.15  from zope.app.form.utility import setUpEditWidgets, applyWidgetsChanges
    2.16  from zope.app.event.objectevent import ObjectModifiedEvent
    2.17 @@ -87,12 +84,18 @@
    2.18              changed = applyWidgetsChanges(self, self.schema,
    2.19                  target=content, names=self.fieldNames)
    2.20              # We should not generate events when an adapter is used.
    2.21 -            # That's the adapter's job.
    2.22 -            if changed and self.context is self.adapted:
    2.23 +            # That's the adapter's job.  We need to unwrap the objects to
    2.24 +            # compare them, as they are wrapped differently.
    2.25 +            # Additionally, we can't use Acquisition.aq_base() because
    2.26 +            # it strangely returns different objects for these two even
    2.27 +            # when they are identical.  In particular
    2.28 +            # aq_base(self.adapted) != self.adapted.aq_base :-(
    2.29 +            if changed and getattr(self.context, 'aq_base', self.context)\
    2.30 +                        is getattr(self.adapted, 'aq_base', self.adapted):
    2.31                  notify(ObjectModifiedEvent(content))
    2.32          except WidgetsError, errors:
    2.33              self.errors = errors
    2.34 -            status = _("An error occured.")
    2.35 +            status = _("An error occurred.")
    2.36              transaction.abort()
    2.37          else:
    2.38              setUpEditWidgets(self, self.schema, source=self.adapted,
    2.39 @@ -100,19 +103,20 @@
    2.40                               names=self.fieldNames)
    2.41              if changed:
    2.42                  self.changed()
    2.43 -                # It's going to be very nice to drop Five 1.0.x support:
    2.44 +                # CPS Patch begins here.
    2.45                  localizer = getattr(self.context, 'Localizer', None)
    2.46 -                if localizer is not None:
    2.47 -                    
    2.48 +                if localizer is not None:                    
    2.49                      status = localizer.default("Updated on %(date_time)s")
    2.50                      format = str(localizer.default('date_medium'))
    2.51                      date = datetime.datetime.now().strftime(format)
    2.52 -                    status = status % {'date_time': date}
    2.53                  else:
    2.54 -                    status = _("Updated on ${date_time}")
    2.55 -                    status.mapping = {'date_time': str(datetime.utcnow())}
    2.56 +                    date = str(datetime.utcnow())
    2.57 +                    
    2.58 +                status = _("Updated on ${date_time}",
    2.59 +                           mapping={'date_time': date})
    2.60  
    2.61      self.update_status = status
    2.62 +
    2.63      return status
    2.64  
    2.65  from zope.i18n.interfaces import IUserPreferredLanguages, ILanguageAvailability