• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python utils.parse_tag_input函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中tagging.utils.parse_tag_input函数的典型用法代码示例。如果您正苦于以下问题:Python parse_tag_input函数的具体用法?Python parse_tag_input怎么用?Python parse_tag_input使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了parse_tag_input函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: test_with_simple_space_delimited_tags

 def test_with_simple_space_delimited_tags(self):
     """ Test with simple space-delimited tags. """
     
     self.assertEquals(parse_tag_input('one'), [u'one'])
     self.assertEquals(parse_tag_input('one two'), [u'one', u'two'])
     self.assertEquals(parse_tag_input('one two three'), [u'one', u'three', u'two'])
     self.assertEquals(parse_tag_input('one one two two'), [u'one', u'two'])
开发者ID:stringfellow,项目名称:ias-ess,代码行数:7,代码来源:tests.py


示例2: test_with_simple_space_delimited_tags

    def test_with_simple_space_delimited_tags(self):
        """ Test with simple space-delimited tags. """

        self.assertEquals(parse_tag_input("one"), [u"one"])
        self.assertEquals(parse_tag_input("one two"), [u"one", u"two"])
        self.assertEquals(parse_tag_input("one two three"), [u"one", u"three", u"two"])
        self.assertEquals(parse_tag_input("one one two two"), [u"one", u"two"])
开发者ID:cagerton,项目名称:django-tagging,代码行数:7,代码来源:tests.py


示例3: add_search_results

    def add_search_results(self, request, queryset, search_results):
        for item in queryset:
            meta_content = parse_tag_input(item.tags)
            meta_content += parse_tag_input(item.alias)
            meta_content += [item.term, item.short_definition]
            meta_content = " ".join(meta_content)
            #print "meta: %r" % meta_content

            search_results.add(
                model_instance=item,

                # displayed short_definition of the result hit
                headline="%s: %s" % (item.term, item.short_definition),

                # displayed in the result list
                language=item.language,

                # Link to the hit
                url=item.get_absolute_url(),

                # the main content -> result lines would be cut out from hits in this content
                content=item.get_search_content(request),

                # hits in meta content has a higher score, but the content would not displayed 
                meta_content=meta_content,
            )
开发者ID:BIGGANI,项目名称:PyLucid,代码行数:26,代码来源:search.py


示例4: testDoubleQuotedMultipleWords

 def testDoubleQuotedMultipleWords(self):
     """A completed quote will trigger this. Unclosed quotes are ignored."""
     self.assertEqual([u'one'], parse_tag_input('"one'))
     self.assertEqual([u'one', u'two'], parse_tag_input('"one two'))
     self.assertEqual([u'one', u'three', u'two'], parse_tag_input('"one two three'))
     self.assertEqual([u'one two'], parse_tag_input('"one two"'))
     self.assertEqual([u'a-one', u'a-two and a-three'], parse_tag_input('a-one "a-two and a-three"'))
开发者ID:Apocalepse,项目名称:django-tagging-ng,代码行数:7,代码来源:core_tests.py


示例5: 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.assertEquals(parse_tag_input(",one"), [u"one"])
        self.assertEquals(parse_tag_input(",one two"), [u"one two"])
        self.assertEquals(parse_tag_input(",one two three"), [u"one two three"])
        self.assertEquals(parse_tag_input("a-one, a-two and a-three"), [u"a-one", u"a-two and a-three"])
开发者ID:cagerton,项目名称:django-tagging,代码行数:8,代码来源:tests.py


示例6: 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.assertEquals(parse_tag_input('"one'), [u"one"])
        self.assertEquals(parse_tag_input('"one two'), [u"one", u"two"])
        self.assertEquals(parse_tag_input('"one two three'), [u"one", u"three", u"two"])
        self.assertEquals(parse_tag_input('"one two"'), [u"one two"])
        self.assertEquals(parse_tag_input('a-one "a-two and a-three"'), [u"a-one", u"a-two and a-three"])
开发者ID:cagerton,项目名称:django-tagging,代码行数:9,代码来源:tests.py


示例7: 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.assertEquals(parse_tag_input(',one'), [u'one'])
     self.assertEquals(parse_tag_input(',one two'), [u'one two'])
     self.assertEquals(parse_tag_input(',one two three'), [u'one two three'])
     self.assertEquals(parse_tag_input('a-one, a-two and a-three'),
         [u'a-one', u'a-two and a-three'])
开发者ID:stringfellow,项目名称:ias-ess,代码行数:9,代码来源:tests.py


示例8: pre_save_handler

