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

Python utils.edit_string_for_tags函数代码示例

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

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



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

示例1: __get__

    def __get__(self, instance, owner=None):
        """
        Tag getter. Returns an instance's tags if accessed on an instance, and
        all of a model's tags if called on a class. That is, this model::

           class Link(models.Model):
               ...
               tags = TagField()

        Lets you do both of these::

           >>> l = Link.objects.get(...)
           >>> l.tags
           'tag1 tag2 tag3'

           >>> Link.tags
           'tag1 tag2 tag3 tag4'

        """
        # Handle access on the model (i.e. Link.tags)
        if instance is None:
            return edit_string_for_tags(Tag.objects.usage_for_model(owner))

        tags = self._get_instance_tag_cache(instance)
        if tags is None:
            if instance.pk is None:
                self._set_instance_tag_cache(instance, '')
            else:
                self._set_instance_tag_cache(
                    instance, edit_string_for_tags(
                        Tag.objects.get_for_object(instance)))
        return self._get_instance_tag_cache(instance)
开发者ID:bogdangoie,项目名称:django-tagging-select2,代码行数:32,代码来源:fields.py


示例2: test_recreation_of_tag_list_string_representations

 def test_recreation_of_tag_list_string_representations(self):
     plain = Tag.objects.create(name='plain')
     spaces = Tag.objects.create(name='spa ces')
     comma = Tag.objects.create(name='com,ma')
     self.assertEquals(edit_string_for_tags([plain]), u'plain')
     self.assertEquals(edit_string_for_tags([plain, spaces]), u'plain, spa ces')
     self.assertEquals(edit_string_for_tags([plain, spaces, comma]), u'plain, spa ces, "com,ma"')
     self.assertEquals(edit_string_for_tags([plain, comma]), u'plain "com,ma"')
     self.assertEquals(edit_string_for_tags([comma, spaces]), u'"com,ma", spa ces')
开发者ID:stringfellow,项目名称:ias-ess,代码行数:9,代码来源:tests.py


示例3: testRecreatingStringRepresentaionsOfTagLists

    def testRecreatingStringRepresentaionsOfTagLists(self):
        plain = Tag.objects.create(name='plain')
        spaces = Tag.objects.create(name='spa ces')
        comma = Tag.objects.create(name='com,ma')

        from tagging.utils import edit_string_for_tags
        self.assertEqual(u'plain', edit_string_for_tags([plain]))
        self.assertEqual(u'plain, spa ces', edit_string_for_tags([plain, spaces]))
        self.assertEqual(u'plain, spa ces, "com,ma"', edit_string_for_tags([plain, spaces, comma]))
        self.assertEqual(u'plain "com,ma"', edit_string_for_tags([plain, comma]))
        self.assertEqual(u'"com,ma", spa ces', edit_string_for_tags([comma, spaces]))
开发者ID:Apocalepse,项目名称:django-tagging-ng,代码行数:11,代码来源:core_tests.py


示例4: __get__

    def __get__(self, instance, owner=None):
        """
        Tag getter. Returns an instance's tags if accessed on an instance, and
        all of a model's tags if called on a class. That is, this model::

           class Link(models.Model):
               ...
               tags = TagField()

        Lets you do both of these::

           >>> l = Link.objects.get(...)
           >>> l.tags
           'tag1 tag2 tag3'

           >>> Link.tags
           'tag1 tag2 tag3 tag4'

        """
        # Handle access on the model (i.e. Link.tags)
        if instance is None:
            try:
                return edit_string_for_tags(Tag.objects.usage_for_model(owner))
            except DatabaseError:
                # handle error when this is accessed before database schema exists
                return ''

        return self._get_instance_tag_cache(instance)
开发者ID:k2internet,项目名称:django-tagging,代码行数:28,代码来源:fields.py


示例5: __init__

    def __init__(self, cache_for_form_optimization=None,  *args, **kwargs):
        # The cache_for_form_optimization is an object that is
        # optionally created by the request that calls
        # BulkEditForm. One difficulty with BulkEditForms is that the
        # forms generate similar data over and over again; we can
        # avoid some database hits by running some queries just once
        # (at BulkEditForm instantiation time), rather than once per
        # sub-form.
        #
        # However, it is unsafe to cache data in the BulkEditForm
        # class because that persists for as long as the Python
        # process does (meaning that subsequent requests will use the
        # same cache).
        EditVideoForm.__init__(self, *args, **kwargs)

        # We have to initialize tags manually because the model form
        # (django.forms.models.model_to_dict) only collects fields and
        # relations, and not descriptors like Video.tags
        self.initial['tags'] = edit_string_for_tags(self.instance.tags)

        # cache the querysets so that we don't hit the DB for each form
        cache_for_form_optimization = self.fill_cache(cache_for_form_optimization)

        self.fields['categories'].queryset = cache_for_form_optimization[
            'categories_qs']
        self.fields['authors'].queryset = cache_for_form_optimization[
            'authors_qs']
