Commits

Jesper Nøhr  committed 7042cd3

bit of tweaking to content-type detection and default create method

  • Participants
  • Parent commits 6c26142

Comments (0)

Files changed (3)

File piston/emitters.py

     
     def method_fields(self, data, fields):
         if not data:
-            return data
+            return { }
 
         has = dir(data)
         ret = dict()

File piston/handler.py

             inst = self.model(**attrs)
             inst.save()
             return inst
+        except self.model.MultipleObjectsReturned:
+            return rc.DUPLICATE_ENTRY
     
     def update(self, request, *args, **kwargs):
         # TODO: This doesn't work automatically yet.

File piston/utils.py

                 return loadee
 
     def content_type(self):
-        return self.request.META.get('CONTENT_TYPE')
+        return self.request.META.get('CONTENT_TYPE', None)
 
     def translate(self):
         """
         None for multipart form data (what your browser sends.)
         """    
         ctype = self.content_type()
+        self.request.content_type = ctype
         
         if not self.is_multipart() and ctype:
             loadee = self.loader_for_type(ctype)
             
             try:
-                self.request.content_type = ctype
                 self.request.data = loadee(self.request.raw_post_data)
                 
                 # Reset both POST and PUT from request, as its