我们从Python开源项目中,提取了以下36个代码示例,用于说明如何使用django.contrib.admin.sites.AdminSite()。
def setUp(self): self.site = AdminSite() self.client = Client() self.factory = RequestFactory() # def test_spider_admin(self): # client = Client() # client.login(username='admin', password='pass') # base_admin = '/admin/driver27' # models = ['circuit', 'competition', 'driver', 'grandprix', 'race', 'season', 'seat', 'team'] # for model in models: # url = base_admin + '/' + model + '/' # resp = client.get(url, follow=True) # self.assertEqual(resp.status_code, 200, url + ' code='+str(resp.status_code)) # url = base_admin + '/' + model + '/add/' # resp = client.get(url, follow=True) # self.assertEqual(resp.status_code, 200, url + ' code='+str(resp.status_code)) # url = base_admin + '/' + model + '/1/change/' # resp = client.get(url, follow=True) # self.assertEqual(resp.status_code, 200, url + ' code='+str(resp.status_code))
def setup_scheduler(self, app): self.app = app self.site = AdminSite() self.request_factory = RequestFactory() entry_name, entry = self.create_conf_entry() self.app.conf.beat_schedule = {entry_name: entry} self.m1 = PeriodicTask(name=entry_name) self.m1.task = 'celery.backend_cleanup' self.m1.save() entry_name, entry = self.create_conf_entry() self.app.conf.beat_schedule = {entry_name: entry} self.m2 = PeriodicTask(name=entry_name) self.m2.task = 'celery.backend_cleanup' self.m2.save()
def register(*models, **kwargs): """ Registers the given model(s) classes and wrapped ModelAdmin class with admin site: @register(Author) class AuthorAdmin(admin.ModelAdmin): pass A kwarg of `site` can be passed as the admin site, otherwise the default admin site will be used. """ from django.contrib.admin import ModelAdmin from django.contrib.admin.sites import site, AdminSite def _model_admin_wrapper(admin_class): admin_site = kwargs.pop('site', site) if not isinstance(admin_site, AdminSite): raise ValueError('site must subclass AdminSite') if not issubclass(admin_class, ModelAdmin): raise ValueError('Wrapped class must subclass ModelAdmin.') admin_site.register(models, admin_class=admin_class) return admin_class return _model_admin_wrapper
def register(*models, **kwargs): """ Registers the given model(s) classes and wrapped ModelAdmin class with admin site: @register(Author) class AuthorAdmin(admin.ModelAdmin): pass A kwarg of `site` can be passed as the admin site, otherwise the default admin site will be used. """ from django.contrib.admin import ModelAdmin from django.contrib.admin.sites import site, AdminSite def _model_admin_wrapper(admin_class): if not models: raise ValueError('At least one model must be passed to register.') admin_site = kwargs.pop('site', site) if not isinstance(admin_site, AdminSite): raise ValueError('site must subclass AdminSite') if not issubclass(admin_class, ModelAdmin): raise ValueError('Wrapped class must subclass ModelAdmin.') admin_site.register(models, admin_class=admin_class) return admin_class return _model_admin_wrapper
def test_default_fields(self): """ Tests widget. """ ma = ModelAdmin(Pizza, AdminSite) self.assertEqual( list(ma.get_form(request).base_fields), ['toppings', 'cheeses']) self.assertEqual( list(ma.get_fields(request)), ['toppings', 'cheeses']) self.assertEqual(ma.get_fields(request), ['toppings', 'cheeses'])
def setUp(self): sc, *_ = State.objects.get_or_create(abbr='SC', name='Santa Catarina') go, *_ = State.objects.get_or_create(abbr='GO', name='Goiás') props = {'name': 'Xpto', 'url': 'http://xp.to', 'source': 'http://twitter.com/xpto', 'category': Provider.FAME, 'other': 'Lorem ipsum'} self.provider = Provider.objects.create(**props) self.provider.coverage = [sc, go] self.admin = ProviderModelAdmin(Provider, AdminSite())
def setUp(self): self.site = AdminSite()
def setUp(self): self.site = AdminSite() self.client = Client() self.factory = RequestFactory()
def setup_method(self, method): class MockRequest: class FILES: @classmethod def getlist(cls, attr): return TestAdminMedia.data[attr] self.site = AdminSite() self.request = MockRequest
def admin_site(): return AdminSite()
def setUp(self): self.factory = RequestFactory() self.site = AdminSite() self.ma = admin.ModelAdmin(Theme, self.site) self.t1 = Theme.objects.create( name="Test1", description="Test Description", default_theme=True, active_theme=True, title="Test Title", tagline="Test Tagline", running_hex="ffffff", running_text_hex="ffffff", running_link_hex="ffffff", pb_text="Test Powered By Text", pb_link="http://boundlessgeo.com/", docs_text="Documentation", docs_link="/static/docs/index.html", background_logo="theme/img/default-background.png", primary_logo="theme/img/default-primary-logo.png", banner_logo="theme/img/default-banner-logo.png" ) self.t1.save() self.t2 = Theme.objects.create( name="Test2", description="Test Description", default_theme=False, active_theme=True, title="Test Title", tagline="Test Tagline", running_hex="ffffff", running_text_hex="ffffff", running_link_hex="ffffff", pb_text="Test Powered By Text", pb_link="http://boundlessgeo.com/", docs_text="Documentation", docs_link="https://boundlessgeo.github.io/exchange-documentation/", background_logo=None, primary_logo=None, banner_logo=None ) self.t2.save()