我们从Python开源项目中,提取了以下11个代码示例,用于说明如何使用django.contrib.admin.AdminSite()。
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
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
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
def report_admin(): site = AdminSite() return ReportAdmin(Report, site)
def singleton_metadata_admin(): site = AdminSite() return SingletonMetadataAdmin(SingletonMetadata, site)
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
def setUp(self): self.admin_site = AdminSite(name='test_admin')
def setUp(self): self.admin_site = AdminSite('test_admin')
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'])
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'])