def pre_save_handler(sender, instance, **kwargs):
    """
    Intercept attempts to save and sort the tag field alphabetically, so
    we won't have different permutations in the filter list.
    """
    taglist = parse_tag_input(instance.tags)
    instance.tags = taglist_to_string(taglist)
开发者ID:nai-central,项目名称:feincms,代码行数:7,代码来源:tagging.py


示例9: update_tags

    def update_tags(self, obj, tag_names):
        """
        Update tags associated with an object.
        """
        ctype = ContentType.objects.get_for_model(obj)
        current_tags = list(self.filter(items__content_type__pk=ctype.pk,
                                        items__object_id=obj.pk))
        updated_tag_names = parse_tag_input(tag_names)
        if settings.FORCE_LOWERCASE_TAGS:
            updated_tag_names = [t.lower() for t in updated_tag_names]

        # Remove tags which no longer apply
        tags_for_removal = [tag for tag in current_tags \
                            if tag.name not in updated_tag_names]
        if len(tags_for_removal):
            TaggedItem._default_manager.filter(content_type__pk=ctype.pk,
                                               object_id=obj.pk,
                                               tag__in=tags_for_removal).delete()
        # Add new tags
        current_tag_names = [tag.name for tag in current_tags]
        for tag_name in updated_tag_names:
            if tag_name not in current_tag_names:
                tag, created = self.get_or_create(name=tag_name)
                try:
                    TaggedItem._default_manager.create(tag=tag, object=obj)
                except IntegrityError:
                    # there is a race condition between querying for current_tags above
                    # and calling create() here. another process / transaction
                    # may have already created this tag. This scenario usually occurs
                    # with two concurrent calls to a django model's save() method
                    # if the model has a TagField that is being changed. should be
                    # harmless to pass here since the TaggedItem already exists
                    pass
开发者ID:CircleUp,项目名称:django-tagging,代码行数:33,代码来源:models.py


示例10: update_tags

    def update_tags(self, obj, tag_names, labels=None):
        """
        Update tags associated with an object.
        """
        ctype = ContentType.objects.get_for_model(obj)

        ##TODO: This fails silently in non-rel when it should not
        #current_tags = list(self.filter(items__content_type__pk=ctype.pk,
        #                                items__object_id=obj.pk))
        ##This works, divided into two queries
        items = TaggedItem.objects.filter(content_type__pk=ctype.pk, object_id=obj.pk)
        current_tags = self.filter(pk__in=[item.tag_id for item in items])

        updated_tag_names = parse_tag_input(tag_names)
        if settings.FORCE_LOWERCASE_TAGS:
            updated_tag_names = [t.lower() for t in updated_tag_names]

        # Remove tags which no longer apply
        tags_for_removal = [tag for tag in current_tags \
                            if tag.name not in updated_tag_names]
        if len(tags_for_removal):
            TaggedItem._default_manager.filter(content_type__pk=ctype.pk,
                                               object_id=obj.pk,
                                               tag__in=tags_for_removal).delete()
        # Add new tags
        current_tag_names = [tag.name for tag in current_tags]
        for tag_name in updated_tag_names:
            if tag_name not in current_tag_names:
                tag, created = self.get_or_create(name=tag_name)
                TaggedItem._default_manager.create(tag=tag, object=obj)
开发者ID:yrik,项目名称:turmap,代码行数:30,代码来源:models.py


示例11: update_tags

    def update_tags(self, obj, tag_names, user=None):
        """
        Update tags associated with an object.
        user - the user adding the new tags
        """

        ctype = ContentType.objects.get_for_model(obj)
        current_tags = list(self.filter(items__content_type__pk=ctype.pk,
                                        items__object_id=obj.pk))
        updated_tag_names = parse_tag_input(tag_names)
        if settings.FORCE_LOWERCASE_TAGS:
            updated_tag_names = [t.lower() for t in updated_tag_names]

        updated_tag_name_slugs = [slugify(t) for t in updated_tag_names]
        update_tag_name_dict = dict(zip(updated_tag_name_slugs, updated_tag_names))

        # Remove tags which no longer apply
        tags_for_removal = [tag for tag in current_tags \
                            if tag.slug not in updated_tag_name_slugs]
        if len(tags_for_removal):
            TaggedItem._default_manager.filter(content_type__pk=ctype.pk,
                                               object_id=obj.pk,
                                               tag__in=tags_for_removal).delete()
        # Add new tags
        current_tag_names = [tag.name for tag in current_tags]
        current_tag_name_slugs = [tag.slug for tag in current_tags]
        for tag_slug in updated_tag_name_slugs:
            if tag_slug not in current_tag_name_slugs:
                tag_name = update_tag_name_dict[tag_slug]
                tag, created = self.get_or_create(slug=tag_slug, defaults=dict(name=tag_name))
                TaggedItem._default_manager.create(tag=tag, object=obj, user=user)
