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


Python helpers.AdminForm方法代码示例

本文整理汇总了Python中django.contrib.admin.helpers.AdminForm方法的典型用法代码示例。如果您正苦于以下问题:Python helpers.AdminForm方法的具体用法?Python helpers.AdminForm怎么用?Python helpers.AdminForm使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在django.contrib.admin.helpers的用法示例。


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

示例1: select_site_view

# 需要导入模块: from django.contrib.admin import helpers [as 别名]
# 或者: from django.contrib.admin.helpers import AdminForm [as 别名]
def select_site_view(self, request, form_url=''):
        """
        Display a choice form to select which site to add settings.
        """
        if not self.has_add_permission(request):
            raise PermissionDenied

        extra_qs = ''
        if request.META['QUERY_STRING']:
            extra_qs = '&' + request.META['QUERY_STRING']

        site_choices = self.get_site_choices()

        if len(site_choices) == 1:
            return HttpResponseRedirect('?site_id={0}{1}'.format(site_choices[0][0], extra_qs))

        # Create form
        form = self.select_site_form(
            data=request.POST if request.method == 'POST' else None,
            initial={'site': site_choices[0][0]}
        )

        form.fields['site'].choices = site_choices

        if form.is_valid():
            return HttpResponseRedirect(
                '?site_id={0}{1}'.format(form.cleaned_data['site'], extra_qs))

        # Wrap in all admin layout
        fieldsets = ((None, {'fields': ('site',)}),)
        adminForm = AdminForm(form, fieldsets, {}, model_admin=self)
        media = self.media + adminForm.media

        context = {
            'title': _('Add %s') % force_text(self.opts.verbose_name),
            'adminform': adminForm,
            'is_popup': '_popup' in request.GET,
            'media': mark_safe(media),
            'errors': AdminErrorList(form, ()),
            'app_label': self.opts.app_label,
        }

        return self.render_select_site_form(request, context, form_url) 
开发者ID:mishbahr,项目名称:django-usersettings2,代码行数:45,代码来源:admin.py

示例2: add_view

# 需要导入模块: from django.contrib.admin import helpers [as 别名]
# 或者: from django.contrib.admin.helpers import AdminForm [as 别名]
def add_view(self, request, form_url='', extra_context=None):
        if not self.has_add_permission(request):
            raise PermissionDenied

        data = None

        changelist_filters = request.GET.get('_changelist_filters')
        if request.method == 'GET' and changelist_filters is not None:
            changelist_filters = dict(parse_qsl(changelist_filters))
            if 'provider' in changelist_filters:
                data = {
                    'provider': changelist_filters['provider']
                }

        form = AccountCreationForm(data=request.POST if request.method == 'POST' else data)

        if form.is_valid():
            info = self.model._meta.app_label, self.model._meta.model_name
            preserved_filters = self.get_preserved_filters(request)
            request.session[PRESERVED_FILTERS_SESSION_KEY] = preserved_filters
            redirect_url = reverse('admin:%s_%s_login' % info,
                                   kwargs={'provider': form.cleaned_data['provider']})
            return redirect(redirect_url)

        fieldsets = (
            (None, {
                'fields': ('provider', )
            }),
        )

        adminForm = helpers.AdminForm(form, list(fieldsets), {}, model_admin=self)
        media = self.media + adminForm.media

        context = dict(
            adminform=adminForm,
            is_popup=IS_POPUP_VAR in request.GET,
            media=media,
            errors=helpers.AdminErrorList(form, ()),
            preserved_filters=self.get_preserved_filters(request),
        )

        context.update(extra_context or {})
        return self.render_change_form(request, context, add=True, change=False, form_url=form_url) 
开发者ID:mishbahr,项目名称:django-connected,代码行数:45,代码来源:admin.py


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