开发者ID:pombredanne,项目名称:mirocommunity,代码行数:27,代码来源:forms.py


示例6: edit_post

def edit_post(request, idee):
    entry = get_object_or_404(BlogEntry, pk=idee)
    form = BlogEntryForm(
        dict(entry_id=entry.id, title=entry.title, content=entry.content, 
             tags=edit_string_for_tags(Tag.objects.get_for_object(entry)))
    )
    return render_to_response('edit_post.html', {'form': form, 'entry': entry})
开发者ID:eevans,项目名称:nicole,代码行数:7,代码来源:views.py


示例7: _update_instance_tag_cache

 def _update_instance_tag_cache(self, instance):
     """
     Helper: update an instance's tag cache from actual Tags.
     """
     # for an unsaved object, leave the default value alone
     if instance.pk is not None:
         tags = edit_string_for_tags(Tag.objects.get_for_object(instance))
         self._set_instance_tag_cache(instance, tags)
开发者ID:bmount,项目名称:courseslate,代码行数:8,代码来源:fields.py


示例8: test_delete_skill

    def test_delete_skill(self):
        """
        test deleting skills
        """
        url_edit_skills = reverse("edit_skills", args=["daveb"])

        p = DjangoPerson.objects.get(user__username="daveb")
        self.assertEqual(len(p.skilltags), 3)
        self.assertTrue("jazz" in edit_string_for_tags(p.skilltags))
        self.assertTrue("linux" in edit_string_for_tags(p.skilltags))
        self.assertTrue("python" in edit_string_for_tags(p.skilltags))

        # delete jazz skill
        skills = "linux python"
        self.client.post(url_edit_skills, {"skills": skills})
        p = DjangoPerson.objects.get(user__username="daveb")
        self.assertEqual(len(p.skilltags), 2)
        self.assertTrue("linux" in edit_string_for_tags(p.skilltags))
        self.assertTrue("python" in edit_string_for_tags(p.skilltags))
        self.assertFalse("jazz" in edit_string_for_tags(p.skilltags))

        # delete all skills
        self.client.post(url_edit_skills, {"skills": ""})
        p = DjangoPerson.objects.get(user__username="daveb")

        self.assertEqual(len(p.skilltags), 0)
        self.assertEqual(edit_string_for_tags(p.skilltags), "")
开发者ID:django,项目名称:djangopeople,代码行数:27,代码来源:tests_edit_views.py


示例9: test_delete_skill

    def test_delete_skill(self):
        '''
        test deleting skills
        '''
        url_edit_skills = reverse('edit_skills', args=['daveb'])

        p = DjangoPerson.objects.get(user__username='daveb')
        self.assertEqual(len(p.skilltags), 3)
        self.assertTrue('jazz' in edit_string_for_tags(p.skilltags))
        self.assertTrue('linux' in edit_string_for_tags(p.skilltags))
        self.assertTrue('python' in edit_string_for_tags(p.skilltags))

        # delete jazz skill
        skills = 'linux python'
        self.client.post(url_edit_skills, {'skills': skills})
        p = DjangoPerson.objects.get(user__username='daveb')
        self.assertEqual(len(p.skilltags), 2)
        self.assertTrue('linux' in edit_string_for_tags(p.skilltags))
        self.assertTrue('python' in edit_string_for_tags(p.skilltags))
        self.assertFalse('jazz' in edit_string_for_tags(p.skilltags))

        # delete all skills
        self.client.post(url_edit_skills, {'skills': ''})
        p = DjangoPerson.objects.get(user__username='daveb')

        self.assertEqual(len(p.skilltags), 0)
        self.assertEqual(edit_string_for_tags(p.skilltags), '')
开发者ID:laurent-larizza,项目名称:djangopeople,代码行数:27,代码来源:tests_edit_views.py


示例10: __set__

 def __set__(self, instance, value):
     kwargs = {'default_namespace': self.namespace}
     q = None
     if  self.namespace is not None:
         q = models.Q(namespace=self.namespace)
         kwargs['filter_namespaces'] = (self.namespace,)
     value = edit_string_for_tags(value or (), **kwargs)
     Tag.objects.update_tags(instance, value, q=q,
         default_namespace=self.namespace)
