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


Python admin.site方法代码示例

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


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

示例1: test_check_custom_user_model_default_admin

# 需要导入模块: from django.contrib import admin [as 别名]
# 或者: from django.contrib.admin import site [as 别名]
def test_check_custom_user_model_default_admin(self):
            # Django doesn't re-register admins when using `override_settings`,
            # so we have to do it manually in this test case.
            admin.site.register(get_user_model(), UserAdmin)

            warnings = checks.check_custom_user_model(HijackAdminConfig)
            expected_warnings = [
                Warning(
                    'django-hijack-admin does not work out the box with a custom user model.',
                    hint='Please mix HijackUserAdminMixin into your custom UserAdmin.',
                    obj=settings.AUTH_USER_MODEL,
                    id='hijack_admin.W001',
                )
            ]
            self.assertEqual(warnings, expected_warnings)

            admin.site.unregister(get_user_model()) 
开发者ID:arteria,项目名称:django-hijack-admin,代码行数:19,代码来源:test_checks.py

示例2: test_email_send_action

# 需要导入模块: from django.contrib import admin [as 别名]
# 或者: from django.contrib.admin import site [as 别名]
def test_email_send_action(self):
        """
        Test re-sending of activation emails via admin action.
        
        """
        admin_class = RegistrationAdmin(RegistrationProfile, admin.site)
        
        alice = self.backend.register(_mock_request(),
                                      username='alice',
                                      email='alice@example.com',
                                      password1='swordfish')
        
        admin_class.resend_activation_email(_mock_request(),
                                            RegistrationProfile.objects.all())
        self.assertEqual(len(mail.outbox), 2) # One on registering, one more on the resend.
        
        RegistrationProfile.objects.filter(user=alice).update(activation_key=RegistrationProfile.ACTIVATED)
        admin_class.resend_activation_email(_mock_request(),
                                            RegistrationProfile.objects.all())
        self.assertEqual(len(mail.outbox), 2) # No additional email because the account has activated. 
开发者ID:znick,项目名称:anytask,代码行数:22,代码来源:backends.py

示例3: test_email_send_action_no_sites

# 需要导入模块: from django.contrib import admin [as 别名]
# 或者: from django.contrib.admin import site [as 别名]
def test_email_send_action_no_sites(self):
        """
        Test re-sending of activation emails via admin action when
        ``django.contrib.sites`` is not installed; the fallback will
        be a ``RequestSite`` instance.
        
        """
        Site._meta.installed = False
        admin_class = RegistrationAdmin(RegistrationProfile, admin.site)
        
        alice = self.backend.register(_mock_request(),
                                      username='alice',
                                      email='alice@example.com',
                                      password1='swordfish')
        
        admin_class.resend_activation_email(_mock_request(),
                                            RegistrationProfile.objects.all())
        self.assertEqual(len(mail.outbox), 2) # One on registering, one more on the resend.
        
        RegistrationProfile.objects.filter(user=alice).update(activation_key=RegistrationProfile.ACTIVATED)
        admin_class.resend_activation_email(_mock_request(),
                                            RegistrationProfile.objects.all())
        self.assertEqual(len(mail.outbox), 2) # No additional email because the account has activated.
        Site._meta.installed = True 
开发者ID:znick,项目名称:anytask,代码行数:26,代码来源:backends.py

示例4: ready

# 需要导入模块: from django.contrib import admin [as 别名]
# 或者: from django.contrib.admin import site [as 别名]
def ready(self):
        if django_version() == DjangoVersion.DJANGO_21:
            # Disable silently the package for Django => 2.1. We don't override
            # admin_site neither the default ModelAdmin.
            warnings.warn(
                'The package `admin_view_permission is deprecated in '
                'Django 2.1. Django added this functionality into the core.',
                DeprecationWarning
            )
            return

        if not isinstance(admin.site, AdminViewPermissionAdminSite):
            admin.site = AdminViewPermissionAdminSite('admin')
            admin.sites.site = admin.site

        post_migrate.connect(update_permissions) 
