def validate(converter, val): if isinstance(val, datetime): return val.date() if isinstance(val, date): return val if isinstance(val, basestring): return str2date(val) throw( TypeError, "Attribute %r: expected type is 'date'. Got: %r" % (converter.attr, val))
def _get_value(field): value = BaseWidget._get_value(field) if not value: return None try: return str2date(value) except: field._auto_error_text = html('@{Incorrect date}') return None
% {"attribute": attribute, "value": ",".join(v for v in value)}, "range": lambda attribute, value: "%(attribute)s >= %(v0)s and (attribute)s <= %(v1)s" % {"attribute": attribute, "v0": value[0], "v1": value[1]}, # TODO: implement # 'week_day', 'regex','isearch', 'search', 'iregex', 'regex', } NONE_REPR = set(["None", "none", "Null", "null"]) TRUE_REPR = set(["true", "True", "yes", "Yes"]) FALSE_REPR = set(["false", "False", "no", "No"]) QUERY_TERM_CONVERT_VALUE = { bool: lambda x: None if x in NONE_REPR else True if x in TRUE_REPR else False if x in FALSE_REPR else x, int: lambda x: None if x in NONE_REPR else int(x), long: lambda x: None if x in NONE_REPR else long(x), datetime.date: lambda x: None if x in NONE_REPR else str2date(x), datetime.datetime: lambda x: None if x in NONE_REPR else str2datetime(x), datetime.time: lambda x: None if x in NONE_REPR else str2time(x), datetime.timedelta: lambda x: None if x in NONE_REPR else datetime.timedelta(0, x), str: lambda x: None if x in NONE_REPR else x.encode("utf-8"), unicode: lambda x: None if x in NONE_REPR else x, decimal.Decimal: lambda x: None if x in NONE_REPR else decimal.Decimal(x), float: lambda x: None if x in NONE_REPR else float(x), } class DjonyDeclarativeMetaclass(DeclarativeMetaclass): def __new__(cls, name, bases, attrs): new_class = super(DjonyDeclarativeMetaclass, cls).__new__(cls, name, bases, attrs) include_fields = getattr(new_class._meta, "fields", []) excludes = getattr(new_class._meta, "excludes", [])
def validate(converter, val): if isinstance(val, datetime): return val.date() if isinstance(val, date): return val if isinstance(val, basestring): return str2date(val) throw(TypeError, "Attribute %r: expected type is 'date'. Got: %r" % (converter.attr, val))
'isnull':lambda attribute,value: ('%(attribute)s is None' if value == 'True' else 'not (%(attribute)s is None)') % {'attribute':attribute,'value':value}, 'in':lambda attribute,value:'%(attribute)s in (%(value)s)' % { 'attribute':attribute,'value':','.join(v for v in value)}, 'range':lambda attribute,value:'%(attribute)s >= %(v0)s and (attribute)s <= %(v1)s' % { 'attribute':attribute,'v0':value[0],'v1':value[1]}, # TODO: implement # 'week_day', 'regex','isearch', 'search', 'iregex', 'regex', } NONE_REPR = set(['None','none','Null','null']) TRUE_REPR = set(['true','True','yes','Yes']) FALSE_REPR = set(['false','False','no','No']) QUERY_TERM_CONVERT_VALUE = { bool:lambda x: None if x in NONE_REPR else True if x in TRUE_REPR else False if x in FALSE_REPR else x, int:lambda x: None if x in NONE_REPR else int(x), long:lambda x: None if x in NONE_REPR else long(x), datetime.date:lambda x: None if x in NONE_REPR else str2date(x), datetime.datetime:lambda x: None if x in NONE_REPR else str2datetime(x), datetime.time:lambda x: None if x in NONE_REPR else str2time(x), datetime.timedelta:lambda x: None if x in NONE_REPR else datetime.timedelta(0,x), str:lambda x: None if x in NONE_REPR else x.encode('utf-8'), unicode:lambda x: None if x in NONE_REPR else x, decimal.Decimal: lambda x: None if x in NONE_REPR else decimal.Decimal(x), float: lambda x: None if x in NONE_REPR else float(x), } class DjonyDeclarativeMetaclass(DeclarativeMetaclass): def __new__(cls, name, bases, attrs): new_class = super(DjonyDeclarativeMetaclass, cls).__new__(cls, name, bases, attrs) include_fields = getattr(new_class._meta, 'fields', []) excludes = getattr(new_class._meta, 'excludes', []) object_model = getattr(new_class._meta, 'object_model', None)