开发者ID:strogonoff,项目名称:django-tagging-machinetags,代码行数:9,代码来源:managers.py


示例11: edit_skills

def edit_skills(request, username):
    person = get_object_or_404(DjangoPerson, user__username=username)
    if not request.POST.get("skills"):
        return render(
            request,
            "edit_skills.html",
            {"form": SkillsForm(initial={"skills": edit_string_for_tags(person.skilltags)})},
        )
    person.skilltags = request.POST.get("skills", "")
    return HttpResponseRedirect("/%s/" % username)
开发者ID:jdunck,项目名称:djangopeople.net,代码行数:10,代码来源:views.py


示例12: edit_skills

def edit_skills(request, username):
    person = get_object_or_404(DjangoPerson, user__username = username)
    if not request.POST.get('skills'):
        return render(request, 'edit_skills.html', {
            'form': SkillsForm(initial={
                'skills': edit_string_for_tags(person.skilltags)
            }),
        })
    person.skilltags = request.POST.get('skills', '')
    return redirect(reverse('user_profile', args=[username]))
开发者ID:KristianOellegaard,项目名称:djangopeople.net,代码行数:10,代码来源:views.py


示例13: edit_skills

def edit_skills(request, username):
    person = get_object_or_404(DjangoPerson, user__username = username)
    if not request.POST.get('skills'):
        return render(request, 'edit_skills.html', {
            'form': SkillsForm(initial={
                'skills': edit_string_for_tags(person.skilltags)
            }),
        })
    person.skilltags = request.POST.get('skills', '')
    return HttpResponseRedirect('/%s/' % username)
开发者ID:Ryochan7,项目名称:djangopeople.net,代码行数:10,代码来源:views.py


示例14: _pre_save

    def _pre_save(self, **kwargs): #signal, sender, instance):
        """
        Save tags back to the database
        """
        tags = self._get_instance_tag_cache(kwargs['instance'])
        tags = parse_tag_input(tags)

        #print 'Tags before: %s' % tags
        instance = kwargs['instance']
        self._set_instance_tag_cache(
            instance, edit_string_for_tags(tags))
开发者ID:Apocalepse,项目名称:django-tagging-ng,代码行数:11,代码来源:fields.py


示例15: update_objects_tags

def update_objects_tags(object):
    if object is None:
        return

    object_tags = Tag.objects.get_for_object(object)
    tags_as_string = edit_string_for_tags(object_tags)

    for field in object._meta.fields:
        if isinstance(field, TagField):
            setattr(object, field.attname, tags_as_string)
            object.save()
            break
开发者ID:gelliravi,项目名称:django-antichaos,代码行数:12,代码来源:utils.py


示例16: profile

def profile(request, username):
    person = get_object_or_404(DjangoPerson, user__username=username)
    person.profile_views += 1  # Not bothering with transactions; only a stat
    person.save()
    mtags = tagdict(person.machinetags.all())

    # Set up convenient iterables for IM and services
    ims = []
    for key, value in mtags.get("im", {}).items():
        shortname, name, icon = IMPROVIDERS_DICT.get(key, ("", "", ""))
        if not shortname:
            continue  # Bad machinetag
        ims.append({"shortname": shortname, "name": name, "value": value})
    ims.sort(lambda x, y: cmp(x["shortname"], y["shortname"]))

    services = []
    for key, value in mtags.get("services", {}).items():
        shortname, name, icon = SERVICES_DICT.get(key, ("", "", ""))
        if not shortname:
            continue  # Bad machinetag
        services.append({"shortname": shortname, "name": name, "value": value})
    services.sort(lambda x, y: cmp(x["shortname"], y["shortname"]))

    # Set up vars that control privacy stuff
    privacy = {
        "show_im": (mtags["privacy"]["im"] == "public" or not request.user.is_anonymous()),
        "show_email": (
            mtags["privacy"]["email"] == "public"
            or (not request.user.is_anonymous() and mtags["privacy"]["email"] == "private")
        ),
        "hide_from_search": mtags["privacy"]["search"] != "public",
        "show_last_irc_activity": bool(person.last_active_on_irc and person.irc_tracking_allowed()),
    }

    # Should we show the 'Finding X' section at all?
    show_finding = services or privacy["show_email"] or (privacy["show_im"] and ims)

    return render(
        request,
        "profile.html",
        {
            "person": person,
            "api_key": settings.GOOGLE_MAPS_API_KEY,
            "is_owner": request.user.username == username,
            "skills_form": SkillsForm(initial={"skills": edit_string_for_tags(person.skilltags)}),
            "mtags": mtags,
            "ims": ims,
            "services": services,
            "privacy": privacy,
            "show_finding": show_finding,
        },
    )
