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

Python utils.edit_string_for_tags函数代码示例

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

本文整理汇总了Python中taggit.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: 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.assertEqual(edit_string_for_tags([plain]), u'plain')
     self.assertEqual(edit_string_for_tags([plain, spaces]), u'"spa ces", plain')
     self.assertEqual(edit_string_for_tags([plain, spaces, comma]), u'"com,ma", "spa ces", plain')
     self.assertEqual(edit_string_for_tags([plain, comma]), u'"com,ma", plain')
     self.assertEqual(edit_string_for_tags([comma, spaces]), u'"com,ma", "spa ces"')
开发者ID:feuervogel,项目名称:django-taggit,代码行数:9,代码来源:tests.py


示例2: test_recreation_of_tag_list_string_representations

 def test_recreation_of_tag_list_string_representations(self):
     plain = Tag(name="plain")
     spaces = Tag(name="spa ces")
     comma = Tag(name="com,ma")
     self.assertEqual(edit_string_for_tags([plain]), "plain")
     self.assertEqual(edit_string_for_tags([plain, spaces]), '"spa ces", plain')
     self.assertEqual(
         edit_string_for_tags([plain, spaces, comma]), '"com,ma", "spa ces", plain'
     )
     self.assertEqual(edit_string_for_tags([plain, comma]), '"com,ma", plain')
     self.assertEqual(edit_string_for_tags([comma, spaces]), '"com,ma", "spa ces"')
开发者ID:alex,项目名称:django-taggit,代码行数:11,代码来源:tests.py


示例3: __init__

    def __init__(self, *args, **kwargs):

        super(EntryForm, self).__init__(*args, **kwargs)

        if 'instance' in kwargs:
            #Update mode
            obj = kwargs['instance']
        else: #Creation mode
            obj = None

        if obj:
            if obj.status == Entry.PUBLISHED_STATUS:
                initial_tags = edit_string_for_tags(obj.tags_list)
            else:
                initial_tags = ','.join(obj.drafted_tags)

            initial_other_authors = [user.username for user in obj.authors]
            self.fields['other_authors'].label = "Author(s)"
            if obj.front_image:
                initial_image = type('ImgTemp', (object,),
                                     { "url": force_text(obj.front_image),
                                       '__unicode__': lambda self : unicode(self.url)})()
                self.fields['front_image_upload'].initial = initial_image
        else:
            initial_tags = None
            initial_other_authors = []


        self.fields['tags'].initial=initial_tags
        #Get all available tags and set it inside the form field. These will be used by tag-it plugin to perform
        #the autocomplet on the widget
        self.fields['tags'].available_tags = json.dumps([ tag.name for tag in Tag.objects.all()])

        self.fields['other_authors'].initial = ", ".join(initial_other_authors)
开发者ID:itsmurfs,项目名称:techblog,代码行数:34,代码来源:admin.py


示例4: get_initial

    def get_initial(self):
        """
        We want to populate the form with data from the two associated models,
        and so we have to use initial, not instance, as this is not a
        ModelForm.

        So we basically slurp and serialize two models.
        """
        review = self.get_object()
        # Dumbest possible serialization that could work
        # @todo: this isn't very DRY.
        artwork = review.artwork
        initial = dict(
            review_id=review.pk,
            artwork_name=artwork.name,
            artwork_kind=artwork.kind,
            artwork_creator=artwork.creator,
            artwork_year=artwork.year,
            artwork_season=review.season,
            artwork_episode=review.episode,
            spider_quantity=review.spider_quantity,
            spider_quality=edit_string_for_tags(review.spider_quality.all()),
            summary=review.summary
        )
        return initial
开发者ID:wlonk,项目名称:are_there_spiders,代码行数:25,代码来源:views.py


示例5: render

    def render(self, name, value, attrs=None):
        if value is not None and not isinstance(value, basestring):
            value = edit_string_for_tags([o.tag for o in
                                          value.select_related("tag")])
        html = super(TagAutocomplete, self).render(name, value, attrs)

        return mark_safe(html)
开发者ID:isi-gach,项目名称:django-taggit-jquery-tag-it,代码行数:7,代码来源:widgets.py


示例6: render

 def render(self, name, value, attrs=None):
     if attrs is not None:
         attrs = dict(self.attrs.items() + attrs.items())
     list_view = reverse("taggit-list")
     if value is not None and not isinstance(value, basestring):
         value = simplejson.dumps(
             [{"value": u"%s" % edit_string_for_tags([o.tag])} for o in value.select_related("tag")]
         )
     else:
         value = []
     html = super(TagAutocomplete, self).render(name + "_dummy", u"", attrs)
     allow_add = "false"
     if "allow_add" in attrs and attrs["allow_add"]:
         allow_add = "true"
     js_config = (
         u'{startText: "%s", \
         preFill: %s, \
         allowAdd: %s, \
         allowAddMessage: "%s"}'
         % (escapejs(_("Enter Tag Here")), value, allow_add, escapejs(_("Please choose an existing tag")))
     )
     js = (
         u'<script type="text/javascript">jQuery = django.jQuery; \
         jQuery().ready(function() { jQuery("#%s").autoSuggest("%s", \
         %s); });</script>'
         % (attrs["id"], list_view, js_config)
     )
     return mark_safe("\n".join([html, js]))
开发者ID:pombredanne,项目名称:django-taggit,代码行数:28,代码来源:widgets.py


示例7: list_tags

def list_tags(request):
    try:
        tags = Tag.objects.filter(name__icontains=request.GET['q'])
        data = [{'value': edit_string_for_tags([t]), 'name': t.name} for t in tags]
    except MultiValueDictKeyError:
        data = ""
    return HttpResponse(simplejson.dumps(data), content_type='application/json')
开发者ID:Caramel,项目名称:django-taggit,代码行数:7,代码来源:views.py


示例8: render

	def render(self, name, value, attrs=None):
		if value is not None and not isinstance(value, basestring):
			value = edit_string_for_tags([o.tag for o in value.select_related("tag")])
		if attrs is None:
			attrs = {}
		attrs.update({'class': 'taggit-tags'})
		return super(TagWidget, self).render(name, value, attrs)
开发者ID:Govexec,项目名称:django-taggit,代码行数:7,代码来源:forms.py


示例9: 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


示例10: render

    def render(self, name, value, attrs=None):
        tags = []
        if value is not None and not isinstance(value, str):
            # value contains a list a TaggedItem instances
            # Here we retrieve a comma-delimited list of tags
            # suitable for editing by the user
            tags = [o.tag for o in value.select_related('tag')]
            value = edit_string_for_tags(tags)
        elif value is not None:
            tags = split_strip(value)

        json_view = reverse('taggit_autocomplete_jqueryui_tag_list')

        html = '<div class="selector"><ul class="tags">'
        for tag in tags:
            html += ('''
                <li data-tag="%(name)s">
                    <span class="name">%(name)s</span>
                    <a class="remove" href="#">X</a>
                </li>''' % {'name': tag})
        html += '</ul>'
        html += super(TagAutocomplete, self).render(name, value, attrs)
        html += '<input type="text" id="%s_autocomplete"/></div>' % attrs['id']

        js = '''
            <script type="text/javascript">
                (function (root) {
                    root.taggit_init = root.taggit_init || [];
                    root.taggit_init.push(['#%s_autocomplete', '%s']);
                })(window);
            </script>''' % (attrs['id'], json_view)
        return mark_safe("\n".join([html, js]))
开发者ID:eliksir,项目名称:django-taggit-autocomplete-jqueryui,代码行数:32,代码来源:widgets.py


