本文整理汇总了Python中taggit.utils.parse_tags函数的典型用法代码示例。如果您正苦于以下问题:Python parse_tags函数的具体用法?Python parse_tags怎么用?Python parse_tags使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了parse_tags函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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"]
)
开发者ID:alex,项目名称:django-taggit,代码行数:7,代码来源:tests.py
示例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'])
开发者ID:FinalsClub,项目名称:django-taggit,代码行数:7,代码来源:test_models.py
示例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'])
开发者ID:feuervogel,项目名称:django-taggit,代码行数:8,代码来源:tests.py
示例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'])
开发者ID:feuervogel,项目名称:django-taggit,代码行数:8,代码来源:tests.py
示例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"])
开发者ID:adeleinr,项目名称:django-taggit,代码行数:8,代码来源:tests.py
示例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"])
开发者ID:adeleinr,项目名称:django-taggit,代码行数:9,代码来源:tests.py
示例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"])
开发者ID:adeleinr,项目名称:django-taggit,代码行数:10,代码来源:tests.py
示例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"]
开发者ID:nikhilkuria,项目名称:kuma,代码行数:10,代码来源:forms.py
示例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'])
开发者ID:feuervogel,项目名称:django-taggit,代码行数:10,代码来源:tests.py
示例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'])
开发者ID:FinalsClub,项目名称:django-taggit,代码行数:11,代码来源:test_models.py
示例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']
开发者ID:tantek,项目名称:kuma,代码行数:12,代码来源:forms.py
示例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)
开发者ID:QPmedia,项目名称:django-taggit,代码行数:7,代码来源:forms.py
示例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
开发者ID:RTLShadow,项目名称:rhombik-object-repository,代码行数:27,代码来源:forms.py
示例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."))
开发者ID:theatlantic,项目名称:django-taggit,代码行数:7,代码来源:forms.py
示例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))
开发者ID:FBK-WED,项目名称:wed-pipe,代码行数:25,代码来源:importer.py
示例16: tag_all
def tag_all(self, request, queryset):
"""
Tag all selected requests with given tags
"""
opts = self.model._meta
# Check that the user has change permission for the actual model
if not self.has_change_permission(request):
raise PermissionDenied
# User has already chosen the other req
if request.POST.get('tags'):
tags = parse_tags(request.POST.get('tags'))
for obj in queryset:
obj.tags.add(*tags)
obj.save()
self.message_user(request, _("Successfully added tags to requests"))
# Return None to display the change list page again.
return None
context = {
'opts': opts,
'queryset': queryset,
'media': self.media,
'action_checkbox_name': helpers.ACTION_CHECKBOX_NAME,
'applabel': opts.app_label
}
# Display the confirmation page
return TemplateResponse(request, 'foirequest/admin_tag_all.html',
context, current_app=self.admin_site.name)
开发者ID:MechanisM,项目名称:froide,代码行数:31,代码来源:admin.py
示例17: save
def save(self, user):
artwork, created = Artwork.objects.get_or_create(
name=self.cleaned_data['artwork_name'],
kind=self.cleaned_data['artwork_kind'],
creator=self.cleaned_data['artwork_creator'],
year=self.cleaned_data['artwork_year'],
)
if artwork.kind == 'show':
# Allow unlimited reviews:
review, created = Review.objects.get_or_create(
pk=self.cleaned_data['review_id'],
user=user,
artwork=artwork,
season=self.cleaned_data['artwork_season'],
episode=self.cleaned_data['artwork_episode'],
)
else:
review, created = Review.objects.get_or_create(
user=user,
artwork=artwork,
)
review.spider_quantity = self.cleaned_data['spider_quantity']
review.summary = self.cleaned_data['summary']
review.spider_quality.set(
*parse_tags(self.cleaned_data['spider_quality'])
)
review.save()
return review
开发者ID:wlonk,项目名称:are_there_spiders,代码行数:28,代码来源:forms.py
示例18: profile_edit
def profile_edit(request, username):
"""View and edit user profile"""
profile = get_object_or_404(UserProfile, user__username=username)
if not profile.allows_editing_by(request.user):
return HttpResponseForbidden()
# Map of form field names to tag namespaces
field_to_tag_ns = (
('interests', 'profile:interest:'),
('expertise', 'profile:expertise:')
)
if request.method != "POST":
initial = dict(email=profile.user.email)
# Load up initial websites with either user data or required base URL
for name, meta in UserProfile.website_choices:
val = profile.websites.get(name, '') or meta['prefix']
initial['websites_%s' % name] = val
# Form fields to receive tags filtered by namespace.
for field, ns in field_to_tag_ns:
initial[field] = ', '.join(t.name.replace(ns, '')
for t in profile.tags.all_ns(ns))
# Finally, set up the form.
form = UserProfileEditForm(instance=profile, initial=initial)
else:
form = UserProfileEditForm(request.POST, request.FILES,
instance=profile)
if form.is_valid():
profile_new = form.save(commit=False)
# Gather up all websites defined by the model, save them.
sites = dict()
for name, meta in UserProfile.website_choices:
field_name = 'websites_%s' % name
field_value = form.cleaned_data.get(field_name, '')
if field_value:
sites[name] = field_value
profile_new.websites = sites
# Save the profile record now, since the rest of this deals with
# related resources...
profile_new.save()
# Update tags from form fields
for field, tag_ns in field_to_tag_ns:
tags = [t.lower() for t in parse_tags(
form.cleaned_data.get(field, ''))]
profile_new.tags.set_ns(tag_ns, *tags)
return HttpResponseRedirect(reverse(
'devmo.views.profile_view', args=(profile.user.username,)))
return jingo.render(request, 'devmo/profile_edit.html', dict(
profile=profile, form=form, INTEREST_SUGGESTIONS=INTEREST_SUGGESTIONS
))
开发者ID:kaiquewdev,项目名称:kuma,代码行数:60,代码来源:views.py
示例19: clean_tags
def clean_tags(self):
"""
Validate the tags ensuring we have no case-sensitive duplicates.
"""
tags = self.cleaned_data['tags']
cleaned_tags = []
if tags:
for tag in parse_tags(tags):
# Note: The exact match query doesn't work correctly with
# MySQL with regards to case-sensitivity. If we move to
# Postgresql in the future this code may need to change.
doc_tag = (DocumentTag.objects.filter(name__exact=tag)
.values_list('name', flat=True))
# Write a log we can grep to help find pre-existing duplicate
# document tags for cleanup.
if len(doc_tag) > 1:
log.warn('Found duplicate document tags: %s' % doc_tag)
if doc_tag:
if doc_tag[0] != tag and doc_tag[0].lower() == tag.lower():
# The tag differs only by case. Do not add a new one,
# add the existing one.
cleaned_tags.append(doc_tag[0])
continue
cleaned_tags.append(tag)
return ' '.join([u'"%s"' % t for t in cleaned_tags])
开发者ID:MatonAnthony,项目名称:kuma,代码行数:30,代码来源:forms.py
示例20: clean
def clean(self, value):
value = super().clean(value)
try:
return parse_tags(value)
except ValueError:
raise forms.ValidationError(
_("Please provide a comma-separated list of tags.")
)
开发者ID:alex,项目名称:django-taggit,代码行数:8,代码来源:forms.py
注:本文中的taggit.utils.parse_tags函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论