Python django.contrib.admin 模块,AdminSite() 实例源码

我们从Python开源项目中,提取了以下11个代码示例,用于说明如何使用django.contrib.admin.AdminSite()

项目:ecs_sclm    作者:meaningful    | 项目源码 | 文件源码
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
项目:DCRM    作者:82Flex    | 项目源码 | 文件源码
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
项目:tumanov_castleoaks    作者:Roamdev    | 项目源码 | 文件源码
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
项目:django-tracking-analyzer    作者:jose-lpa    | 项目源码 | 文件源码
def setUp(self):
        self.tracker_1 = TrackerFactory.create(
            device_type=Tracker.PC, ip_country='ESP')
        self.tracker_2 = TrackerFactory.create(
            device_type=Tracker.MOBILE, ip_country='NLD')
        self.tracker_3 = TrackerFactory.create(
            device_type=Tracker.TABLET, ip_country='GBR')

        self.admin_site = AdminSite(name='tracker_admin')
        self.tracker_admin = TrackerAdmin(Tracker, self.admin_site)

        self.url = reverse('admin:tracking_analyzer_tracker_changelist')

        # Create a superuser and mock a request made by it.
        self.user = UserFactory.create(is_staff=True, is_superuser=True)
        self.request = RequestFactory().get('/')
        self.request.user = self.user
项目:tts-bug-bounty-dashboard    作者:18F    | 项目源码 | 文件源码
def report_admin():
    site = AdminSite()
    return ReportAdmin(Report, site)
项目:tts-bug-bounty-dashboard    作者:18F    | 项目源码 | 文件源码
def singleton_metadata_admin():
    site = AdminSite()
    return SingletonMetadataAdmin(SingletonMetadata, site)
项目:django-admin-menu    作者:cdrx    | 项目源码 | 文件源码
def get_admin_site(context):
    try:
        current_resolver = resolve(context.get('request').path)
        index_resolver = resolve(reverse('%s:index' % current_resolver.namespaces[0]))

        if hasattr(index_resolver.func, 'admin_site'):
            return index_resolver.func.admin_site

        for func_closure in index_resolver.func.__closure__:
            if isinstance(func_closure.cell_contents, admin.AdminSite):
                return func_closure.cell_contents
    except:
        pass

    return admin.site
项目:django-admin-view-permission    作者:ctxis    | 项目源码 | 文件源码
def setUp(self):
        self.admin_site = AdminSite(name='test_admin')
项目:django-admin-view-permission    作者:ctxis    | 项目源码 | 文件源码
def setUp(self):
        self.admin_site = AdminSite('test_admin')
项目:django-lti-launch    作者:unizin    | 项目源码 | 文件源码
def test_form_widgets(self):
        admin = LTIToolConsumerAdmin(LTIToolConsumer, AdminSite())
        req = self.request_factory.get('/')
        form = admin.get_form(req)
        self.assertIsNotNone(form)
        for field in ('tool_consumer_instance_guid',
                      'oauth_consumer_secret',
                      'oauth_consumer_key'):
            self.assertIn(field, form.base_fields)
            widget = form.base_fields[field].widget
            self.assertEquals(1, widget.attrs['rows'])
项目:django-lti-launch    作者:unizin    | 项目源码 | 文件源码
def test_form_widgets(self):
        admin = LTIToolProviderAdmin(LTIToolProvider, AdminSite())
        req = self.request_factory.get('/')
        form = admin.get_form(req)
        self.assertIsNotNone(form)
        self.assertIn('launch_path', form.base_fields)
        widget = form.base_fields['launch_path'].widget
        self.assertEquals(1, widget.attrs['rows'])