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

Commit

Permalink
updated dict unpacking
Browse files Browse the repository at this point in the history
  • Loading branch information
vforgione committed Aug 31, 2015
1 parent 4d84f38 commit 348babf
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 15 deletions.
5 changes: 2 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
*.py[co]

.Python
bin
include
lib

dist
*.egg-info
*.egg-info
.idea/
4 changes: 2 additions & 2 deletions djbetty/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
__version__ = "0.2.0"
__version__ = "0.2.1"

from .fields import ImageField # noqa
from .fields import ImageField # noqa
26 changes: 16 additions & 10 deletions djbetty/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,22 @@
class ImageFieldSerializer(serializers.Field):

def to_representation(self, obj):
if obj is None or obj.id is None:
return None
data = {
"id": obj.id,
}
if obj.field.alt_field:
data["alt"] = obj.alt

if obj.field.caption_field:
data["caption"] = obj.caption
if isinstance(obj, dict):
data = {
"id": obj.get("id"),
"alt": obj.get("alt"),
"caption": obj.get("caption")
}
else:
if obj is None or obj.id is None:
return None
data = {
"id": obj.id,
}
if obj.field.alt_field:
data["alt"] = obj.alt
if obj.field.caption_field:
data["caption"] = obj.caption
return data

def to_internal_value(self, data):
Expand Down

0 comments on commit 348babf

Please sign in to comment.