time_from = lambda x : datetime.fromtimestamp(long(x is not None and x or '0')) time_to = lambda x : x is not None and datetime.fromtimestamp(long(x)) or datetime.now() void = lambda x : x def param(key, default, validate): def decorator(view_func): @wraps(view_func, assigned = available_attrs(view_func)) def _wrapped_view(request, *args, **kwargs): try: value = request.REQUEST.get(key, default) value = validate(value) if hasattr(request, 'DATA'): dct = getattr(request, 'DATA') dct.update({key : value}) else: dct = {key: value} setattr(request, 'DATA', dct) except ValueError, e: return JsonResponse(error = -3, error_msg = u'参数%s格式错误' % key) except TypeError, e: return JsonResponse(error = -4, error_msg = u'参数%s不能为空' % key) return view_func(request, *args, **kwargs) return _wrapped_view return decorator