PyLint fixes
Moved credentials into new Config class
This commit is contained in:
parent
b124b48a75
commit
48e29f24a9
16 changed files with 277 additions and 218 deletions
|
@ -2,11 +2,12 @@ try:
|
|||
from urllib.parse import quote # Python3
|
||||
except ImportError:
|
||||
from urllib import quote # Python2
|
||||
from .errors import *
|
||||
|
||||
class OpenPhotoObject:
|
||||
""" Base object supporting the storage of custom fields as attributes """
|
||||
def __init__(self, openphoto, json_dict):
|
||||
self.id = None
|
||||
self.name = None
|
||||
self._openphoto = openphoto
|
||||
self._json_dict = json_dict
|
||||
self._set_fields(json_dict)
|
||||
|
@ -29,9 +30,9 @@ class OpenPhotoObject:
|
|||
self._set_fields(json_dict)
|
||||
|
||||
def __repr__(self):
|
||||
if hasattr(self, "name"):
|
||||
if self.name is not None:
|
||||
return "<%s name='%s'>" % (self.__class__, self.name)
|
||||
elif hasattr(self, "id"):
|
||||
elif self.id is not None:
|
||||
return "<%s id='%s'>" % (self.__class__, self.id)
|
||||
else:
|
||||
return "<%s>" % (self.__class__)
|
||||
|
@ -48,14 +49,15 @@ class Photo(OpenPhotoObject):
|
|||
Returns True if successful.
|
||||
Raises an OpenPhotoError if not.
|
||||
"""
|
||||
result = self._openphoto.post("/photo/%s/delete.json" % self.id, **kwds)["result"]
|
||||
result = self._openphoto.post("/photo/%s/delete.json" %
|
||||
self.id, **kwds)["result"]
|
||||
self._replace_fields({})
|
||||
return result
|
||||
|
||||
def edit(self, **kwds):
|
||||
""" Returns an HTML form to edit the photo """
|
||||
result = self._openphoto.get("/photo/%s/edit.json" % self.id,
|
||||
**kwds)["result"]
|
||||
result = self._openphoto.get("/photo/%s/edit.json" %
|
||||
self.id, **kwds)["result"]
|
||||
return result["markup"]
|
||||
|
||||
def replace(self, photo_file, **kwds):
|
||||
|
@ -66,8 +68,8 @@ class Photo(OpenPhotoObject):
|
|||
|
||||
def update(self, **kwds):
|
||||
""" Update this photo with the specified parameters """
|
||||
new_dict = self._openphoto.post("/photo/%s/update.json" % self.id,
|
||||
**kwds)["result"]
|
||||
new_dict = self._openphoto.post("/photo/%s/update.json" %
|
||||
self.id, **kwds)["result"]
|
||||
self._replace_fields(new_dict)
|
||||
|
||||
def view(self, **kwds):
|
||||
|
@ -75,8 +77,8 @@ class Photo(OpenPhotoObject):
|
|||
Used to view the photo at a particular size.
|
||||
Updates the photo's fields with the response.
|
||||
"""
|
||||
new_dict = self._openphoto.get("/photo/%s/view.json" % self.id,
|
||||
**kwds)["result"]
|
||||
new_dict = self._openphoto.get("/photo/%s/view.json" %
|
||||
self.id, **kwds)["result"]
|
||||
self._replace_fields(new_dict)
|
||||
|
||||
def dynamic_url(self, **kwds):
|
||||
|
@ -87,8 +89,8 @@ class Photo(OpenPhotoObject):
|
|||
Returns a dict containing the next and previous photo lists
|
||||
(there may be more than one next/previous photo returned).
|
||||
"""
|
||||
result = self._openphoto.get("/photo/%s/nextprevious.json" % self.id,
|
||||
**kwds)["result"]
|
||||
result = self._openphoto.get("/photo/%s/nextprevious.json" %
|
||||
self.id, **kwds)["result"]
|
||||
value = {}
|
||||
if "next" in result:
|
||||
# Workaround for APIv1
|
||||
|
@ -115,12 +117,13 @@ class Photo(OpenPhotoObject):
|
|||
Performs transformation specified in **kwds
|
||||
Example: transform(rotate=90)
|
||||
"""
|
||||
new_dict = self._openphoto.post("/photo/%s/transform.json" % self.id,
|
||||
**kwds)["result"]
|
||||
new_dict = self._openphoto.post("/photo/%s/transform.json" %
|
||||
self.id, **kwds)["result"]
|
||||
|
||||
# APIv1 doesn't return the transformed photo (frontend issue #955)
|
||||
if isinstance(new_dict, bool):
|
||||
new_dict = self._openphoto.get("/photo/%s/view.json" % self.id)["result"]
|
||||
new_dict = self._openphoto.get("/photo/%s/view.json" %
|
||||
self.id)["result"]
|
||||
|
||||
self._replace_fields(new_dict)
|
||||
|
||||
|
@ -131,7 +134,8 @@ class Tag(OpenPhotoObject):
|
|||
Returns True if successful.
|
||||
Raises an OpenPhotoError if not.
|
||||
"""
|
||||
result = self._openphoto.post("/tag/%s/delete.json" % quote(self.id), **kwds)["result"]
|
||||
result = self._openphoto.post("/tag/%s/delete.json" %
|
||||
quote(self.id), **kwds)["result"]
|
||||
self._replace_fields({})
|
||||
return result
|
||||
|
||||
|
@ -145,15 +149,17 @@ class Tag(OpenPhotoObject):
|
|||
class Album(OpenPhotoObject):
|
||||
def __init__(self, openphoto, json_dict):
|
||||
OpenPhotoObject.__init__(self, openphoto, json_dict)
|
||||
self.photos = None
|
||||
self.cover = None
|
||||
self._update_fields_with_objects()
|
||||
|
||||
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):
|
||||
if 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):
|
||||
if isinstance(self.photos, list):
|
||||
for i, photo in enumerate(self.photos):
|
||||
if isinstance(photo, dict):
|
||||
self.photos[i] = Photo(self._openphoto, photo)
|
||||
|
@ -164,7 +170,8 @@ class Album(OpenPhotoObject):
|
|||
Returns True if successful.
|
||||
Raises an OpenPhotoError if not.
|
||||
"""
|
||||
result = self._openphoto.post("/album/%s/delete.json" % self.id, **kwds)["result"]
|
||||
result = self._openphoto.post("/album/%s/delete.json" %
|
||||
self.id, **kwds)["result"]
|
||||
self._replace_fields({})
|
||||
return result
|
||||
|
||||
|
@ -179,12 +186,13 @@ class Album(OpenPhotoObject):
|
|||
|
||||
def update(self, **kwds):
|
||||
""" Update this album with the specified parameters """
|
||||
new_dict = self._openphoto.post("/album/%s/update.json" % self.id,
|
||||
**kwds)["result"]
|
||||
new_dict = self._openphoto.post("/album/%s/update.json" %
|
||||
self.id, **kwds)["result"]
|
||||
|
||||
# APIv1 doesn't return the updated album (frontend issue #937)
|
||||
if isinstance(new_dict, bool):
|
||||
new_dict = self._openphoto.get("/album/%s/view.json" % self.id)["result"]
|
||||
new_dict = self._openphoto.get("/album/%s/view.json" %
|
||||
self.id)["result"]
|
||||
|
||||
self._replace_fields(new_dict)
|
||||
self._update_fields_with_objects()
|
||||
|
@ -194,7 +202,7 @@ class Album(OpenPhotoObject):
|
|||
Requests the full contents of the album.
|
||||
Updates the album's fields with the response.
|
||||
"""
|
||||
result = self._openphoto.get("/album/%s/view.json" % self.id,
|
||||
**kwds)["result"]
|
||||
result = self._openphoto.get("/album/%s/view.json" %
|
||||
self.id, **kwds)["result"]
|
||||
self._replace_fields(result)
|
||||
self._update_fields_with_objects()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue