Commits

Jesper Nøhr committed 5dda441

using bitwise permission scheme for repository permissions in API, adding accessible_to to Repository (returns these bits), HTTP 400 on immediate form validation

Comments (0)

Files changed (2)

piston/resource.py

         
         try:
             result = meth(request, *args, **kwargs)
-        except FormValidationError, errors:
-            return HttpResponse("errors: %r" % errors)
+        except FormValidationError, form:
+            return HttpResponse("Bad Request: %s" % form.errors, status=400)
         except Exception, e:
             result = e
         
     """
     ALL_OK = create_reply('OK', status=200)
     CREATED = create_reply('Created', status=201)
-    DELETED = create_reply('No Content', status=204)
+    DELETED = create_reply('', status=204) # 204 says "Don't send a body!"
     FORBIDDEN = create_reply('Forbidden', status=401)
     DUPLICATE_ENTRY = create_reply('Conflict', status=409)
     NOT_HERE = create_reply('Gone', status=410)
     NOT_IMPLEMENTED = create_reply('Not Implemented', status=501)
     
 class FormValidationError(Exception):
-    pass
+    def __init__(self, form):
+        self.form = form
 
 class HttpStatusCode(Exception):
     def __init__(self, message, code=200):
         self.message = message
         self.code = code
 
-def validate(form, operation='POST'):
+def validate(v_form, operation='POST'):
     def dec(func):
         def wrap(self, request, *a, **kwa):
-            f = form(getattr(request, operation))
+            form = v_form(getattr(request, operation))
 
-            if f.is_valid():
-                kwa.update({'form':f})
+            if form.is_valid():
+                kwa.update({ 'form': form })
                 return func(self, request, *a, **kwa)
             else:
-                raise FormValidationError(f.errors)
+                raise FormValidationError(form)
                                 
         return wrap
     return dec