本文整理汇总了Python中taggit.utils.parse_tags函数的典型用法代码示例。如果您正苦于以下问题:Python parse_tags函数的具体用法?Python parse_tags怎么用?Python parse_tags使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了parse_tags函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_custom_comma_splitter
def test_custom_comma_splitter(self):
self.assertEqual(parse_tags(" Cued Speech "), ["Cued Speech"])
self.assertEqual(parse_tags(" ,Cued Speech, "), ["Cued Speech"])
self.assertEqual(parse_tags("Cued Speech"), ["Cued Speech"])
self.assertEqual(
parse_tags("Cued Speech, dictionary"), ["Cued Speech", "dictionary"]
)
示例2: test_with_comma_delimited_multiple_words_disabled_space_split
def test_with_comma_delimited_multiple_words_disabled_space_split(self, mocked_settings):
mocked_settings.TAGGIT_ENABLE_SPACE_SPLIT_IF_NOT_QUOTES = False
tools.assert_equals(parse_tags(',one'), [u'one'])
tools.assert_equals(parse_tags(',one two'), [u'one two'])
tools.assert_equals(parse_tags(',one two three'), [u'one two three'])
tools.assert_equals(parse_tags('a one, a-two and a-three'),
[u'a one', u'a-two and a-three'])
示例3: test_tags_with_double_quotes_can_contain_commas
def test_tags_with_double_quotes_can_contain_commas(self):
"""
Double quotes can contain commas
"""
self.assertEqual(parse_tags('a-one "a-two, and a-three"'),
[u'a-one', u'a-two, and a-three'])
self.assertEqual(parse_tags('"two", one, one, two, "one"'),
[u'one', u'two'])
示例4: test_with_simple_space_delimited_tags
def test_with_simple_space_delimited_tags(self):
"""
Test with simple space-delimited tags.
"""
self.assertEqual(parse_tags('one'), [u'one'])
self.assertEqual(parse_tags('one two'), [u'one', u'two'])
self.assertEqual(parse_tags('one two three'), [u'one', u'three', u'two'])
self.assertEqual(parse_tags('one one two two'), [u'one', u'two'])
示例5: test_with_simple_space_delimited_tags
def test_with_simple_space_delimited_tags(self):
"""
Test with simple space-delimited tags.
"""
self.assertEqual(parse_tags("one"), ["one"])
self.assertEqual(parse_tags("one two"), ["one", "two"])
self.assertEqual(parse_tags("one two three"), ["one", "three", "two"])
self.assertEqual(parse_tags("one one two two"), ["one", "two"])
示例6: test_with_comma_delimited_multiple_words
def test_with_comma_delimited_multiple_words(self):
"""
Test with comma-delimited multiple words.
An unquoted comma in the input will trigger this.
"""
self.assertEqual(parse_tags(",one"), ["one"])
self.assertEqual(parse_tags(",one two"), ["one two"])
self.assertEqual(parse_tags(",one two three"), ["one two three"])
self.assertEqual(parse_tags("a-one, a-two and a-three"), ["a-one", "a-two and a-three"])
示例7: test_with_double_quoted_multiple_words
def test_with_double_quoted_multiple_words(self):
"""
Test with double-quoted multiple words.
A completed quote will trigger this. Unclosed quotes are ignored.
"""
self.assertEqual(parse_tags('"one'), ["one"])
self.assertEqual(parse_tags('"one two'), ["one", "two"])
self.assertEqual(parse_tags('"one two three'), ["one", "three", "two"])
self.assertEqual(parse_tags('"one two"'), ["one two"])
self.assertEqual(parse_tags('a-one "a-two and a-three"'), ["a-one", "a-two and a-three"])
示例8: clean_expertise
def clean_expertise(self):
"""Enforce expertise as a subset of interests"""
# bug 709938 - don't assume interests passed validation
interests = set(parse_tags(self.cleaned_data.get("interests", "")))
expertise = set(parse_tags(self.cleaned_data["expertise"]))
if len(expertise) > 0 and not expertise.issubset(interests):
raise forms.ValidationError(_("Areas of expertise must be a " "subset of interests"))
return self.cleaned_data["expertise"]
示例9: test_with_comma_delimited_multiple_words
def test_with_comma_delimited_multiple_words(self):
"""
Test with comma-delimited multiple words.
An unquoted comma in the input will trigger this.
"""
self.assertEqual(parse_tags(',one'), [u'one'])
self.assertEqual(parse_tags(',one two'), [u'one two'])
self.assertEqual(parse_tags(',one two three'), [u'one two three'])
self.assertEqual(parse_tags('a-one, a-two and a-three'),
[u'a-one', u'a-two and a-three'])
示例10: test_with_double_quoted_multiple_words
def test_with_double_quoted_multiple_words(self):
"""
Test with double-quoted multiple words.
A completed quote will trigger this. Unclosed quotes are ignored.
"""
tools.assert_equals(parse_tags('"one'), [u'one'])
tools.assert_equals(parse_tags('"one two'), [u'one', u'two'])
tools.assert_equals(parse_tags('"one two three'), [u'one', u'three', u'two'])
tools.assert_equals(parse_tags('"one two"'), [u'one two'])
tools.assert_equals(parse_tags('a-one "a-two and a-three"'),
[u'a-one', u'a-two and a-three'])
示例11: clean_expertise
def clean_expertise(self):
"""Enforce expertise as a subset of interests"""
cleaned_data = self.cleaned_data
interests = set(parse_tags(cleaned_data['interests']))
expertise = set(parse_tags(cleaned_data['expertise']))
if len(expertise) > 0 and not expertise.issubset(interests):
raise forms.ValidationError(_("Areas of expertise must be a "
"subset of interests"))
return cleaned_data['expertise']
示例12: render
def render(self, name, value, attrs=None):
if value is not None:
if isinstance(value, basestring):
value = parse_tags(value)
else:
value = edit_string_for_tags([o.tag for o in value.select_related("tag")])
return super(TagWidget, self).render(name, value, attrs)
示例13: search
def search(self):
# First, store the SearchQuerySet received from other processing.
if self.cleaned_data['q']:
sqs = super(objectSearchForm, self).search()
else:
sqs= SearchQuerySet().exclude(draft=True)
if not self.is_valid():
return self.no_query_found()
# Check to see if a start_date was chosen.
if self.cleaned_data['tags']:
sqs = sqs.filter(tags=parse_tags(self.cleaned_data['tags']))
# if 'start_date' in self.cleaned_data:
# sqs = sqs.filter(created__gte=self.cleaned_data['start_date'])
# Check to see if an end_date was chosen.
# if 'end_date' in self.cleaned_data:
# sqs = sqs.filter(created=self.cleaned_data['end_date'])
if not self.cleaned_data['sort'] or self.cleaned_data['sort'] == "votes":
sqs = sqs.order_by('-ratingSortBest')
elif self.cleaned_data['sort'] == "new":
sqs = sqs.order_by('-created')
return sqs
示例14: clean
def clean(self, value):
value = super(TagField, self).clean(value)
value = ','.join(SIO(value))
try:
return parse_tags(value)
except ValueError:
raise forms.ValidationError(_("Please provide a comma-separated list of tags."))
示例15: read_csv
def read_csv(source, csv_stream):
"""
Reads metadata from a CSV for a specified source name.
"""
if not isinstance(source, Source):
source = Source.objects.get(name=source)
from csvkit import CSVKitReader
rows = list(CSVKitReader(csv_stream, delimiter='\t'))
fields = dict(enumerate(rows[0]))
errors = []
for row in rows[1:]:
try:
data = {fields[idx]: value for idx, value in enumerate(row)}
tags = data.pop('tags', None)
dataset = Dataset(**data)
dataset.source = source
dataset.save()
if tags:
dataset.tags.add(*parse_tags(tags))
except Exception, e:
logger.exception('Cannot import a dataset from CSV')
errors.append(repr(e))