Better tag processing while saving to DB.
1. handle isolated comma in tags 2. handle leading comma 3. select unique tags 4. sort tags
This commit is contained in:
parent
e300b186ef
commit
31a46e041a
26
buku
26
buku
@ -355,15 +355,21 @@ def getTags(keywords=[]):
|
|||||||
# TODO: Simplify this logic
|
# TODO: Simplify this logic
|
||||||
|
|
||||||
tags = ','
|
tags = ','
|
||||||
|
origTags = []
|
||||||
|
uniqueTags = []
|
||||||
|
|
||||||
# Cleanse and get the tags
|
# Cleanse and get the tags
|
||||||
for tag in keywords:
|
for tag in keywords:
|
||||||
if tag[-1] == ',':
|
if tag[0] == ',': # delimiter precedes token (e.g. token1 ,token2)
|
||||||
tag = tag.strip(',') + ',' # if delimiter is present, maintain it
|
if tags[-1] != ',':
|
||||||
else:
|
tags += ','
|
||||||
tag = tag.strip(',') # a token in a multi-word tag
|
|
||||||
|
|
||||||
if tag == ',':
|
if tag[-1] == ',': # if delimiter is present, maintain it (e.g. token1, token2)
|
||||||
|
tag = tag.strip(',') + ','
|
||||||
|
else: # a token in a multi-word tag (e.g. token1 token2)
|
||||||
|
tag = tag.strip(',')
|
||||||
|
|
||||||
|
if tag == ',': # isolated delimiter (e.g. token1 , token2)
|
||||||
if tags[-1] != ',':
|
if tags[-1] != ',':
|
||||||
tags += tag
|
tags += tag
|
||||||
continue
|
continue
|
||||||
@ -376,7 +382,15 @@ def getTags(keywords=[]):
|
|||||||
if tags[-1] != ',':
|
if tags[-1] != ',':
|
||||||
tags += ','
|
tags += ','
|
||||||
|
|
||||||
return tags
|
origTags.extend(tags.strip(',').split(','))
|
||||||
|
for tag in origTags:
|
||||||
|
if tag not in uniqueTags:
|
||||||
|
uniqueTags.append(tag) # Select unique tags
|
||||||
|
|
||||||
|
# Sort the tags
|
||||||
|
sortedTags = sorted(uniqueTags, key=str.lower)
|
||||||
|
|
||||||
|
return ',' + ','.join(sortedTags) + ','
|
||||||
|
|
||||||
|
|
||||||
def AddInsertEntry(conn, cur, keywords, insertindex=0):
|
def AddInsertEntry(conn, cur, keywords, insertindex=0):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user