开发者ID:ctxis,项目名称:django-admin-view-permission,代码行数:18,代码来源:apps.py

示例5: test_changelist_view

# 需要导入模块: from django.contrib import admin [as 别名]
# 或者: from django.contrib.admin import site [as 别名]
def test_changelist_view(self):
        request = RequestFactory().get('/')
        request.user = User.objects.create(username='name', password='pass', is_superuser=True)
        admin_obj = PreferencesAdmin(MyPreferences, admin.site)

        # With only one preferences object redirect to its change view.
        response = admin_obj.changelist_view(request)
        self.assertEqual(response.status_code, 302)
        self.assertEqual(response.url, '/admin/tests/mypreferences/1/change/')

        # With multiple preferences display listing view.
        MyPreferences.objects.create()
        response = admin_obj.changelist_view(request)
        response.render()
        self.failUnless('changelist-form' in response.content, 'Should \
display listing if multiple preferences objects are available.') 
开发者ID:82Flex,项目名称:DCRM,代码行数:18,代码来源:test_all.py

示例6: test_get_queryset

# 需要导入模块: from django.contrib import admin [as 别名]
# 或者: from django.contrib.admin import site [as 别名]
def test_get_queryset(self):
        # Should return preferences without sites.
        # Shouldn't fail on duplicates.
        self.failIf(MyPreferences.singleton.get().sites.all(), "Without \
                SITE_ID should not have any preferences with sites.")

        # Should return preferences for current site.
        # Shouldn't fail on duplicates.
        settings.SITE_ID = 1
        current_site = Site.objects.get_current()
        obj = MyPreferences.singleton.get()
        self.failUnlessEqual(current_site, obj.sites.get(), "With SITE_ID \
                should have preferences for current site.")

        # Should return preferences for current site.
        # Shouldn't fail on duplicates.
        settings.SITE_ID = 2
        second_site, created = Site.objects.get_or_create(id=2)
        obj = MyPreferences.singleton.get()
        self.failUnlessEqual(second_site, obj.sites.get(), "With SITE_ID \
                should have preferences for current site.") 
开发者ID:82Flex,项目名称:DCRM,代码行数:23,代码来源:test_all.py

示例7: get_admin_site

# 需要导入模块: from django.contrib import admin [as 别名]
# 或者: from django.contrib.admin import site [as 别名]
def get_admin_site(current_app):
    """
    Method tries to get actual admin.site class, if any custom admin sites
    were used. Couldn't find any other references to actual class other than
    in func_closer dict in index() func returned by resolver.
    """
    try:
        resolver_match = resolve(reverse('%s:index' % current_app))
        # Django 1.9 exposes AdminSite instance directly on view function
        if hasattr(resolver_match.func, 'admin_site'):
            return resolver_match.func.admin_site

        for func_closure in resolver_match.func.__closure__:
            if isinstance(func_closure.cell_contents, AdminSite):
                return func_closure.cell_contents
    except:
        pass
    from django.contrib import admin
    return admin.site 
开发者ID:82Flex,项目名称:DCRM,代码行数:21,代码来源:suit_menu.py

示例8: test_datefilter_filtered

# 需要导入模块: from django.contrib import admin [as 别名]
# 或者: from django.contrib.admin import site [as 别名]
def test_datefilter_filtered(self):
        self.request_factory = RequestFactory()
        modeladmin = RangeModelDTAdmin(RangeModelDT, site)

        request = self.request_factory.get('/', {'created_at__range__gte': self.today,
                                                 'created_at__range__lte': self.tomorrow})
        request.user = self.user

        changelist = self.get_changelist(request, RangeModelDT, modeladmin)

        queryset = changelist.get_queryset(request)

        self.assertEqual(list(queryset), [self.django_book])
        filterspec = changelist.get_filters(request)[0][0]
        self.assertEqual(force_str(filterspec.title), 'created at')

        choice = select_by(filterspec.choices(changelist))
        self.assertEqual(choice['query_string'], '?')
        self.assertEqual(choice['system_name'], 'created-at') 
