Add Tag.normalize_description.
This commit is contained in:
parent
b4d3de3651
commit
229530580f
2 changed files with 15 additions and 2 deletions
|
@ -1164,7 +1164,7 @@ class Tag(ObjectBase, GroupableMixin):
|
||||||
db_row = dict(zip(constants.SQL_COLUMNS['tags'], db_row))
|
db_row = dict(zip(constants.SQL_COLUMNS['tags'], db_row))
|
||||||
self.id = db_row['id']
|
self.id = db_row['id']
|
||||||
self.name = db_row['name']
|
self.name = db_row['name']
|
||||||
self.description = db_row['description'] or ''
|
self.description = self.normalize_description(db_row['description'])
|
||||||
self.author_id = self.normalize_author_id(db_row['author_id'])
|
self.author_id = self.normalize_author_id(db_row['author_id'])
|
||||||
|
|
||||||
self.group_getter = self.photodb.get_tag
|
self.group_getter = self.photodb.get_tag
|
||||||
|
@ -1184,6 +1184,18 @@ class Tag(ObjectBase, GroupableMixin):
|
||||||
rep = 'Tag:{name}'.format(name=self.name)
|
rep = 'Tag:{name}'.format(name=self.name)
|
||||||
return rep
|
return rep
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def normalize_description(description):
|
||||||
|
if description is None:
|
||||||
|
return ''
|
||||||
|
|
||||||
|
if not isinstance(description, str):
|
||||||
|
raise TypeError('Description must be string, not %s' % type(description))
|
||||||
|
|
||||||
|
description = description.strip()
|
||||||
|
|
||||||
|
return description
|
||||||
|
|
||||||
def _uncache(self):
|
def _uncache(self):
|
||||||
self.photodb.caches['tag'].remove(self.id)
|
self.photodb.caches['tag'].remove(self.id)
|
||||||
self._cached_qualified_name = None
|
self._cached_qualified_name = None
|
||||||
|
@ -1297,7 +1309,7 @@ class Tag(ObjectBase, GroupableMixin):
|
||||||
if description is None:
|
if description is None:
|
||||||
return
|
return
|
||||||
|
|
||||||
self.description = description
|
self.description = self.normalize_description(description)
|
||||||
|
|
||||||
data = {
|
data = {
|
||||||
'id': self.id,
|
'id': self.id,
|
||||||
|
|
|
@ -842,6 +842,7 @@ class PDBTagMixin:
|
||||||
pass
|
pass
|
||||||
else:
|
else:
|
||||||
raise exceptions.TagExists(existing_tag)
|
raise exceptions.TagExists(existing_tag)
|
||||||
|
description = objects.Tag.normalize_description(description)
|
||||||
|
|
||||||
self.log.debug('New Tag: %s', tagname)
|
self.log.debug('New Tag: %s', tagname)
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue