python类force_unicode()的实例源码

widgets.py 文件源码 项目:MxOnline 作者: myTeemo 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def render(self, name, value, attrs=None, choices=()):
        if value is None:
            value = []
        has_id = attrs and 'id' in attrs
        final_attrs = self.build_attrs(attrs, name=name)
        output = []
        # Normalize to strings
        str_values = set([force_unicode(v) for v in value])
        for i, (option_value, option_label) in enumerate(chain(self.choices, choices)):
            # If an ID attribute was given, add a numeric index as a suffix,
            # so that the checkboxes don't all have the same ID attribute.
            if has_id:
                final_attrs = dict(final_attrs, id='%s_%s' % (attrs['id'], i))
                label_for = u' for="%s"' % final_attrs['id']
            else:
                label_for = ''

            cb = forms.CheckboxInput(
                final_attrs, check_test=lambda value: value in str_values)
            option_value = force_unicode(option_value)
            rendered_cb = cb.render(name, option_value)
            option_label = conditional_escape(force_unicode(option_label))

            if final_attrs.get('inline', False):
                output.append(u'<label%s class="checkbox-inline">%s %s</label>' % (label_for, rendered_cb, option_label))
            else:
                output.append(u'<div class="checkbox"><label%s>%s %s</label></div>' % (label_for, rendered_cb, option_label))
        return mark_safe(u'\n'.join(output))
edit.py 文件源码 项目:MxOnline 作者: myTeemo 项目源码 文件源码 阅读 28 收藏 0 点赞 0 评论 0
def get_context(self):
        new_context = {
            'title': _('Add %s') % force_unicode(self.opts.verbose_name),
        }
        context = super(CreateAdminView, self).get_context()
        context.update(new_context)
        return context
edit.py 文件源码 项目:MxOnline 作者: myTeemo 项目源码 文件源码 阅读 26 收藏 0 点赞 0 评论 0
def get_breadcrumb(self):
        bcs = super(ModelFormAdminView, self).get_breadcrumb()
        item = {'title': _('Add %s') % force_unicode(self.opts.verbose_name)}
        if self.has_add_permission():
            item['url'] = self.model_admin_url('add')
        bcs.append(item)
        return bcs
edit.py 文件源码 项目:MxOnline 作者: myTeemo 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
def init_request(self, object_id, *args, **kwargs):
        self.org_obj = self.get_object(unquote(object_id))

        if not self.has_change_permission(self.org_obj):
            raise PermissionDenied

        if self.org_obj is None:
            raise Http404(_('%(name)s object with primary key %(key)r does not exist.') %
                          {'name': force_unicode(self.opts.verbose_name), 'key': escape(object_id)})

        # comm method for both get and post
        self.prepare_form()
edit.py 文件源码 项目:MxOnline 作者: myTeemo 项目源码 文件源码 阅读 20 收藏 0 点赞 0 评论 0
def get_context(self):
        new_context = {
            'title': _('Change %s') % force_unicode(self.org_obj),
            'object_id': str(self.org_obj.pk),
        }
        context = super(UpdateAdminView, self).get_context()
        context.update(new_context)
        return context
edit.py 文件源码 项目:MxOnline 作者: myTeemo 项目源码 文件源码 阅读 18 收藏 0 点赞 0 评论 0
def get_breadcrumb(self):
        bcs = super(ModelFormAdminView, self).get_breadcrumb()

        item = {'title': force_unicode(self.org_obj)}
        if self.has_change_permission():
            item['url'] = self.model_admin_url('change', self.org_obj.pk)
        bcs.append(item)

        return bcs
edit.py 文件源码 项目:MxOnline 作者: myTeemo 项目源码 文件源码 阅读 30 收藏 0 点赞 0 评论 0
def post_response(self):
        """
        Determines the HttpResponse for the change_view stage.
        """
        opts = self.new_obj._meta
        obj = self.new_obj
        request = self.request
        verbose_name = opts.verbose_name

        pk_value = obj._get_pk_val()

        msg = _('The %(name)s "%(obj)s" was changed successfully.') % {'name':
                                                                       force_unicode(verbose_name), 'obj': force_unicode(obj)}
        if "_continue" in request.POST:
            self.message_user(
                msg + ' ' + _("You may edit it again below."), 'success')
            return request.path
        elif "_addanother" in request.POST:
            self.message_user(msg + ' ' + (_("You may add another %s below.")
                              % force_unicode(verbose_name)), 'success')
            return self.model_admin_url('add')
        else:
            self.message_user(msg, 'success')
            # Figure out where to redirect. If the user has change permission,
            # redirect to the change-list page for this object. Otherwise,
            # redirect to the admin index.
            if "_redirect" in request.POST:
                return request.POST["_redirect"]
            elif self.has_view_permission():
                change_list_url = self.model_admin_url('changelist')
                if 'LIST_QUERY' in self.request.session \
                and self.request.session['LIST_QUERY'][0] == self.model_info:
                    change_list_url += '?' + self.request.session['LIST_QUERY'][1]
                return change_list_url
            else:
                return self.get_admin_url('index')
list.py 文件源码 项目:MxOnline 作者: myTeemo 项目源码 文件源码 阅读 26 收藏 0 点赞 0 评论 0
def label(self):
        text = mark_safe(
            self.text) if self.allow_tags else conditional_escape(self.text)
        if force_unicode(text) == '':
            text = mark_safe('&nbsp;')
        for wrap in self.wraps:
            text = mark_safe(wrap % text)
        return text
dashboard.py 文件源码 项目:MxOnline 作者: myTeemo 项目源码 文件源码 阅读 28 收藏 0 点赞 0 评论 0
def render(self, name, value, attrs=None):
        if value is None:
            value = ''
        final_attrs = self.build_attrs(attrs, name=name)
        final_attrs['class'] = 'nav nav-pills nav-stacked'
        output = [u'<ul%s>' % flatatt(final_attrs)]
        options = self.render_options(force_unicode(value), final_attrs['id'])
        if options:
            output.append(options)
        output.append(u'</ul>')
        output.append('<input type="hidden" id="%s_input" name="%s" value="%s"/>' %
                     (final_attrs['id'], name, force_unicode(value)))
        return mark_safe(u'\n'.join(output))
dashboard.py 文件源码 项目:MxOnline 作者: myTeemo 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def get_title(self):
        return self.title % force_unicode(self.obj)
dashboard.py 文件源码 项目:MxOnline 作者: myTeemo 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
def init_request(self, object_id, *args, **kwargs):
        self.obj = self.get_object(unquote(object_id))

        if not self.has_view_permission(self.obj):
            raise PermissionDenied

        if self.obj is None:
            raise Http404(_('%(name)s object with primary key %(key)r does not exist.') %
                          {'name': force_unicode(self.opts.verbose_name), 'key': escape(object_id)})
detail.py 文件源码 项目:MxOnline 作者: myTeemo 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def val(self):
        text = mark_safe(
            self.text) if self.allow_tags else conditional_escape(self.text)
        if force_unicode(text) == '' or text == 'None' or text == EMPTY_CHANGELIST_VALUE:
            text = mark_safe(
                '<span class="text-muted">%s</span>' % EMPTY_CHANGELIST_VALUE)
        for wrap in self.wraps:
            text = mark_safe(wrap % text)
        return text
detail.py 文件源码 项目:MxOnline 作者: myTeemo 项目源码 文件源码 阅读 34 收藏 0 点赞 0 评论 0
def init_request(self, object_id, *args, **kwargs):
        self.obj = self.get_object(unquote(object_id))

        if not self.has_view_permission(self.obj):
            raise PermissionDenied

        if self.obj is None:
            raise Http404(
                _('%(name)s object with primary key %(key)r does not exist.') %
                {'name': force_unicode(self.opts.verbose_name), 'key': escape(object_id)})
        self.org_obj = self.obj
