當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。