Beispiel #1
0
 def validate(self, value, model_instance):
     value = super(DateTimeProperty, self).validate(value, model_instance)
     
     if isinstance(value, str) or isinstance(value, unicode):
         if not strutil.is_datetime(value, fmt=self.fmt):
             raise TypeDatetimeError(self.get_label_i18n_key())
         else:
             value = strutil.to_datetime(value, fmt=self.fmt)
     
     if value and not isinstance(value, self.data_type):
         raise CoreError('Property %s must be a %s' % 
                           (self.name, self.data_type.__name__))
     return value
Beispiel #2
0
 def _get_datetime_parameter(self, name, fmt, default=None):
     value = self._get_str_parameter(name)
     return strutil.to_datetime(value, fmt=fmt, default=default)
Beispiel #3
0
 def normalize_value(self, value):
     if isinstance(value, datetime.datetime):
         return value
     else:
         return strutil.to_datetime(value, fmt=self.fmt)