Add max_len
parameter to Tag.qualified_name.
This commit is contained in:
parent
6cb13c7835
commit
bc5df9f1c2
1 changed files with 29 additions and 6 deletions
|
@ -1086,16 +1086,39 @@ class Tag(ObjectBase, GroupableMixin):
|
||||||
self.photodb.log.debug('Committing - edit tag')
|
self.photodb.log.debug('Committing - edit tag')
|
||||||
self.photodb.commit()
|
self.photodb.commit()
|
||||||
|
|
||||||
def qualified_name(self):
|
def qualified_name(self, *, max_len=None):
|
||||||
'''
|
'''
|
||||||
Return the 'group1.group2.tag' string for this tag.
|
Return the 'group1.group2.tag' string for this tag.
|
||||||
|
|
||||||
|
If `max_len` is not None, bring the length of the qualname down
|
||||||
|
by first stripping off ancestors, then slicing the end off of the
|
||||||
|
name if necessary.
|
||||||
|
|
||||||
|
('people.family.mother', max_len=25) -> 'people.family.mother'
|
||||||
|
('people.family.mother', max_len=15) -> 'family.mother'
|
||||||
|
('people.family.mother', max_len=10) -> 'mother'
|
||||||
|
('people.family.mother', max_len=4) -> 'moth'
|
||||||
'''
|
'''
|
||||||
|
if max_len is not None:
|
||||||
|
if len(self.name) == max_len:
|
||||||
|
return self.name
|
||||||
|
if len(self.name) > max_len:
|
||||||
|
return self.name[:max_len]
|
||||||
|
|
||||||
if self._cached_qualified_name:
|
if self._cached_qualified_name:
|
||||||
return self._cached_qualified_name
|
qualname = self._cached_qualified_name
|
||||||
qualname = self.name
|
else:
|
||||||
for parent in self.walk_parents():
|
qualname = self.name
|
||||||
qualname = parent.name + '.' + qualname
|
for parent in self.walk_parents():
|
||||||
self._cached_qualified_name = qualname
|
qualname = parent.name + '.' + qualname
|
||||||
|
self._cached_qualified_name = qualname
|
||||||
|
|
||||||
|
if max_len is None or len(qualname) <= max_len:
|
||||||
|
return qualname
|
||||||
|
|
||||||
|
while len(qualname) > max_len:
|
||||||
|
qualname = qualname.split('.', 1)[1]
|
||||||
|
|
||||||
return qualname
|
return qualname
|
||||||
|
|
||||||
@decorators.transaction
|
@decorators.transaction
|
||||||
|
|
Loading…
Reference in a new issue