当前位置: 首页>>代码示例>>Python>>正文


Python utils.add_existing_tag函数代码示例

本文整理汇总了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
开发者ID:MiChrFri,项目名称:kitsune,代码行数:30,代码来源:models.py

示例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
开发者ID:bowmasters,项目名称:kitsune,代码行数:21,代码来源:views.py

示例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)
开发者ID:Akamad007,项目名称:kitsune,代码行数:3,代码来源:test_models.py

示例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'])
开发者ID:Akamad007,项目名称:kitsune,代码行数:4,代码来源:test_models.py


注:本文中的tags.utils.add_existing_tag函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。