Skip to content
This repository has been archived by the owner on Feb 24, 2021. It is now read-only.

Commit

Permalink
v0.9.4
Browse files Browse the repository at this point in the history
  • Loading branch information
deepera-yding committed Sep 4, 2017
1 parent 7161f55 commit fff2b8c
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions deeputils/serializers.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import json
from json.decoder import JSONDecodeError

from deeputils.exceptions import *
from django.core.exceptions import ObjectDoesNotExist
from django.core.exceptions import ValidationError
from django.db import models
from rest_framework import serializers
from rest_framework.exceptions import NotFound, NotAuthenticated
from rest_framework.serializers import empty


Expand All @@ -16,7 +16,7 @@ def validate_id(model, account, oid, allow_none=True):
if getattr(model, 'public', False) and obj.public is True:
pass
elif account is not None and obj.account != account:
raise serializers.ValidationError(Unauthorized.default_detail)
raise serializers.ValidationError(NotAuthenticated.default_detail)
except ObjectDoesNotExist:
raise serializers.ValidationError(NotFound.default_detail)
elif not allow_none:
Expand All @@ -32,7 +32,7 @@ def run_validation(self, data=empty):
except JSONDecodeError:
raise ValidationError("Data is not in JSON type.")
return super().run_validation(data)

def to_representation(self, data):
return json.loads(data) if data is not None else None

Expand Down Expand Up @@ -117,7 +117,7 @@ def validate_id(self, value):
if value is not None:
try:
self.model.objects.get(pk=value)
raise serializers.ValidationError(Conflict.default_detail)
raise serializers.ValidationError('Content is conflict.')
except ObjectDoesNotExist:
pass
return value
Expand Down

0 comments on commit fff2b8c

Please sign in to comment.