本文整理汇总了Python中tags.utils.add_existing_tag函数的典型用法代码示例。如果您正苦于以下问题:Python add_existing_tag函数的具体用法?Python add_existing_tag怎么用?Python add_existing_tag使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了add_existing_tag函数的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: auto_tag
def auto_tag(self):
"""Apply tags to myself that are implied by my metadata.
You don't need to call save on the question after this.
"""
to_add = self.product.get('tags', []) + self.category.get('tags', [])
version = self.metadata.get('ff_version', '')
dev_releases = product_details.firefox_history_development_releases
if version in dev_releases or \
version in product_details.firefox_history_stability_releases or \
version in product_details.firefox_history_major_releases:
to_add.append('Firefox %s' % version)
tenths = _tenths_version(version)
if tenths:
to_add.append('Firefox %s' % tenths)
elif _has_beta(version, dev_releases):
to_add.append('Firefox %s' % version)
to_add.append('beta')
self.tags.add(*to_add)
# Add a tag for the OS if it already exists as a tag:
os = self.metadata.get('os')
if os:
try:
add_existing_tag(os, self.tags)
except Tag.DoesNotExist:
pass
示例2: _add_tag
def _add_tag(request, question_id):
"""Add a named tag to a question, creating it first if appropriate.
Tag name (case-insensitive) must be in request.POST['tag-name'].
If there is no such tag and the user is not allowed to make new tags, raise
Tag.DoesNotExist. If no tag name is provided, return None. Otherwise,
return the canonicalized tag name.
"""
tag_name = request.POST.get('tag-name', '').strip()
if tag_name:
question = get_object_or_404(Question, pk=question_id)
try:
canonical_name = add_existing_tag(tag_name, question.tags)
except Tag.DoesNotExist:
if request.user.has_perm('taggit.add_tag'):
question.tags.add(tag_name) # implicitly creates if needed
return tag_name
raise
return canonical_name
示例3: test_add_existing_no_such_tag
def test_add_existing_no_such_tag(self):
"""Assert add_existing_tag doesn't work when the tag doesn't exist."""
add_existing_tag('nonexistent tag', self.untagged_question.tags)
示例4: test_add_existing_case_insensitive
def test_add_existing_case_insensitive(self):
"""Assert add_existing_tag works case-insensitively."""
add_existing_tag('LEMON', self.untagged_question.tags)
tags_eq(self.untagged_question, [u'lemon'])