开发者ID:silentsokolov,项目名称:django-admin-rangefilter,代码行数:21,代码来源:tests.py

示例9: test_datefilter_with_default

# 需要导入模块: from django.contrib import admin [as 别名]
# 或者: from django.contrib.admin import site [as 别名]
def test_datefilter_with_default(self):
        self.request_factory = RequestFactory()
        modeladmin = RangeModelDTAdmin(RangeModelDT, site)
        modeladmin.get_rangefilter_created_at_default = lambda r: [self.today, self.tomorrow]

        request = self.request_factory.get('/')
        request.user = self.user

        changelist = self.get_changelist(request, RangeModelDT, modeladmin)

        queryset = changelist.get_queryset(request)

        self.assertEqual(list(queryset), [self.djangonaut_book, self.django_book])
        filterspec = changelist.get_filters(request)[0][0]
        self.assertEqual(force_str(filterspec.title), 'created at')
        self.assertEqual(filterspec.default_gte, self.today)
        self.assertEqual(filterspec.default_lte, self.tomorrow) 
开发者ID:silentsokolov,项目名称:django-admin-rangefilter,代码行数:19,代码来源:tests.py

示例10: test_datefilter_filtered_with_one_params

# 需要导入模块: from django.contrib import admin [as 别名]
# 或者: from django.contrib.admin import site [as 别名]
def test_datefilter_filtered_with_one_params(self):
        self.request_factory = RequestFactory()
        modeladmin = RangeModelDTAdmin(RangeModelDT, site)

        request = self.request_factory.get('/', {'created_at__range__gte': self.today})
        request.user = self.user

        changelist = self.get_changelist(request, RangeModelDT, modeladmin)

        queryset = changelist.get_queryset(request)

        self.assertEqual(list(queryset), [self.django_book])
        filterspec = changelist.get_filters(request)[0][0]
        self.assertEqual(force_str(filterspec.title), 'created at')

        choice = select_by(filterspec.choices(changelist))
        self.assertEqual(choice['query_string'], '?')
        self.assertEqual(choice['system_name'], 'created-at') 
开发者ID:silentsokolov,项目名称:django-admin-rangefilter,代码行数:20,代码来源:tests.py

示例11: test_datefilter_filtered_datefield

# 需要导入模块: from django.contrib import admin [as 别名]
# 或者: from django.contrib.admin import site [as 别名]
def test_datefilter_filtered_datefield(self):
        self.request_factory = RequestFactory()
        modeladmin = RangeModelDAdmin(RangeModelD, site)

        request = self.request_factory.get('/', {'created_at__range__gte': self.today,
                                                 'created_at__range__lte': self.tomorrow})
        request.user = self.user

        changelist = self.get_changelist(request, RangeModelD, modeladmin)

        queryset = changelist.get_queryset(request)

        self.assertEqual(list(queryset), [self.django_book_date])
        filterspec = changelist.get_filters(request)[0][0]
        self.assertEqual(force_str(filterspec.title), 'created at')

        choice = select_by(filterspec.choices(changelist))
        self.assertEqual(choice['query_string'], '?')
        self.assertEqual(choice['system_name'], 'created-at') 
开发者ID:silentsokolov,项目名称:django-admin-rangefilter,代码行数:21,代码来源:tests.py

示例12: test_datetimfilter_filtered

