Rename Photo.tags -> get_tags.

This commit is contained in:
voussoir 2018-02-16 23:07:21 -08:00
parent ac9d7ede22
commit 2f9b51b636
6 changed files with 19 additions and 19 deletions

View file

@ -36,7 +36,7 @@ def exception(e):
return j return j
def photo(p, include_albums=True, include_tags=True): def photo(p, include_albums=True, include_tags=True):
tags = p.tags() tags = p.get_tags()
tags.sort(key=lambda x: x.name) tags.sort(key=lambda x: x.name)
j = { j = {
'id': p.id, 'id': p.id,

View file

@ -664,7 +664,7 @@ class Photo(ObjectBase):
''' '''
Take all of the tags owned by other_photo and apply them to this photo. Take all of the tags owned by other_photo and apply them to this photo.
''' '''
for tag in other_photo.tags(): for tag in other_photo.get_tags():
self.add_tag(tag) self.add_tag(tag)
@decorators.required_feature('photo.edit') @decorators.required_feature('photo.edit')
@ -792,6 +792,18 @@ class Photo(ObjectBase):
self.__reinit__() self.__reinit__()
return self.thumbnail return self.thumbnail
def get_tags(self):
'''
Return the tags assigned to this Photo.
'''
generator = helpers.select_generator(
self.photodb.sql,
'SELECT tagid FROM photo_tag_rel WHERE photoid == ?',
[self.id]
)
tags = [self.photodb.get_tag(id=fetch[0]) for fetch in generator]
return tags
def has_tag(self, tag, *, check_children=True): def has_tag(self, tag, *, check_children=True):
''' '''
Return the Tag object if this photo contains that tag. Return the Tag object if this photo contains that tag.
@ -1024,22 +1036,10 @@ class Photo(ObjectBase):
self.__reinit__() self.__reinit__()
def sorted_tags(self): def sorted_tags(self):
tags = self.tags() tags = self.get_tags()
tags.sort(key=lambda x: x.qualified_name()) tags.sort(key=lambda x: x.qualified_name())
return tags return tags
def tags(self):
'''
Return the tags assigned to this Photo.
'''
generator = helpers.select_generator(
self.photodb.sql,
'SELECT tagid FROM photo_tag_rel WHERE photoid == ?',
[self.id]
)
tags = [self.photodb.get_tag(id=fetch[0]) for fetch in generator]
return tags
class Tag(ObjectBase, GroupableMixin): class Tag(ObjectBase, GroupableMixin):
''' '''

View file

@ -634,7 +634,7 @@ class PDBPhotoMixin:
continue continue
if (has_tags is not None) or is_tagsearch: if (has_tags is not None) or is_tagsearch:
photo_tags = set(photo.tags()) photo_tags = set(photo.get_tags())
if has_tags is False and len(photo_tags) > 0: if has_tags is False and len(photo_tags) > 0:
continue continue

View file

@ -211,7 +211,7 @@ def get_search_core():
# TAGS ON THIS PAGE # TAGS ON THIS PAGE
total_tags = set() total_tags = set()
for photo in photos: for photo in photos:
for tag in photo.tags(): for tag in photo.get_tags():
total_tags.add(tag) total_tags.add(tag)
total_tags = sorted(total_tags, key=lambda t: t.qualified_name()) total_tags = sorted(total_tags, key=lambda t: t.qualified_name())

View file

@ -37,7 +37,7 @@
{% endif %} {% endif %}
{% set tag_names_title = [] %} {% set tag_names_title = [] %}
{% for tag in photo.tags() %} {% for tag in photo.get_tags() %}
{% do tag_names_title.append(tag.name) %} {% do tag_names_title.append(tag.name) %}
{% endfor %} {% endfor %}

View file

@ -30,7 +30,7 @@ def easytagger():
def photag(photo_id): def photag(photo_id):
photo = P.get_photo_by_id(photo_id) photo = P.get_photo_by_id(photo_id)
print(photo.tags()) print(photo.get_tags())
while True: while True:
photo.add_tag(input('> ')) photo.add_tag(input('> '))
get = P.get_tag get = P.get_tag