From 3c4f69f6470c0920df52c1c80632a51ec7c65809 Mon Sep 17 00:00:00 2001 From: Ethan Dalool Date: Fri, 16 Feb 2018 22:25:56 -0800 Subject: [PATCH] Specify name= on calls to PDB.get_tag. Sometimes it's easy to forget whether its the name or ID, and I like the consistency of specifying. --- etiquette/objects.py | 14 +++++++------- etiquette/photodb.py | 11 ++++------- .../etiquette_flask/etiquette_flask/common.py | 2 +- .../etiquette_flask/endpoints/tag_endpoints.py | 2 +- frontends/etiquette_repl.py | 2 +- 5 files changed, 14 insertions(+), 17 deletions(-) diff --git a/etiquette/objects.py b/etiquette/objects.py index 719dc11..5228a7d 100644 --- a/etiquette/objects.py +++ b/etiquette/objects.py @@ -322,7 +322,7 @@ class Album(ObjectBase, GroupableMixin): If True, add the tag to photos contained in sub-albums. Otherwise, only local photos. ''' - tag = self.photodb.get_tag(tag) + tag = self.photodb.get_tag(name=tag) if nested_children: photos = self.walk_photos() else: @@ -596,7 +596,7 @@ class Photo(ObjectBase): @decorators.required_feature('photo.add_remove_tag') @decorators.transaction def add_tag(self, tag, *, commit=True): - tag = self.photodb.get_tag(tag) + tag = self.photodb.get_tag(name=tag) existing = self.has_tag(tag, check_children=False) if existing: @@ -800,7 +800,7 @@ class Photo(ObjectBase): check_children: If True, children of the requested tag are accepted. ''' - tag = self.photodb.get_tag(tag) + tag = self.photodb.get_tag(name=tag) if check_children: tags = tag.walk_children() @@ -935,7 +935,7 @@ class Photo(ObjectBase): @decorators.required_feature('photo.add_remove_tag') @decorators.transaction def remove_tag(self, tag, *, commit=True): - tag = self.photodb.get_tag(tag) + tag = self.photodb.get_tag(name=tag) self.photodb.log.debug('Removing tag {t} from photo {p}'.format(t=repr(tag), p=repr(self))) tags = list(tag.walk_children()) @@ -1089,7 +1089,7 @@ class Tag(ObjectBase, GroupableMixin): raise exceptions.CantSynonymSelf() try: - existing_tag = self.photodb.get_tag_by_name(synname) + existing_tag = self.photodb.get_tag(name=synname) except exceptions.NoSuchTag: pass else: @@ -1122,7 +1122,7 @@ class Tag(ObjectBase, GroupableMixin): Good for when two tags need to be merged under a single name. ''' - mastertag = self.photodb.get_tag(mastertag) + mastertag = self.photodb.get_tag(name=mastertag) # Migrate the old tag's synonyms to the new one # UPDATE is safe for this operation because there is no chance of duplicates. @@ -1279,7 +1279,7 @@ class Tag(ObjectBase, GroupableMixin): return try: - existing_tag = self.photodb.get_tag(new_name) + existing_tag = self.photodb.get_tag(name=new_name) except exceptions.NoSuchTag: pass else: diff --git a/etiquette/photodb.py b/etiquette/photodb.py index d4ee673..a0613e2 100644 --- a/etiquette/photodb.py +++ b/etiquette/photodb.py @@ -293,7 +293,7 @@ class PDBPhotoMixin: photo.generate_thumbnail(commit=False) tags = tags or [] - tags = [self.get_tag(tag) for tag in tags] + tags = [self.get_tag(name=tag) for tag in tags] for tag in tags: photo.add_tag(tag, commit=False) @@ -790,9 +790,6 @@ class PDBUserMixin: raise exceptions.PasswordTooShort(min_length=self.config['user']['min_password_length']) def _assert_valid_username(self, username): - ''' - If something is wrong, raise an exception. Otherwise do nothing. - ''' if len(username) < self.config['user']['min_length']: raise exceptions.UsernameTooShort( username=username, @@ -1183,10 +1180,10 @@ class PhotoDB(PDBAlbumMixin, PDBBookmarkMixin, PDBPhotoMixin, PDBTagMixin, PDBUs def create_or_get(name): #print('cog', name) try: - item = self.get_tag(name) + item = self.get_tag(name=name) note = ('existing_tag', item.qualified_name()) except exceptions.NoSuchTag: - item = self.new_tag(name) + item = self.new_tag(name=name) note = ('new_tag', item.qualified_name()) output_notes.append(note) return item @@ -1221,7 +1218,7 @@ class PhotoDB(PDBAlbumMixin, PDBBookmarkMixin, PDBPhotoMixin, PDBTagMixin, PDBUs raise exceptions.EasyBakeError('No tag supplied') if rename_to: - tag = self.get_tag(tag) + tag = self.get_tag(name=tag) old_name = tag.name tag.rename(rename_to) note = ('rename', '%s=%s' % (old_name, tag.name)) diff --git a/frontends/etiquette_flask/etiquette_flask/common.py b/frontends/etiquette_flask/etiquette_flask/common.py index 7e51c6f..9ffe8a3 100644 --- a/frontends/etiquette_flask/etiquette_flask/common.py +++ b/frontends/etiquette_flask/etiquette_flask/common.py @@ -77,7 +77,7 @@ def P_photo(photo_id): @P_wrapper def P_tag(tagname): - return P.get_tag(tagname) + return P.get_tag(name=tagname) @P_wrapper def P_user(username): diff --git a/frontends/etiquette_flask/etiquette_flask/endpoints/tag_endpoints.py b/frontends/etiquette_flask/etiquette_flask/endpoints/tag_endpoints.py index 4db4ba5..3074893 100644 --- a/frontends/etiquette_flask/etiquette_flask/endpoints/tag_endpoints.py +++ b/frontends/etiquette_flask/etiquette_flask/endpoints/tag_endpoints.py @@ -130,7 +130,7 @@ def post_tag_delete(): ''' tagname = request.form['tagname'] tagname = tagname.split('.')[-1].split('+')[0] - tag = common.P.get_tag(tagname) + tag = common.P.get_tag(name=tagname) tag.delete() response = {'action': 'delete_tag', 'tagname': tag.name} diff --git a/frontends/etiquette_repl.py b/frontends/etiquette_repl.py index c9d238c..ac3f5a6 100644 --- a/frontends/etiquette_repl.py +++ b/frontends/etiquette_repl.py @@ -22,7 +22,7 @@ def easytagger(): if i.startswith('?'): i = i.split('?')[1] or None try: - etiquette.tag_export.stdout([P.get_tag(i)]) + etiquette.tag_export.stdout([P.get_tag(name=i)]) except: traceback.print_exc() else: