Skip to content

Commit

Permalink
[master][nav] Generalised tag_string_convert()
Browse files Browse the repository at this point in the history
Now multiple keys in the schema can contribute to the tag list.
  • Loading branch information
Ian Murray committed Feb 6, 2012
1 parent c8abe99 commit 9a3658e
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions ckan/logic/validators.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import re
import datetime
from itertools import count
import re
from pylons.i18n import _, ungettext, N_, gettext
from ckan.lib.navl.dictization_functions import Invalid, Missing, missing, unflatten
from ckan.authz import Authorizer
Expand Down Expand Up @@ -268,13 +269,17 @@ def tag_string_convert(key, data, errors, context):
'''Takes a list of tags that is a comma-separated string (in data[key])
and parses tag names. These are added to the data dict, enumerated. They
are also validated.'''
tag_string = data[key]

tags = [tag.strip() \
for tag in tag_string.split(',') \
if tag.strip()]
if isinstance(data[key], basestring):
tags = [tag.strip() \
for tag in data[key].split(',') \
if tag.strip()]
else:
tags = data[key]

current_index = max( [int(k[1]) for k in data.keys() if len(k) == 3 and k[0] == 'tags'] + [-1] )

for num, tag in enumerate(tags):
for num, tag in zip(count(current_index+1), tags):
data[('tags', num, 'name')] = tag

for tag in tags:
Expand Down

0 comments on commit 9a3658e

Please sign in to comment.