开发者ID:WoLpH,项目名称:django-tagging,代码行数:31,代码来源:models.py


示例12: update_tags

    def update_tags(self, obj, tag_names, default_namespace=None, q=None):
        """
        Update tags associated with an object.

        Accepts a ``default_namespace`` parameter that is assigned to tags
        with no namespace specified.
        """
        ctype = ContentType.objects.get_for_model(obj)
        current_tags = self.filter(items__content_type__pk=ctype.pk,
            items__object_id=obj.pk)
        if q is not None:
            current_tags = current_tags.filter(q)
        current_tags = list(current_tags)
        updated_tag_names = parse_tag_input(tag_names,
            default_namespace=default_namespace)
        if conf.FORCE_LOWERCASE_TAGS:
            updated_tag_names = [t.lower() for t in updated_tag_names]

        # Remove tags which no longer apply
        tags_for_removal = [tag for tag in current_tags \
                            if unicode(tag) not in updated_tag_names]
        if len(tags_for_removal):
            TaggedItem._default_manager.filter(content_type__pk=ctype.pk,
                object_id=obj.pk, tag__in=tags_for_removal).delete()
        # Add new tags
        current_tag_names = [unicode(tag) for tag in current_tags]
        for tag_name in updated_tag_names:
            if tag_name not in current_tag_names:
                tag, created = self.get_or_create(**get_tag_parts(tag_name))
                TaggedItem._default_manager.create(tag=tag, object=obj)
开发者ID:volgoweb,项目名称:wt,代码行数:30,代码来源:models.py


示例13: add_tag

 def add_tag(self, obj, tag_name):
     """
     Associates the given object with a tag.
     """
     tag_names = parse_tag_input(tag_name)
     if not len(tag_names):
         raise AttributeError(_('No tags were given: "%s".') % tag_name)
     if len(tag_names) > 1:
         raise AttributeError(_('Multiple tags were given: "%s".') % tag_name)
     tag_name = tag_names[0]
     if settings.FORCE_LOWERCASE_TAGS:
         tag_name = tag_name.lower()
     tag, created = self.get_or_create(slug=slugify(tag_name),
                                       defaults={'name': tag_name})
     if not created:
         # check if there is a preferred synonym for this tag
         try:
             related_tag = RelatedTag.objects.get(tag=tag, relation_type='=>')
         except RelatedTag.DoesNotExist:
             pass
         else:
             # there is a preferred synonym; use it instead of the original
             tag = related_tag.related_tag
     ctype = ContentType.objects.get_for_model(obj)
     TaggedItem._default_manager.get_or_create(
         tag=tag, content_type=ctype, object_id=obj.pk)
开发者ID:antonioceraso,项目名称:django-tagging,代码行数:26,代码来源:models.py


示例14: add_tag

    def add_tag(self, obj, tag_name):
        """
        Associates the given object with a tag.
        """
        tag_names = parse_tag_input(tag_name)
        if not len(tag_names):
            raise AttributeError(_('No tags were given: "%s".') % tag_name)
        if len(tag_names) > 1:
            raise AttributeError(_('Multiple tags were given: "%s".') % tag_name)
        tag_name = tag_names[0]
        if settings.FORCE_LOWERCASE_TAGS:
            tag_name = tag_name.lower()
        ctype = ContentType.objects.get_for_model(obj)

        ###ADDED BY RHIZOME TO DISTINGUISH TYPE 
        post_content_type, artwork_content_type, member_exhibition_content_type = get_content_types()
                        
        if ctype == post_content_type:        
            tag, created = self.get_or_create(slug=tag_name, type="editorial")
        if ctype == artwork_content_type:        
            tag, created = self.get_or_create(slug=tag_name, type="artbase")
        if ctype == member_exhibition_content_type:
            tag, created = self.get_or_create(slug=tag_name, type="member_exhibition")

        TaggedItem._default_manager.get_or_create(
            tag=tag, content_type=ctype, object_id=obj.pk)
开发者ID:hxrts,项目名称:rhizome.org,代码行数:26,代码来源:models.py


