Пример #1
0
 def fillItemFromForm(self):
     """Automatically fill the item field values from the corresponding form widgets.
     """
     catalogItem = self._catalogItem
     for field in catalogItem.__class__:
         fieldName = field.name
         widget = getattr(self, fieldName, None)
         if widget:
             fieldValue = forms.getValue(widget)
             if isinstance(field, orm.IdField) and not fieldValue: # if nothing is entered into Id field - treat it as NULL
                 fieldValue = None
             elif isinstance(field, orm.DateTimeField):
                 if any(char.isdigit() for char in fieldValue):
                     fieldValue = DateTime.strptime(fieldValue, '%Y-%m-%d %H:%M:%S.%f')
                 else:
                     fieldValue = None
             setattr(catalogItem, fieldName, fieldValue)
Пример #2
0
 def date(self):
     """Return the date entered in the field. If it is empty or invalid - `None` is returned."""
     try:
         return DateTime.strptime(self.text(), '%d.%m.%Y').date()
     except ValueError:
         return None