コード例 #1
0
    def deserialize(self, data, instance=None):
        partial = bool(instance)
        unmarshal_result = self.context['schema_class'](partial=partial).load(
            data, instance=instance)
        if unmarshal_result.errors:
            raise APIError(400, extra=unmarshal_result.errors)

        return unmarshal_result.data
コード例 #2
0
 def check_permission(self, instance=None):
     if self.get_instance_from_context(
             'framework').get_request_method() not in self.SAFE_METHODS:
         raise APIError(403)
コード例 #3
0
 def check_permission(self, instance=None):
     if self.context['current_user'] is None:
         raise APIError(401)
コード例 #4
0
 def handled_exception(self):
     raise APIError(499, {'detail': 'Now this is a weird HTTP code'})
コード例 #5
0
 def get_object(self, queryset, pk):
     try:
         return queryset.get(pk=pk)
     except ObjectDoesNotExist:
         raise APIError(404)
コード例 #6
0
 def get_object(self, queryset, pk):
     try:
         return queryset.filter(id=pk).get()
     except DoesNotExist:
         raise APIError(404)
コード例 #7
0
 def get_object(self, queryset, pk):
     try:
         return queryset.filter_by(id=pk).one()
     except NoResultFound:
         raise APIError(404)