示例15: update_tags

    def update_tags(self, obj, tag_names):
        """
        Update tags associated with an object.
        """
        ctype = ContentType.objects.get_for_model(obj)
        current_tags = list(self.filter(items__content_type__pk=ctype.pk, items__object_id=obj.pk))
        updated_tag_names = parse_tag_input(tag_names)
        if settings.FORCE_LOWERCASE_TAGS:
            updated_tag_names = [t.lower() for t in updated_tag_names]

        # Remove tags which no longer apply
        tags_for_removal = [tag for tag in current_tags if tag.name not in updated_tag_names]
        if len(tags_for_removal):
            TaggedItem._default_manager.filter(
                content_type__pk=ctype.pk, object_id=obj.pk, tag__in=tags_for_removal
            ).delete()
        # Add new tags
        current_tag_names = [tag.name for tag in current_tags]
        for tag_name in updated_tag_names:
            if tag_name not in current_tag_names:
                tag, created = self.get_or_create(name=tag_name)
                try:
                    TaggedItem._default_manager.create(tag=tag, object=obj)
                except:
                    pass
开发者ID:dalembertian,项目名称:django-tagging,代码行数:25,代码来源:models.py


示例16: update_tags

    def update_tags(self, obj, tag_names):
        """
        Update tags associated with an object.
        """
        ctypes = ctypes_leading_to(obj)
        current_tags = list(self.filter(items__content_type__pk__in=[ctype.pk for ctype in ctypes],
                                          items__object_id=obj.pk))

        updated_tag_names = parse_tag_input(tag_names)
        if settings.FORCE_LOWERCASE_TAGS:
            updated_tag_names = [t.lower() for t in updated_tag_names]

        # Remove tags which no longer apply
        tags_for_removal = [tag for tag in current_tags \
                            if tag.name not in updated_tag_names]
        if len(tags_for_removal):
            TaggedItem._default_manager.filter(content_type__pk__in=[ctype.pk for ctype in ctypes],
                                               object_id=obj.pk,
                                               tag__in=tags_for_removal).delete()
        # Add new tags
        current_tag_names = [tag.name for tag in current_tags]
        for robj in get_all_parents_until_registered(obj):
            for tag_name in updated_tag_names:
                if tag_name not in current_tag_names:
                    tag, created = self.get_or_create(name=tag_name)
                    TaggedItem._default_manager.create(tag=tag, object=robj)
开发者ID:diefenbach,项目名称:django-tagging-inheritance,代码行数:26,代码来源:models.py


示例17: testBadUsersNaughtyUsers

 def testBadUsersNaughtyUsers(self):
     self.assertEqual([], parse_tag_input(None))
     self.assertEqual([], parse_tag_input(''))
     self.assertEqual([], parse_tag_input('"'))
     self.assertEqual([], parse_tag_input('""'))
     self.assertEqual([], parse_tag_input('"' * 7))
     self.assertEqual([], parse_tag_input(',,,,,,'))
     self.assertEqual([u','], parse_tag_input('",",",",",",","'))
     self.assertEqual([u'a-one', u'a-three', u'a-two', u'and'], parse_tag_input('a-one "a-two" and "a-three'))
开发者ID:Apocalepse,项目名称:django-tagging-ng,代码行数:9,代码来源:core_tests.py


示例18: render

 def render(self, name, value, attrs=None):
     output = ['<div class="tagbox" id="id_%s">' % (name)]
     if value:
         tags = parse_tag_input(value)
         for tag in tags:
             output.append(tag + ",")
     output.append("</div>")
     return mark_safe(u"\n".join(output))
开发者ID:ildus,项目名称:django-ilib,代码行数:8,代码来源:widgets.py


示例19: is_tag_list

def is_tag_list(value):
    """
	Validates that ``value`` is a valid list of tags.
	"""
    for tag_name in parse_tag_input(value):
        if len(tag_name) > settings.MAX_TAG_LENGTH:
            raise forms.ValidationError(_("Each tag may be no more than %s characters long.") % settings.MAX_TAG_LENGTH)
    return value
开发者ID:myles,项目名称:django-tagging,代码行数:8,代码来源:validators.py


示例20: clean

 def clean(self, value):
     value = super(TagField, self).clean(value)
     for tag_name in parse_tag_input(value):
         if len(tag_name) > settings.MAX_TAG_LENGTH:
             raise forms.ValidationError(
                 _('Each tag may be no more than %s characters long.') %
                 settings.MAX_TAG_LENGTH)
     return value
开发者ID:Fantomas42,项目名称:django-tagging,代码行数:8,代码来源:forms.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python views.tagged_object_list函数代码示例发布时间:2022-05-27
下一篇:
Python utils.get_tag_list函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap