Exemple #1
0
def my_exception_handler(exc, context):  # 200 will never be here
    # Call REST framework's default exception handler first,
    # to get the standard error response.
    response = exception_handler(exc, context)

    if response is None:  # force 500 to 200, for the same error msg format
        exc_info = sys.exc_info()
        LOG.exception(exc)
        return Response({'error_code': 500, 'error': u'服务器繁忙,请稍后再试'})

    # add the HTTP status code to the response & force 200
    return Response({
        'error_code': response.status_code,
        'error': response.data.get('detail')
    })
Exemple #2
0
def comment_page(request, page_id):
    page = get_object_or_404(Page, id=page_id)
    if request.method == 'POST':
        content = request.POST.getlist('content')
        try:
            comment = PageComment(user=request.user, content=content)
        except Exception, e:
            LOG.exception(e)
            messages.error(request, _(u'输入错误,请重新输入'))
        else:
            for c in comments:
                c.save()
            order.comment_time = django_now()
            order.save()
            messages.success(request, _(u'评论完成,已经添加到产品详细页面中。'))
            return redirect('/order/%s/' % order_id)
Exemple #3
0
 def put(self, request):
     '''
     Load request data into request.PUT
     refs: https://bitbucket.org/jespern/django-piston/src/c4b2d21db51a/piston/utils.py
     '''
     if hasattr(request, '_post'):
         del request._post
         del request._files
     
     try:
         request.method = 'POST'
         request._load_post_and_files()
         request.method = 'PUT'
     except AttributeError, e:
         LOG.exception(e)
         request.META['REQUEST_METHOD'] = 'POST'
         request._load_post_and_files()
         request.META['REQUEST_METHOD'] = 'PUT'