本文整理汇总了Python中django.contrib.admin.sites.AdminSite方法的典型用法代码示例。如果您正苦于以下问题:Python sites.AdminSite方法的具体用法?Python sites.AdminSite怎么用?Python sites.AdminSite使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类django.contrib.admin.sites
的用法示例。
在下文中一共展示了sites.AdminSite方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_admin_actions
# 需要导入模块: from django.contrib.admin import sites [as 别名]
# 或者: from django.contrib.admin.sites import AdminSite [as 别名]
def test_admin_actions(self):
complaint_admin = ComplaintModelAdmin(Complaint, AdminSite())
request = SimpleNamespace()
Complaint.objects.create(created_by=self.user.profile, status=STATUS_REPORTED)
queryset = Complaint.objects.filter(status=STATUS_REPORTED)
complaint_admin.mark_as_resolved(complaint_admin, request, queryset)
self.assertEqual(Complaint.objects.get(status=STATUS_RESOLVED).status, STATUS_RESOLVED)
Complaint.objects.create(created_by=self.user.profile, status=STATUS_REPORTED)
queryset = Complaint.objects.filter(status=STATUS_REPORTED)
complaint_admin.mark_as_in_progress(complaint_admin, request, queryset)
self.assertEqual(Complaint.objects.get(status=STATUS_IN_PROGRESS).status, STATUS_IN_PROGRESS)
Complaint.objects.create(created_by=self.user.profile, status=STATUS_REPORTED)
queryset = Complaint.objects.filter(status=STATUS_REPORTED)
complaint_admin.mark_as_deleted(complaint_admin, request, queryset)
self.assertEqual(Complaint.objects.get(status=STATUS_DELETED).status, STATUS_DELETED)
示例2: test_autocomplete_e040
# 需要导入模块: from django.contrib.admin import sites [as 别名]
# 或者: from django.contrib.admin.sites import AdminSite [as 别名]
def test_autocomplete_e040(self):
class NoSearchFieldsAdmin(ModelAdmin):
pass
class AutocompleteAdmin(ModelAdmin):
autocomplete_fields = ('featuring',)
site = AdminSite()
site.register(Band, NoSearchFieldsAdmin)
self.assertIsInvalid(
AutocompleteAdmin, Song,
msg=(
'NoSearchFieldsAdmin must define "search_fields", because '
'it\'s referenced by AutocompleteAdmin.autocomplete_fields.'
),
id='admin.E040',
invalid_obj=AutocompleteAdmin,
admin_site=site,
)
示例3: setUp
# 需要导入模块: from django.contrib.admin import sites [as 别名]
# 或者: from django.contrib.admin.sites import AdminSite [as 别名]
def setUp(self):
Site.objects.get_or_create(id=settings.SITE_ID, domain='example.com', name='example.com')
self.obj = get_usersettings_model().objects.create(**self.usersettings_data)
self.user = get_user_model().objects.create_superuser(
self.username, self.email, self.password)
self.assertTrue(self.client.login(
username=self.username, password=self.password),
'Failed to login user %s' % self.email)
factory = RequestFactory()
request = factory.get('/admin')
request.user = self.user
request.session = {}
self.request = request
self.settings_admin = SettingsAdmin(get_usersettings_model(), AdminSite())
# Hack to test this function as it calls 'messages.add'
# See https://code.djangoproject.com/ticket/17971
setattr(self.request, 'session', 'session')
messages = FallbackStorage(self.request)
setattr(self.request, '_messages', messages)
示例4: setUp
# 需要导入模块: from django.contrib.admin import sites [as 别名]
# 或者: from django.contrib.admin.sites import AdminSite [as 别名]
def setUp(self):
""" Test case setup """
self.user = User.objects.create_user('test_user', 'test_user+courses@edx.org', 'foo')
self.table_entry = CourseCreator(user=self.user)
self.table_entry.save()
self.admin = User.objects.create_user('Mark', 'admin+courses@edx.org', 'foo')
self.admin.is_staff = True
self.request = HttpRequest()
self.request.user = self.admin
self.creator_admin = CourseCreatorAdmin(self.table_entry, AdminSite())
self.studio_request_email = 'mark@marky.mark'
self.enable_creator_group_patch = {
"ENABLE_CREATOR_GROUP": True,
"STUDIO_REQUEST_EMAIL": self.studio_request_email
}
示例5: test_has_valid_migration_options
# 需要导入模块: from django.contrib.admin import sites [as 别名]
# 或者: from django.contrib.admin.sites import AdminSite [as 别名]
def test_has_valid_migration_options(self):
site = AdminSite()
product_admin = admin.ProductAdmin(models.Product, site)
obj = models.Product.objects.create(
product_id="Product",
eox_update_time_stamp=None
)
result = product_admin.has_migration_options(obj)
expected = False
assert result == expected
models.ProductMigrationOption.objects.create(
product=obj,
migration_source=models.ProductMigrationSource.objects.create(name="test")
)
result = product_admin.has_migration_options(obj)
expected = True
assert result == expected
示例6: test_preferred_replacement_option
# 需要导入模块: from django.contrib.admin import sites [as 别名]
# 或者: from django.contrib.admin.sites import AdminSite [as 别名]
def test_preferred_replacement_option(self):
site = AdminSite()
product_admin = admin.ProductAdmin(models.Product, site)
obj = models.Product.objects.create(
product_id="Product",
eox_update_time_stamp=None
)
result = product_admin.preferred_replacement_option(obj)
expected = ""
assert result == expected
models.ProductMigrationOption.objects.create(
product=obj,
migration_source=models.ProductMigrationSource.objects.create(name="test"),
replacement_product_id="MyProductId"
)
result = product_admin.preferred_replacement_option(obj)
expected = "MyProductId"
assert result == expected
示例7: test_inline_has_add_permission_uses_obj
# 需要导入模块: from django.contrib.admin import sites [as 别名]
# 或者: from django.contrib.admin.sites import AdminSite [as 别名]
def test_inline_has_add_permission_uses_obj(self):
class ConcertInline(TabularInline):
model = Concert
def has_add_permission(self, request, obj):
return bool(obj)
class BandAdmin(ModelAdmin):
inlines = [ConcertInline]
ma = BandAdmin(Band, AdminSite())
request = MockRequest()
request.user = self.MockAddUser()
self.assertEqual(ma.get_inline_instances(request), [])
band = Band(name='The Doors', bio='', sign_date=date(1965, 1, 1))
inline_instances = ma.get_inline_instances(request, band)
self.assertEqual(len(inline_instances), 1)
self.assertIsInstance(inline_instances[0], ConcertInline)
示例8: test_inline_has_add_permission_without_obj
# 需要导入模块: from django.contrib.admin import sites [as 别名]
# 或者: from django.contrib.admin.sites import AdminSite [as 别名]
def test_inline_has_add_permission_without_obj(self):
# This test will be removed in Django 3.0 when `obj` becomes a required
# argument of has_add_permission() (#27991).
class ConcertInline(TabularInline):
model = Concert
def has_add_permission(self, request):
return super().has_add_permission(request)
class BandAdmin(ModelAdmin):
inlines = [ConcertInline]
ma = BandAdmin(Band, AdminSite())
request = MockRequest()
request.user = self.MockAddUserWithInline()
band = Band(name='The Doors', bio='', sign_date=date(1965, 1, 1))
inline_instances = ma.get_inline_instances(request, band)
self.assertEqual(len(inline_instances), 1)
self.assertIsInstance(inline_instances[0], ConcertInline)
示例9: setUp
# 需要导入模块: from django.contrib.admin import sites [as 别名]
# 或者: from django.contrib.admin.sites import AdminSite [as 别名]
def setUp(self):
"""
Create a device at the fourth time step. The current token is 154567.
"""
try:
self.admin = self.create_user(
'admin', 'password', email='admin@example.com',
is_staff=True
)
except IntegrityError:
self.skipTest("Unable to create the test user.")
else:
self.device = self.admin.totpdevice_set.create(
key='2a2bbba1092ffdd25a328ad1a0a5f5d61d7aacc4', step=30,
t0=int(time() - (30 * 3)), digits=6, tolerance=0, drift=0
)
self.device_admin = TOTPDeviceAdmin(TOTPDevice, AdminSite())
self.get_request = RequestFactory().get('/')
self.get_request.user = self.admin
示例10: setUp
# 需要导入模块: from django.contrib.admin import sites [as 别名]
# 或者: from django.contrib.admin.sites import AdminSite [as 别名]
def setUp(self):
"""
Create a device at the fourth time step. The current token is 154567.
"""
try:
self.admin = self.create_user(
'admin', 'password', email='admin@example.com',
is_staff=True
)
except IntegrityError:
self.skipTest("Unable to create test user.")
else:
self.device = self.admin.hotpdevice_set.create(
key='d2e8a68036f68960b1c30532bb6c56da5934d879', digits=6,
tolerance=1, counter=0
)
self.device_admin = HOTPDeviceAdmin(HOTPDevice, AdminSite())
self.get_request = RequestFactory().get('/')
self.get_request.user = self.admin
示例11: setup
# 需要导入模块: from django.contrib.admin import sites [as 别名]
# 或者: from django.contrib.admin.sites import AdminSite [as 别名]
def setup(self, db):
self.admin_site = AdminSite()
示例12: register
# 需要导入模块: from django.contrib.admin import sites [as 别名]
# 或者: from django.contrib.admin.sites import AdminSite [as 别名]
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
示例13: setUp
# 需要导入模块: from django.contrib.admin import sites [as 别名]
# 或者: from django.contrib.admin.sites import AdminSite [as 别名]
def setUp(self):
self.first = create_account(name='first', account_type=Account.FOREIGN)
self.second = create_account(name='second', account_type=Account.FOREIGN)
self.third = create_account(name='third', account_type=Account.FOREIGN)
self.personal = create_account(name='personal')
create_transaction('first', self.personal, self.first, 50, Transaction.WITHDRAW)
create_transaction('second', self.personal, self.second, 100, Transaction.WITHDRAW)
create_transaction('second', self.personal, self.third, 25, Transaction.WITHDRAW)
self.site = AdminSite()
self.modeladmin = MockedAdmin(Account, self.site)
示例14: register
# 需要导入模块: from django.contrib.admin import sites [as 别名]
# 或者: from django.contrib.admin.sites import AdminSite [as 别名]
def register(*models, site=None):
"""
Register the given model(s) classes and wrapped ModelAdmin class with
admin site:
@register(Author)
class AuthorAdmin(admin.ModelAdmin):
pass
The `site` kwarg is an admin site to use instead of the default admin site.
"""
from django.contrib.admin import ModelAdmin
from django.contrib.admin.sites import site as default_site, AdminSite
def _model_admin_wrapper(admin_class):
if not models:
raise ValueError('At least one model must be passed to register.')
admin_site = site or default_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
示例15: setUp
# 需要导入模块: from django.contrib.admin import sites [as 别名]
# 或者: from django.contrib.admin.sites import AdminSite [as 别名]
def setUp(self):
self.ca = Ca.objects.create()
self.cert = Cert.objects.create(ca_id=self.ca.pk)
self.cert.ca = self.ca
self.site = AdminSite()