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.
|
If True, add the tag to photos contained in sub-albums.
|
||||||
Otherwise, only local photos.
|
Otherwise, only local photos.
|
||||||
'''
|
'''
|
||||||
tag = self.photodb.get_tag(tag)
|
tag = self.photodb.get_tag(name=tag)
|
||||||
if nested_children:
|
if nested_children:
|
||||||
photos = self.walk_photos()
|
photos = self.walk_photos()
|
||||||
else:
|
else:
|
||||||
|
@ -596,7 +596,7 @@ class Photo(ObjectBase):
|
||||||
@decorators.required_feature('photo.add_remove_tag')
|
@decorators.required_feature('photo.add_remove_tag')
|
||||||
@decorators.transaction
|
@decorators.transaction
|
||||||
def add_tag(self, tag, *, commit=True):
|
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)
|
existing = self.has_tag(tag, check_children=False)
|
||||||
if existing:
|
if existing:
|
||||||
|
@ -800,7 +800,7 @@ class Photo(ObjectBase):
|
||||||
check_children:
|
check_children:
|
||||||
If True, children of the requested tag are accepted.
|
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:
|
if check_children:
|
||||||
tags = tag.walk_children()
|
tags = tag.walk_children()
|
||||||
|
@ -935,7 +935,7 @@ class Photo(ObjectBase):
|
||||||
@decorators.required_feature('photo.add_remove_tag')
|
@decorators.required_feature('photo.add_remove_tag')
|
||||||
@decorators.transaction
|
@decorators.transaction
|
||||||
def remove_tag(self, tag, *, commit=True):
|
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)))
|
self.photodb.log.debug('Removing tag {t} from photo {p}'.format(t=repr(tag), p=repr(self)))
|
||||||
tags = list(tag.walk_children())
|
tags = list(tag.walk_children())
|
||||||
|
@ -1089,7 +1089,7 @@ class Tag(ObjectBase, GroupableMixin):
|
||||||
raise exceptions.CantSynonymSelf()
|
raise exceptions.CantSynonymSelf()
|
||||||
|
|
||||||
try:
|
try:
|
||||||
existing_tag = self.photodb.get_tag_by_name(synname)
|
existing_tag = self.photodb.get_tag(name=synname)
|
||||||
except exceptions.NoSuchTag:
|
except exceptions.NoSuchTag:
|
||||||
pass
|
pass
|
||||||
else:
|
else:
|
||||||
|
@ -1122,7 +1122,7 @@ class Tag(ObjectBase, GroupableMixin):
|
||||||
|
|
||||||
Good for when two tags need to be merged under a single name.
|
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
|
# Migrate the old tag's synonyms to the new one
|
||||||
# UPDATE is safe for this operation because there is no chance of duplicates.
|
# UPDATE is safe for this operation because there is no chance of duplicates.
|
||||||
|
@ -1279,7 +1279,7 @@ class Tag(ObjectBase, GroupableMixin):
|
||||||
return
|
return
|
||||||
|
|
||||||
try:
|
try:
|
||||||
existing_tag = self.photodb.get_tag(new_name)
|
existing_tag = self.photodb.get_tag(name=new_name)
|
||||||
except exceptions.NoSuchTag:
|
except exceptions.NoSuchTag:
|
||||||
pass
|
pass
|
||||||
else:
|
else:
|
||||||
|
|
|
@ -293,7 +293,7 @@ class PDBPhotoMixin:
|
||||||
photo.generate_thumbnail(commit=False)
|
photo.generate_thumbnail(commit=False)
|
||||||
|
|
||||||
tags = tags or []
|
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:
|
for tag in tags:
|
||||||
photo.add_tag(tag, commit=False)
|
photo.add_tag(tag, commit=False)
|
||||||
|
|
||||||
|
@ -790,9 +790,6 @@ class PDBUserMixin:
|
||||||
raise exceptions.PasswordTooShort(min_length=self.config['user']['min_password_length'])
|
raise exceptions.PasswordTooShort(min_length=self.config['user']['min_password_length'])
|
||||||
|
|
||||||
def _assert_valid_username(self, username):
|
def _assert_valid_username(self, username):
|
||||||
'''
|
|
||||||
If something is wrong, raise an exception. Otherwise do nothing.
|
|
||||||
'''
|
|
||||||
if len(username) < self.config['user']['min_length']:
|
if len(username) < self.config['user']['min_length']:
|
||||||
raise exceptions.UsernameTooShort(
|
raise exceptions.UsernameTooShort(
|
||||||
username=username,
|
username=username,
|
||||||
|
@ -1183,10 +1180,10 @@ class PhotoDB(PDBAlbumMixin, PDBBookmarkMixin, PDBPhotoMixin, PDBTagMixin, PDBUs
|
||||||
def create_or_get(name):
|
def create_or_get(name):
|
||||||
#print('cog', name)
|
#print('cog', name)
|
||||||
try:
|
try:
|
||||||
item = self.get_tag(name)
|
item = self.get_tag(name=name)
|
||||||
note = ('existing_tag', item.qualified_name())
|
note = ('existing_tag', item.qualified_name())
|
||||||
except exceptions.NoSuchTag:
|
except exceptions.NoSuchTag:
|
||||||
item = self.new_tag(name)
|
item = self.new_tag(name=name)
|
||||||
note = ('new_tag', item.qualified_name())
|
note = ('new_tag', item.qualified_name())
|
||||||
output_notes.append(note)
|
output_notes.append(note)
|
||||||
return item
|
return item
|
||||||
|
@ -1221,7 +1218,7 @@ class PhotoDB(PDBAlbumMixin, PDBBookmarkMixin, PDBPhotoMixin, PDBTagMixin, PDBUs
|
||||||
raise exceptions.EasyBakeError('No tag supplied')
|
raise exceptions.EasyBakeError('No tag supplied')
|
||||||
|
|
||||||
if rename_to:
|
if rename_to:
|
||||||
tag = self.get_tag(tag)
|
tag = self.get_tag(name=tag)
|
||||||
old_name = tag.name
|
old_name = tag.name
|
||||||
tag.rename(rename_to)
|
tag.rename(rename_to)
|
||||||
note = ('rename', '%s=%s' % (old_name, tag.name))
|
note = ('rename', '%s=%s' % (old_name, tag.name))
|
||||||
|
|
|
@ -77,7 +77,7 @@ def P_photo(photo_id):
|
||||||
|
|
||||||
@P_wrapper
|
@P_wrapper
|
||||||
def P_tag(tagname):
|
def P_tag(tagname):
|
||||||
return P.get_tag(tagname)
|
return P.get_tag(name=tagname)
|
||||||
|
|
||||||
@P_wrapper
|
@P_wrapper
|
||||||
def P_user(username):
|
def P_user(username):
|
||||||
|
|
|
@ -130,7 +130,7 @@ def post_tag_delete():
|
||||||
'''
|
'''
|
||||||
tagname = request.form['tagname']
|
tagname = request.form['tagname']
|
||||||
tagname = tagname.split('.')[-1].split('+')[0]
|
tagname = tagname.split('.')[-1].split('+')[0]
|
||||||
tag = common.P.get_tag(tagname)
|
tag = common.P.get_tag(name=tagname)
|
||||||
|
|
||||||
tag.delete()
|
tag.delete()
|
||||||
response = {'action': 'delete_tag', 'tagname': tag.name}
|
response = {'action': 'delete_tag', 'tagname': tag.name}
|
||||||
|
|
|
@ -22,7 +22,7 @@ def easytagger():
|
||||||
if i.startswith('?'):
|
if i.startswith('?'):
|
||||||
i = i.split('?')[1] or None
|
i = i.split('?')[1] or None
|
||||||
try:
|
try:
|
||||||
etiquette.tag_export.stdout([P.get_tag(i)])
|
etiquette.tag_export.stdout([P.get_tag(name=i)])
|
||||||
except:
|
except:
|
||||||
traceback.print_exc()
|
traceback.print_exc()
|
||||||
else:
|
else:
|
||||||
|
|
Loading…
Reference in a new issue