From bb5fa816d8fdb8421b877d4bc5dffbcc182f6efc Mon Sep 17 00:00:00 2001 From: Ethan Dalool Date: Sat, 11 Nov 2017 22:41:26 -0800 Subject: [PATCH] Cleanup: Rename GroupableMixin.add to add_child for clarity. Especially since for albums it might sound like you're adding a photo. --- etiquette/objects.py | 15 ++++++++------- etiquette/photodb.py | 2 +- .../etiquette_flask/etiquette_flask.py | 2 +- 3 files changed, 10 insertions(+), 9 deletions(-) diff --git a/etiquette/objects.py b/etiquette/objects.py index a0846ce..a235df6 100644 --- a/etiquette/objects.py +++ b/etiquette/objects.py @@ -48,7 +48,7 @@ class GroupableMixin: group_table = None @decorators.transaction - def add(self, member, *, commit=True): + def add_child(self, member, *, commit=True): ''' Add a child object to this group. Child must be of the same type as the calling object. @@ -175,7 +175,7 @@ class GroupableMixin: @decorators.transaction def join_group(self, group, *, commit=True): ''' - Leave the current group, then call `group.add(self)`. + Leave the current group, then call `group.add_child(self)`. ''' if not isinstance(group, type(self)): raise TypeError('Group must also be %s' % type(self)) @@ -184,7 +184,7 @@ class GroupableMixin: raise ValueError('Cant join self') self.leave_group(commit=commit) - group.add(self, commit=commit) + group.add_child(self, commit=commit) @decorators.transaction def leave_group(self, *, commit=True): @@ -222,6 +222,7 @@ class Album(ObjectBase, GroupableMixin): super().__init__(photodb) if isinstance(db_row, (list, tuple)): db_row = dict(zip(constants.SQL_ALBUM_COLUMNS, db_row)) + self.id = db_row['id'] self.title = db_row['title'] or '' self.description = db_row['description'] or '' @@ -242,8 +243,8 @@ class Album(ObjectBase, GroupableMixin): self._sum_bytes_albums = None @decorators.required_feature('album.edit') - def add(self, *args, **kwargs): - return super().add(*args, **kwargs) + def add_child(self, *args, **kwargs): + return super().add_child(*args, **kwargs) @decorators.required_feature('album.edit') @decorators.transaction @@ -1014,8 +1015,8 @@ class Tag(ObjectBase, GroupableMixin): self._cached_qualified_name = None @decorators.required_feature('tag.edit') - def add(self, *args, **kwargs): - return super().add(*args, **kwargs) + def add_child(self, *args, **kwargs): + return super().add_child(*args, **kwargs) @decorators.required_feature('tag.edit') @decorators.transaction diff --git a/etiquette/photodb.py b/etiquette/photodb.py index d97b9fb..091d92d 100644 --- a/etiquette/photodb.py +++ b/etiquette/photodb.py @@ -1258,7 +1258,7 @@ class PhotoDB(PDBAlbumMixin, PDBBookmarkMixin, PDBPhotoMixin, PDBTagMixin, PDBUs parent = albums.get(current_location.parent.absolute_path, None) if parent is not None: try: - parent.add(current_album, commit=False) + parent.add_child(current_album, commit=False) except exceptions.GroupExists: pass for photo in new_photos: diff --git a/frontends/etiquette_flask/etiquette_flask/etiquette_flask.py b/frontends/etiquette_flask/etiquette_flask/etiquette_flask.py index 6a94ab5..3a0c7a5 100644 --- a/frontends/etiquette_flask/etiquette_flask/etiquette_flask.py +++ b/frontends/etiquette_flask/etiquette_flask/etiquette_flask.py @@ -534,7 +534,7 @@ def post_albums_create(): response = jsonify.make_json_response(response, status=400) flask.abort(response) if parent is not None: - parent.add(album) + parent.add_child(album) response = etiquette.jsonify.album(album, minimal=False) return jsonify.make_json_response(response)