Small refactor of code that automatically converts returned dicts into objects for Album commands.
Add comments to handle API change when/if frontend issue number 937 lands
This commit is contained in:
parent
f3c48d4f43
commit
854c4fd605
2 changed files with 23 additions and 12 deletions
|
@ -39,7 +39,10 @@ class ApiAlbum:
|
||||||
if not isinstance(album, Album):
|
if not isinstance(album, Album):
|
||||||
album = Album(self._client, {"id": album})
|
album = Album(self._client, {"id": album})
|
||||||
album.update(**kwds)
|
album.update(**kwds)
|
||||||
# Don't return the album, since the API doesn't give us the modified album
|
|
||||||
|
# Don't return the album, since the API currently doesn't give us the modified album
|
||||||
|
# Uncomment the following once frontend issue #937 is resolved
|
||||||
|
# return album
|
||||||
|
|
||||||
def view(self, album, **kwds):
|
def view(self, album, **kwds):
|
||||||
"""
|
"""
|
||||||
|
|
|
@ -104,9 +104,18 @@ class Tag(OpenPhotoObject):
|
||||||
class Album(OpenPhotoObject):
|
class Album(OpenPhotoObject):
|
||||||
def __init__(self, openphoto, json_dict):
|
def __init__(self, openphoto, json_dict):
|
||||||
OpenPhotoObject.__init__(self, openphoto, json_dict)
|
OpenPhotoObject.__init__(self, openphoto, json_dict)
|
||||||
# Update the cover attribute with a photo object
|
self._update_fields_with_objects()
|
||||||
if hasattr(self, "cover") and self.cover is not None:
|
|
||||||
self.cover = Photo(openphoto, self.cover)
|
def _update_fields_with_objects(self):
|
||||||
|
""" Convert dict fields into objects, where appropriate """
|
||||||
|
# Update the cover with a photo object
|
||||||
|
if hasattr(self, "cover") and isinstance(self.cover, dict):
|
||||||
|
self.cover = Photo(self._openphoto, self.cover)
|
||||||
|
# Update the photo list with photo objects
|
||||||
|
if hasattr(self, "photos") and isinstance(self.photos, list):
|
||||||
|
for i, photo in enumerate(self.photos):
|
||||||
|
if isinstance(photo, dict):
|
||||||
|
self.photos[i] = Photo(self._openphoto, photo)
|
||||||
|
|
||||||
def delete(self, **kwds):
|
def delete(self, **kwds):
|
||||||
""" Delete this album """
|
""" Delete this album """
|
||||||
|
@ -124,12 +133,16 @@ class Album(OpenPhotoObject):
|
||||||
|
|
||||||
def update(self, **kwds):
|
def update(self, **kwds):
|
||||||
""" Update this album with the specified parameters """
|
""" Update this album with the specified parameters """
|
||||||
self._openphoto.post("/album/%s/update.json" % self.id,
|
new_dict = self._openphoto.post("/album/%s/update.json" % self.id,
|
||||||
**kwds)["result"]
|
**kwds)["result"]
|
||||||
|
|
||||||
# Since the API doesn't give us the modified album, we need to
|
# Since the API doesn't give us the modified album, we need to
|
||||||
# update our fields based on the kwds that were sent
|
# update our fields based on the kwds that were sent
|
||||||
self._set_fields(kwds)
|
self._set_fields(kwds)
|
||||||
|
|
||||||
|
# Replace the above line with the below once frontend issue #937 is resolved
|
||||||
|
# self._set_fields(new_dict)
|
||||||
|
# self._update_fields_with_objects()
|
||||||
|
|
||||||
def view(self, **kwds):
|
def view(self, **kwds):
|
||||||
"""
|
"""
|
||||||
|
@ -138,10 +151,5 @@ class Album(OpenPhotoObject):
|
||||||
"""
|
"""
|
||||||
result = self._openphoto.get("/album/%s/view.json" % self.id,
|
result = self._openphoto.get("/album/%s/view.json" % self.id,
|
||||||
**kwds)["result"]
|
**kwds)["result"]
|
||||||
# Update the cover attribute with a photo object
|
|
||||||
if result["cover"] is not None:
|
|
||||||
result["cover"] = Photo(self._openphoto, result["cover"])
|
|
||||||
# Update the photo list with photo objects
|
|
||||||
for i, photo in enumerate(result["photos"]):
|
|
||||||
result["photos"][i] = Photo(self._openphoto, result["photos"][i])
|
|
||||||
self._replace_fields(result)
|
self._replace_fields(result)
|
||||||
|
self._update_fields_with_objects()
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue