Changeset 8152 for main


Ignore:
Timestamp:
14 Apr 2012, 14:13:39 (13 years ago)
Author:
uli
Message:
  • Add new default date widgets for different date formats.
  • In FormattedDateWidgets? use own default also, if no date format was set with the connected schema field. In former implementation we expected always a valid date_format from connected schema field or no date_format at all. But as FormattedDate? schema fields now may also return None as date_format, which means that the date_format was not set at all in the interface, we can override this value with respective default values.

As a result, when setting no date_format in an interface with
FormattedDate? schema fields and when rendered with one of the
FormattedDateWidgets?, the default format of the respective widget
will be used to render the value: %d.%m.%Y for german dates, etc.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • main/waeup.kofa/trunk/src/waeup/kofa/widgets/datewidget.py

    r8150 r8152  
    9090    def __init__(self, context, request, *args, **kw):
    9191        # try to grab date_format and show_year from bound schema field.
    92         self.date_format = getattr(context, 'date_format', self.date_format)
     92        date_format = getattr(context, 'date_format', self.date_format)
     93        if date_format is not None:
     94            self.date_format = date_format
    9395        self.show_year = getattr(context, 'show_year', self.show_year)
    9496        # add css class determined by date_format and show_year
     
    136138    def __init__(self, context, request, *args, **kw):
    137139        # try to grab date_format and show_year from bound schema field.
    138         self.date_format = getattr(context, 'date_format', self.date_format)
     140        date_format = getattr(context, 'date_format', self.date_format)
     141        if date_format is not None:
     142            self.date_format = date_format
    139143        self.show_year = getattr(context, 'show_year', self.show_year)
    140144        return super(FormattedDateDisplayWidget, self).__init__(
     
    152156                             cssClass=self.cssClass)
    153157
     158class DateLEWidget(FormattedDateWidget):
     159    date_format = '%d/%m/%Y'
     160
     161class DateDEWidget(FormattedDateWidget):
     162    date_format = '%d.%m.%Y'
     163
     164class DateUSWidget(FormattedDateWidget):
     165    date_format = '%m/%d/%Y'
     166
     167class DateLEDisplayWidget(FormattedDateDisplayWidget):
     168    date_format = '%d/%m/%Y'
     169
     170class DateDEDisplayWidget(FormattedDateDisplayWidget):
     171    date_format = '%d.%m.%Y'
     172
     173class DateUSDisplayWidget(FormattedDateDisplayWidget):
     174    date_format = '%m/%d/%Y'
     175
    154176def FriendlyDateWidget(format):
    155177    """Get a friendly date input widget for `format`.
Note: See TracChangeset for help on using the changeset viewer.