From 229530580f4a6bdb7e0d3ce39d4bd51fed1a1d19 Mon Sep 17 00:00:00 2001 From: Ethan Dalool Date: Fri, 23 Mar 2018 00:20:07 -0700 Subject: [PATCH] Add Tag.normalize_description. --- etiquette/objects.py | 16 ++++++++++++++-- etiquette/photodb.py | 1 + 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/etiquette/objects.py b/etiquette/objects.py index 2f3bf7b..fcbe1af 100644 --- a/etiquette/objects.py +++ b/etiquette/objects.py @@ -1164,7 +1164,7 @@ class Tag(ObjectBase, GroupableMixin): db_row = dict(zip(constants.SQL_COLUMNS['tags'], db_row)) self.id = db_row['id'] 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.group_getter = self.photodb.get_tag @@ -1184,6 +1184,18 @@ class Tag(ObjectBase, GroupableMixin): rep = 'Tag:{name}'.format(name=self.name) 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): self.photodb.caches['tag'].remove(self.id) self._cached_qualified_name = None @@ -1297,7 +1309,7 @@ class Tag(ObjectBase, GroupableMixin): if description is None: return - self.description = description + self.description = self.normalize_description(description) data = { 'id': self.id, diff --git a/etiquette/photodb.py b/etiquette/photodb.py index 4e3501b..0b44133 100644 --- a/etiquette/photodb.py +++ b/etiquette/photodb.py @@ -842,6 +842,7 @@ class PDBTagMixin: pass else: raise exceptions.TagExists(existing_tag) + description = objects.Tag.normalize_description(description) self.log.debug('New Tag: %s', tagname)