开发者ID:jdunck,项目名称:djangopeople.net,代码行数:52,代码来源:views.py


示例17: _get_edit_string_for_tags

    def _get_edit_string_for_tags(self, owner=None, instance=None):
        kwargs = {'default_namespace': self.namespace}
        # if there are more than one tag field on this model,
        # skip the tags with namespaces of athor fields.
        # Thats their domain.
        if self.namespace is not None:
            kwargs['filter_namespaces'] = (self.namespace,)
        elif self._has_instance_multiple_tag_fields:
            kwargs['exclude_namespaces'] = self._foreign_namespaces

        # Handle access on the model (i.e. Link.tags)
        if instance is None:
            queryset = Tag.objects.usage_for_model(owner)
        # Handle access on the model instance
        else:
            queryset = Tag.objects.get_for_object(instance)
        return edit_string_for_tags(queryset, **kwargs)
开发者ID:strogonoff,项目名称:django-tagging-machinetags,代码行数:17,代码来源:fields.py


示例18: _set_instance_tag_cache

 def _set_instance_tag_cache(self, instance, tags):
     """
     Helper: set an instance's tag cache.
     """
     self._init(instance)
     # If there is a tag field with a namespace, make sure that this field
     # only gets the tags that are allowed.
     if tags and (
             self._has_instance_multiple_tag_fields or
             self.namespace is not None
         ):
         kwargs = {'default_namespace': self.namespace}
         if  self.namespace is None:
             kwargs['exclude_namespaces'] = self._foreign_namespaces
         else:
             kwargs['filter_namespaces'] = (self.namespace,)
         tags = edit_string_for_tags(tags, **kwargs)
     setattr(instance, '_%s_cache' % self.attname, tags)
开发者ID:strogonoff,项目名称:django-tagging-machinetags,代码行数:18,代码来源:fields.py


示例19: test_add_skills

    def test_add_skills(self):
        """
        test adding skills
        """
        url_edit_skills = reverse("edit_skills", args=["daveb"])

        p = DjangoPerson.objects.get(user__username="daveb")
        self.assertEqual(len(p.skilltags), 3)
        self.assertTrue("jazz" in edit_string_for_tags(p.skilltags))
        self.assertTrue("linux" in edit_string_for_tags(p.skilltags))
        self.assertTrue("python" in edit_string_for_tags(p.skilltags))

        skills = "%s django" % (edit_string_for_tags(p.skilltags))
        self.client.post(url_edit_skills, {"skills": skills})

        p = DjangoPerson.objects.get(user__username="daveb")
        self.assertEqual(len(p.skilltags), 4)
        self.assertTrue("jazz" in edit_string_for_tags(p.skilltags))
        self.assertTrue("linux" in edit_string_for_tags(p.skilltags))
        self.assertTrue("python" in edit_string_for_tags(p.skilltags))
        self.assertTrue("django" in edit_string_for_tags(p.skilltags))
开发者ID:django,项目名称:djangopeople,代码行数:21,代码来源:tests_edit_views.py


示例20: test_add_skills

    def test_add_skills(self):
        '''
        test adding skills
        '''
        url_edit_skills = reverse('edit_skills', args=['daveb'])

        p = DjangoPerson.objects.get(user__username='daveb')
        self.assertEqual(len(p.skilltags), 3)
        self.assertTrue('jazz' in edit_string_for_tags(p.skilltags))
        self.assertTrue('linux' in edit_string_for_tags(p.skilltags))
        self.assertTrue('python' in edit_string_for_tags(p.skilltags))

        skills = '%s django' % (edit_string_for_tags(p.skilltags))
        self.client.post(url_edit_skills, {'skills': skills})

        p = DjangoPerson.objects.get(user__username='daveb')
        self.assertEqual(len(p.skilltags), 4)
        self.assertTrue('jazz' in edit_string_for_tags(p.skilltags))
        self.assertTrue('linux' in edit_string_for_tags(p.skilltags))
        self.assertTrue('python' in edit_string_for_tags(p.skilltags))
        self.assertTrue('django' in edit_string_for_tags(p.skilltags))
开发者ID:laurent-larizza,项目名称:djangopeople,代码行数:21,代码来源:tests_edit_views.py



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Python utils.get_queryset_and_model函数代码示例发布时间:2022-05-27
下一篇:
Python utils.calculate_cloud函数代码示例发布时间: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