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.
This commit is contained in:
parent
16ac6f8b85
commit
3c4f69f647
5 changed files with 14 additions and 17 deletions
|
@ -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:
|
||||
|
|
|
@ -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))
|
||||
|
|
|
@ -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):
|
||||
|
|
|
@ -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}
|
||||
|
|
|
@ -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:
|
||||
|
|
Loading…
Reference in a new issue