Changeset 8150


Ignore:
Timestamp:
13 Apr 2012, 21:44:00 (13 years ago)
Author:
uli
Message:

Register FormattedDateDisplayWidget? for FormattedDate? schema type.

Location:
main/waeup.kofa/trunk/src/waeup/kofa
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • main/waeup.kofa/trunk/src/waeup/kofa/applicants/browser.py

    r8149 r8150  
    382382    form_fields = grok.AutoFields(IApplicant).omit(
    383383        'locked', 'course_admitted', 'password')
    384     form_fields['date_of_birth'].custom_widget = FriendlyDateDisplayWidget('le')
    385384    label = _('Applicant')
    386385    pnav = 3
  • main/waeup.kofa/trunk/src/waeup/kofa/utils/overrides.zcml

    r8148 r8150  
    2525      />
    2626
     27  <adapter
     28      for="waeup.kofa.schema.interfaces.IFormattedDate
     29           zope.publisher.interfaces.browser.IBrowserRequest"
     30      provides="zope.formlib.interfaces.IDisplayWidget"
     31      factory="waeup.kofa.widgets.datewidget.FormattedDateDisplayWidget"
     32      permission="zope.Public"
     33      />
     34
    2735</configure>
  • main/waeup.kofa/trunk/src/waeup/kofa/widgets/datewidget.py

    r8147 r8150  
    9292        self.date_format = getattr(context, 'date_format', self.date_format)
    9393        self.show_year = getattr(context, 'show_year', self.show_year)
    94         self.cssClass = FORMATS_BY_VALUE.get((
    95             self.date_format, self.show_year), self.cssClass)
     94        # add css class determined by date_format and show_year
     95        css_cls = FORMATS_BY_VALUE.get((self.date_format, self.show_year), '')
     96        self.cssClass = ' '.join([self.cssClass, css_cls]).strip()
    9697        return super(FormattedDateWidget, self).__init__(
    9798            context, request, *args, **kw)
     
    122123        return value
    123124
     125
    124126class FormattedDateDisplayWidget(DateDisplayWidget):
    125127    """A date widget that supports different (and _explicit_) date formats.
     
    128130    """
    129131    date_format = '%Y-%m-%d'
     132    show_year = False
     133
    130134    implements(IDisplayWidget)
     135
     136    def __init__(self, context, request, *args, **kw):
     137        # try to grab date_format and show_year from bound schema field.
     138        self.date_format = getattr(context, 'date_format', self.date_format)
     139        self.show_year = getattr(context, 'show_year', self.show_year)
     140        return super(FormattedDateDisplayWidget, self).__init__(
     141            context, request, *args, **kw)
    131142
    132143    def __call__(self):
Note: See TracChangeset for help on using the changeset viewer.