# 需要导入模块: from django.contrib import admin [as 别名]
# 或者: from django.contrib.admin import site [as 别名]
def test_datetimfilter_filtered(self):
        self.request_factory = RequestFactory()
        modeladmin = RangeModelDTTimeAdmin(RangeModelDT, site)

        request = self.request_factory.get('/', {'created_at__range__gte_0': self.today,
                                                 'created_at__range__gte_1': self.min_time,
                                                 'created_at__range__lte_0': self.tomorrow,
                                                 'created_at__range__lte_1': self.max_time})
        request.user = self.user

        changelist = self.get_changelist(request, RangeModelDT, modeladmin)

        queryset = changelist.get_queryset(request)

        self.assertEqual(list(queryset), [self.django_book])
        filterspec = changelist.get_filters(request)[0][0]
        self.assertEqual(force_str(filterspec.title), 'created at')

        choice = select_by(filterspec.choices(changelist))
        self.assertEqual(choice['query_string'], '?')
        self.assertEqual(choice['system_name'], 'created-at') 
开发者ID:silentsokolov,项目名称:django-admin-rangefilter,代码行数:23,代码来源:tests.py

示例13: test_datetimfilter_with_default

# 需要导入模块: from django.contrib import admin [as 别名]
# 或者: from django.contrib.admin import site [as 别名]
def test_datetimfilter_with_default(self):
        self.request_factory = RequestFactory()
        modeladmin = RangeModelDTTimeAdmin(RangeModelDT, site)
        modeladmin.get_rangefilter_created_at_default = lambda r: [self.today, self.tomorrow]

        request = self.request_factory.get('/')
        request.user = self.user

        changelist = self.get_changelist(request, RangeModelDT, modeladmin)

        queryset = changelist.get_queryset(request)

        self.assertEqual(list(queryset), [self.djangonaut_book, self.django_book])
        filterspec = changelist.get_filters(request)[0][0]
        self.assertEqual(force_str(filterspec.title), 'created at')
        self.assertEqual(filterspec.default_gte, self.today)
        self.assertEqual(filterspec.default_lte, self.tomorrow) 
开发者ID:silentsokolov,项目名称:django-admin-rangefilter,代码行数:19,代码来源:tests.py

示例14: get_admin_site

# 需要导入模块: from django.contrib import admin [as 别名]
# 或者: from django.contrib.admin import site [as 别名]
def get_admin_site(current_app):
    """
    Method tries to get actual admin.site class, if any custom admin sites
    were used. Couldn't find any other references to actual class other than
    in func_closer dict in index() func returned by resolver.
    """
    try:
        resolver_match = resolve(reverse('%s:index' % current_app))
        # Django 1.9 exposes AdminSite instance directly on view function
        if hasattr(resolver_match.func, 'admin_site'):
            return resolver_match.func.admin_site

        for func_closure in resolver_match.func.__closure__:
            if isinstance(func_closure.cell_contents, AdminSite):
                return func_closure.cell_contents
    except:
        pass
    return admin.site 
开发者ID:ra-systems,项目名称:django-ra-erp,代码行数:20,代码来源:suit_menu.py

示例15: test_list_filter_queryset_filters_objects_correctly

# 需要导入模块: from django.contrib import admin [as 别名]
# 或者: from django.contrib.admin import site [as 别名]
def test_list_filter_queryset_filters_objects_correctly(self):
        StringEnumeratedModel.objects.create(enumeration=CharTestEnum.FIRST)
        StringEnumeratedModel.objects.create(enumeration=CharTestEnum.SECOND)
        StringEnumeratedModel.objects.create(enumeration=CharTestEnum.THIRD)

        modeladmin = StringEnumAdmin(
            StringEnumeratedModel,
            admin.site
        )

        for enumeration in CharTestEnum:
            request = self.request_factory.get('/', {'enumeration__exact': enumeration.value})
            request.user = self.user

            changelist = self.get_changelist_instance(request, StringEnumeratedModel, modeladmin)

            self.assertEqual(changelist.queryset.count(), 1) 
开发者ID:HackSoftware,项目名称:django-enum-choices,代码行数:19,代码来源:test_admin_filter.py


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