示例11: render

    def render(self, name, value, attrs=None):
        list_view = reverse('taggit_autocomplete-list')
        if value is not None and not isinstance(value, basestring):
            value = edit_string_for_tags(
                    [o.tag for o in value.select_related("tag")])
        html = super(TagAutocomplete, self).render(name, value, attrs)

        # Activate tag-it in this field
        js = u"""
            <script type="text/javascript">
              document.addEventListener('DOMContentLoaded', function() {
                (function($) {
                    $(document).ready(function() {
                        $("#%(id)s").tagit({
                            caseSensitive: false,
                            allowSpaces: true,
                            tagSource: function(search, showChoices) {
                                options = this;
                                $.getJSON("%(source)s", {
                                    q: search.term.toLowerCase()
                                }, function(data) {
                                    showChoices(options._subtractArray(data, options.assignedTags()));
                                });
                            }
                        });
                    });
                })(jQuery);
              }, false);
            </script>
            """ % ({
                'id': attrs['id'],
                'source': list_view
            })
        return mark_safe("\n".join([html, js]))
开发者ID:IMGIITRoorkee,项目名称:django-taggit-jquery-tag-it,代码行数:34,代码来源:widgets.py


示例12: dehydrate

    def dehydrate(self, bundle):
        bundle.data["embed_url"] = bundle.obj.get_embed_url()
        bundle.data["raw_url"] = bundle.obj.get_raw_url()
        bundle.data["tags_list"] = edit_string_for_tags(bundle.obj.tags.all())
        bundle.data["full_absolute_url"] = bundle.obj.get_full_absolute_url()
        bundle.data["description_rendered"] = linebreaksbr(
            urlize(bundle.obj.description)
        )
        bundle.data["views"] = bundle.obj.views
        bundle.data["favs"] = bundle.obj.favs()

        if bundle.data["publish_date"]:
            bundle.data["publish_date"] = date(
                bundle.data["publish_date"], "M d, Y \\a\\t h:i A"
            )

        log_entries = bundle.obj.sniptlogentry_set.all()
        bundle_log_entries = []

        for entry in log_entries:
            bundle_log_entries.append(
                {
                    "created": entry.created,
                    "user": entry.user,
                    "code": entry.code,
                    "diff": entry.diff,
                }
            )

        bundle.data["log_entries"] = bundle_log_entries

        return bundle
开发者ID:nicksergeant,项目名称:snipt,代码行数:32,代码来源:api.py


示例13: render

 def render(self, name, value, attrs=None):
     if value is not None and not isinstance(value, basestring):
         value = edit_string_for_tags(
                 [o.tag for o in value.select_related("tag")])
     attrs['class'] = (attrs.get('class', '') + ' django-taggit-ac').strip()
     attrs['data-src'] = reverse('taggit_autocomplete-list')
     return super(TagAutocomplete, self).render(name, value, attrs)
开发者ID:litchfield,项目名称:django-taggit-jquery-tag-it,代码行数:7,代码来源:widgets.py


示例14: render

 def render(self, name, value, attrs=None):
     if attrs is not None:
         attrs = dict(self.attrs.items() + attrs.items())
     if value is not None and not isinstance(value, basestring):
         value = [edit_string_for_tags([o.tag]) for o in value.select_related("tag")]
     else:
         if value is not None:
             value = value.split(",")
         else:
             value = []
     html = super(TagAutocomplete, self).render("%s_dummy" % name, ",".join(value), attrs)
     allow_add = "false"
     if "allow_add" in attrs and attrs["allow_add"]:
         allow_add = "true"
     js_config = u"""{startText: "%s", \
         preFill: prefill, \
         allowAdd: %s, \
         allowAddMessage: "%s"}""" % (
         escapejs(_("Enter Tag Here")),
         allow_add,
         escapejs(_("Please choose an existing tag")),
     )
     js = u"""<script type="text/javascript">jQuery = django.jQuery; \
         jQuery().ready(function() { \
         var prefill = [];
         jQuery.each(jQuery('input[name="%s_dummy"]').val().split(','),function(i,v){prefill.push({'value': v})});
         jQuery("#%s").autoSuggest("%s", \
         %s); });</script>""" % (
         name,
         attrs["id"],
         reverse("taggit-list"),
         js_config,
     )
     return mark_safe("\n".join([html, js]))
开发者ID:FinalsClub,项目名称:django-taggit,代码行数:34,代码来源:widgets.py