detail.py 文件源码 项目:MxOnline 作者: myTeemo 项目源码 文件源码 阅读 28 收藏 0 点赞 0 评论 0
def get_breadcrumb(self):
        bcs = super(DetailAdminView, self).get_breadcrumb()
        item = {'title': force_unicode(self.obj)}
        if self.has_view_permission():
            item['url'] = self.model_admin_url('detail', self.obj.pk)
        bcs.append(item)
        return bcs
base.py 文件源码 项目:MxOnline 作者: myTeemo 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
def get_context(self):
        new_context = {
            "opts": self.opts,
            "app_label": self.app_label,
            "model_name": self.model_name,
            "verbose_name": force_unicode(self.opts.verbose_name),
            'model_icon': self.get_model_icon(self.model),
        }
        context = super(ModelAdminView, self).get_context()
        context.update(new_context)
        return context
delete.py 文件源码 项目:MxOnline 作者: myTeemo 项目源码 文件源码 阅读 27 收藏 0 点赞 0 评论 0
def get_breadcrumb(self):
        bcs = super(DeleteAdminView, self).get_breadcrumb()
        bcs.append({
            'title': force_unicode(self.obj),
            'url': self.get_object_url(self.obj)
        })
        item = {'title': _('Delete')}
        if self.has_delete_permission():
            item['url'] = self.model_admin_url('delete', self.obj.pk)
        bcs.append(item)

        return bcs
xversion.py 文件源码 项目:MxOnline 作者: myTeemo 项目源码 文件源码 阅读 26 收藏 0 点赞 0 评论 0
def get_context(self):
        context = super(RecoverListView, self).get_context()
        opts = self.opts
        deleted = self._order_version_queryset(Version.objects.get_deleted(self.model))
        context.update({
            "opts": opts,
            "app_label": opts.app_label,
            "model_name": capfirst(opts.verbose_name),
            "title": _("Recover deleted %(name)s") % {"name": force_unicode(opts.verbose_name_plural)},
            "deleted": deleted,
            "changelist_url": self.model_admin_url("changelist"),
        })
        return context
xversion.py 文件源码 项目:MxOnline 作者: myTeemo 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def get_context(self):
        context = super(RevisionListView, self).get_context()

        opts = self.opts
        action_list = [
            {
                "revision": version.revision,
                "url": self.model_admin_url('revision', quote(version.object_id), version.id),
                "version": version
            }
            for version
            in self._reversion_order_version_queryset(Version.objects.get_for_object_reference(
                self.model,
                self.obj.pk,
            ).select_related("revision__user"))
        ]
        context.update({
            'title': _('Change history: %s') % force_unicode(self.obj),
            'action_list': action_list,
            'model_name': capfirst(force_unicode(opts.verbose_name_plural)),
            'object': self.obj,
            'app_label': opts.app_label,
            "changelist_url": self.model_admin_url("changelist"),
            "update_url": self.model_admin_url("change", self.obj.pk),
            'opts': opts,
        })
        return context
xversion.py 文件源码 项目:MxOnline 作者: myTeemo 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
def get_context(self):
        context = super(RevisionView, self).get_context()
        context["title"] = _(
            "Revert %s") % force_unicode(self.model._meta.verbose_name)
        return context
xversion.py 文件源码 项目:MxOnline 作者: myTeemo 项目源码 文件源码 阅读 36 收藏 0 点赞 0 评论 0
def post_response(self):
        self.message_user(_('The %(model)s "%(name)s" was reverted successfully. You may edit it again below.') %
                          {"model": force_unicode(self.opts.verbose_name), "name": unicode(self.new_obj)}, 'success')
        return HttpResponseRedirect(self.model_admin_url('change', self.new_obj.pk))


问题


面经


文章

微信
公众号

扫码关注公众号