def view_order(request, order_id): form = OrderViewForm({'order_id' : order_id}) if not form.is_valid(): return response_error('%s' % form.errors,) return response_success(params={'order': form.cleaned_data['order_id'].output})
def create_order(request): form = OrderCreateForm(request.POST) if not form.is_valid(): return response_error('%s' % form.errors,) Order().create_order(form.cleaned_data[REQ_CREATE_ORDER.PRODUCTS_ID]) params = {'status': 'created'} return response_success(params=params)
def inner(request, *args, **kwargs): try: response = view_func(request, *args, **kwargs) except AssertionError as e: return response_error(unicode(e.args[0])) except Exception as ex: logger_error = { 'func_name' : view_func.func_name, 'module' : 'api_view_500', 'request_body' : request.body if hasattr(request, 'body') else 'empty', 'request_post' : request.POST, 'request_get' : request.GET, 'message_error' : str(ex), } #todo logger(logger_error) if DEBUG: print logger_error print traceback.format_exc() raise ex if output == 'json_400': return HttpResponse(json.dumps({"err": "Unknown error.", "code": 400})) return response_error(u'Непредвиденная ошибка') return response