示例15: dehydrate

    def dehydrate(self, bundle):
        bundle.data['embed_url'] = bundle.obj.get_embed_url()
        bundle.data['raw_url'] = bundle.obj.get_raw_url()
        bundle.data['tags_list'] = edit_string_for_tags(bundle.obj.tags.all())
        bundle.data['full_absolute_url'] = bundle.obj.get_full_absolute_url()
        bundle.data['description_rendered'] = \
            linebreaksbr(urlize(bundle.obj.description))
        bundle.data['views'] = bundle.obj.views
        bundle.data['favs'] = bundle.obj.favs()

        if bundle.data['publish_date']:
            bundle.data['publish_date'] = \
                date(bundle.data['publish_date'], 'M d, Y \\a\\t h:i A')

        log_entries = bundle.obj.sniptlogentry_set.all()
        bundle_log_entries = []

        for entry in log_entries:
            bundle_log_entries.append({
                'created': entry.created,
                'user': entry.user,
                'code': entry.code,
                'diff': entry.diff
            })

        bundle.data['log_entries'] = bundle_log_entries

        return bundle
开发者ID:ScriptSB,项目名称:snipt,代码行数:28,代码来源:api.py


示例16: render

 def render(self, name, value, attrs=None):
     if value is not None and not isinstance(value, basestring):
         value = edit_string_for_tags([o.tag for o in value.select_related("tag")])
     rendered = super(TaggitLiveWidget, self).render(name, value, attrs)
     url = reverse("taggit_autocomplete_list")
     js = '<script type="text/javascript">(function($) { $("#%s").taggit_live({callback: "%s"}); })(jQuery || django.jQuery);</script>' % (attrs['id'], url)
     return rendered + mark_safe(js)
开发者ID:arneb,项目名称:django-taggit-live,代码行数:7,代码来源:forms.py


示例17: __init__

 def __init__(self, *args, **kwargs):
     self.page = kwargs.pop('page')
     super(PageEditForm, self).__init__(*args, **kwargs)
     if self.page.pk:
         self.fields['tags'].initial = edit_string_for_tags(
                 self.page.tags.all())
         self.fields['prev_revision'].queryset = self.page.revisions.all()
         self.fields['prev_revision'].initial = self.page.last_revision()
开发者ID:ptone,项目名称:djiki,代码行数:8,代码来源:forms.py


示例18: taggit

def taggit(request):
    if request.current_page:
        tags = get_page_tags(request.current_page)
        return {'taggit':
                    {'tags': tags,
                     'edit_string': edit_string_for_tags(tags)}
                }
    return {}
开发者ID:mpaolini,项目名称:crdj-cms-taggit,代码行数:8,代码来源:context_processors.py


示例19: render

 def render(self, name, value, attrs=None, renderer=None):
     if value is not None and not isinstance(value, six.string_types):
         value = edit_string_for_tags([o.tag for o in value.select_related("tag")])
     final_attrs = self.build_attrs(attrs, extra_attrs={"name": name})
     return mark_safe(render_to_string('taggit_bootstrap/widget.html', {
         'final_attrs': flatatt(final_attrs),
         'value': value if value else '',
         'id': final_attrs['id']
     }))
开发者ID:Guildary,项目名称:django-taggit-bootstrap,代码行数:9,代码来源:widgets.py


示例20: _has_changed

    def _has_changed(self, initial, data):
        """
        Called by BaseForm._get_changed_data, which sends this the form's initial value
        for the field and the raw value that was submitted to the form, *before it has
        been through any clean() methods.*

        This means that the initial data will (usually) be a related Tag manager, while
        the raw data will (usually) be a string. So, they're both converted to strings
        before sending them to the regular change comparison.
        """

        if initial is not None and not isinstance(initial, basestring):
            initial = edit_string_for_tags([o.tag for o in initial.select_related("tag")])

        if data is not None and not isinstance(data, basestring):
            data = edit_string_for_tags([o.tag for o in data.select_related("tag")])

        return super(TagWidget, self)._has_changed(initial, data)
开发者ID:ptone,项目名称:django-taggit,代码行数:18,代码来源:forms.py



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

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