本文整理汇总了Python中django.contrib.admin.AdminSite类的典型用法代码示例。如果您正苦于以下问题:Python AdminSite类的具体用法?Python AdminSite怎么用?Python AdminSite使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了AdminSite类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_default_change_form_template
def test_default_change_form_template(self):
site = AdminSite()
site.register(SimpleModel, TranslatableAdmin)
admin = site._registry[SimpleModel]
self.assertEqual(admin.default_change_form_template, "admin/change_form.html")
# Avoid str + __proxy__ errors
self.assertEqual("default/" + admin.default_change_form_template, "default/admin/change_form.html")
示例2: test_history_form_view_accepts_additional_context
def test_history_form_view_accepts_additional_context(self):
request = RequestFactory().post("/")
request.session = "session"
request._messages = FallbackStorage(request)
request.user = self.user
poll = Poll.objects.create(question="why?", pub_date=today)
poll.question = "how?"
poll.save()
history = poll.history.all()[0]
admin_site = AdminSite()
admin = SimpleHistoryAdmin(Poll, admin_site)
with patch("simple_history.admin.render") as mock_render:
admin.history_form_view(
request,
poll.id,
history.pk,
extra_context={"anything_else": "will be merged into context"},
)
context = {
# Verify this is set for original object
"anything_else": "will be merged into context",
"original": poll,
"change_history": False,
"title": "Revert %s" % force_text(poll),
"adminform": ANY,
"object_id": poll.id,
"is_popup": False,
"media": ANY,
"errors": ANY,
"app_label": "tests",
"original_opts": ANY,
"changelist_url": "/admin/tests/poll/",
"change_url": ANY,
"history_url": "/admin/tests/poll/1/history/",
"add": False,
"change": True,
"has_add_permission": admin.has_add_permission(request),
"has_change_permission": admin.has_change_permission(request, poll),
"has_delete_permission": admin.has_delete_permission(request, poll),
"has_file_field": True,
"has_absolute_url": False,
"form_url": "",
"opts": ANY,
"content_type_id": ANY,
"save_as": admin.save_as,
"save_on_top": admin.save_on_top,
"root_path": getattr(admin_site, "root_path", None),
}
context.update(admin_site.each_context(request))
mock_render.assert_called_once_with(
request, admin.object_history_form_template, context
)
示例3: test_history_form_view_getting_history_abstract_external
def test_history_form_view_getting_history_abstract_external(self):
request = RequestFactory().post("/")
request.session = "session"
request._messages = FallbackStorage(request)
request.user = self.user
request.POST = {"_change_history": True}
obj = ConcreteExternal.objects.create(name="test")
obj.name = "new_test"
obj.save()
history = obj.history.all()[0]
admin_site = AdminSite()
admin = SimpleHistoryAdmin(ConcreteExternal, admin_site)
with patch("simple_history.admin.render") as mock_render:
with patch("simple_history.admin.SIMPLE_HISTORY_EDIT", True):
admin.history_form_view(request, obj.id, history.pk)
context = {
# Verify this is set for history object
"original": history.instance,
"change_history": True,
"title": "Revert %s" % force_text(history.instance),
"adminform": ANY,
"object_id": obj.id,
"is_popup": False,
"media": ANY,
"errors": ANY,
"app_label": "tests",
"original_opts": ANY,
"changelist_url": "/admin/tests/concreteexternal/",
"change_url": ANY,
"history_url": "/admin/tests/concreteexternal/{pk}/history/".format(
pk=obj.pk
),
"add": False,
"change": True,
"has_add_permission": admin.has_add_permission(request),
"has_change_permission": admin.has_change_permission(request, obj),
"has_delete_permission": admin.has_delete_permission(request, obj),
"has_file_field": True,
"has_absolute_url": False,
"form_url": "",
"opts": ANY,
"content_type_id": ANY,
"save_as": admin.save_as,
"save_on_top": admin.save_on_top,
"root_path": getattr(admin_site, "root_path", None),
}
context.update(admin_site.each_context(request))
mock_render.assert_called_once_with(
request, admin.object_history_form_template, context
)
示例4: __init__
def __init__(self, *args, **kwargs):
BaseAdminSite.__init__(self, *args, **kwargs)
self.register(db.User, UserAdmin)
self.register(db.Group, GroupAdmin)
self.register(db.Verbiage, VerbiageAdmin)
self.register(db.NewsArticle, ArticleAdmin)
self.register(db.ForumPost, ArticleAdmin)
self.register(db.UserInfo, UserInfoAdmin)
self.register(db.Comment, CommentAdmin)
self.register(db.RideRequest, GeoAdmin)
self.register(db.Ride, GeoAdmin)
示例5: __init__
def __init__(self, *args, **kwargs):
BaseAdminSite.__init__(self, *args, **kwargs)
self.register(db.User, UserAdmin)
self.register(db.Group, GroupAdmin)
self.register(db.Carousel, CarouselAdmin)
self.register(db.Verbiage, VerbiageAdmin)
self.register(db.NewsArticle, ArticleAdmin)
self.register(db.ForumPost, ArticleAdmin)
self.register(db.UserInfo, UserInfoAdmin)
self.register(db.Comment, CommentAdmin)
self.register(db.RideRequest, GeoAdmin)
self.register(db.Ride, GeoAdmin)
self.register(db.SpamText, admin.ModelAdmin)
self.register(db.List, ListAdmin)
self.register(db.ListMember, ListMemberAdmin)
示例6: setUp
def setUp(self):
super(TestPublishableAdmin, self).setUp()
self.page1 = Page.objects.create(slug='page1', title='page 1')
self.page2 = Page.objects.create(slug='page2', title='page 2')
self.page1.publish()
self.page2.publish()
self.author1 = Author.objects.create(name='a1')
self.author2 = Author.objects.create(name='a2')
self.author1.publish()
self.author2.publish()
self.admin_site = AdminSite('Test Admin')
class PageBlockInline(PublishableStackedInline):
model = PageBlock
class PageAdmin(PublishableAdmin):
inlines = [PageBlockInline]
self.admin_site.register(Page, PageAdmin)
self.page_admin = PageAdmin(Page, self.admin_site)
# override urls, so reverse works
settings.ROOT_URLCONF = patterns(
'',
('^admin/',
include(self.admin_site.urls)),
)
示例7: setUp
def setUp(self):
super(AdminTestCase, self).setUp()
# Have a separate site, to avoid dependency on polymorphic wrapping or standard admin configuration
self.admin_site = AdminSite()
if self.model is not None:
self.admin_register(self.model, self.admin_class)
示例8: get_urls
def get_urls(self):
from django.conf.urls.defaults import patterns, url, include
from obadmin.admin.urls import urlpatterns as local_urls
url_patterns = local_urls
url_patterns += AdminSite.get_urls(self)
return url_patterns
示例9: get_urls
def get_urls(self):
urlpatterns = DjangoAdminSite.get_urls(self)
urlpatterns += patterns('',
url(r'^confirm_script$', is_staff(ConfirmScriptView.as_view()), name='confirm_script'),
url(r'^run_script$', is_staff(RunScriptView.as_view()), name='run_script'),
url(r'^kill_script$', is_staff(KillScriptView.as_view()), name='kill_script')
)
return urlpatterns
示例10: get_urls
def get_urls(self):
"""
Add some extra URLs to the admin site, as per
https://docs.djangoproject.com/en/dev/ref/contrib/admin/#adding-views-to-admin-sites
"""
from obadmin.admin.urls import urlpatterns as local_urls
url_patterns = local_urls
url_patterns += AdminSite.get_urls(self)
return url_patterns
示例11: PublishPage
class PublishPage(TestCase):
def setUp(self):
super(PublishPage, self).setUp()
self.admin_site = AdminSite('Test Admin')
class PageAdmin(PublishableAdmin):
pass
self.admin_site.register(Page, PageAdmin)
self.page_admin = PageAdmin(Page, self.admin_site)
def test_should_be_publish(self):
self.page1 = Page.objects.create(slug='page1', title='page 1')
user1 = User.objects.create_superuser('test1', '[email protected]',
'pass')
self.factory = RequestFactory()
request = self.factory.post('/publish/change_view',
data={'_publish': ''})
request.user = user1
self.page_admin.change_view(request, str(self.page1.id))
self.assertEqual(Page.objects.filter(Page.Q_PUBLISHED,
slug=self.page1.slug).count(), 1)
def test_should_be_republish(self):
self.page1 = Page.objects.create(slug='page1', title='page 1')
self.page1.publish()
user1 = User.objects.create_superuser('test1', '[email protected]',
'pass')
self.factory = RequestFactory()
request = self.factory.post('/publish/change_view',
data={'_publish': ''})
request.user = user1
self.page_admin.change_view(request, str(self.page1.id))
self.assertEqual(Page.objects.filter(Page.Q_PUBLISHED,
slug=self.page1.slug).count(), 1)
示例12: TestGetGrootPermissions
class TestGetGrootPermissions(TestCase):
def setUp(self):
self.site = AdminSite(name='admin')
def test_default_perms(self):
self.site.register(Author, AuthorAdmin)
author_admin = self.site._registry[Author]
permissions = author_admin.get_groot_permissions(request=None)
self.assertListEqual(
list(permissions.values_list('codename', flat=True)),
['add_author', 'change_author', 'delete_author'],
)
def test_limited_perms(self):
self.site.register(Author, AuthorAdmin, groot_permissions=('add_author',))
author_admin = self.site._registry[Author]
permissions = author_admin.get_groot_permissions(request=None)
self.assertListEqual(
list(permissions.values_list('codename', flat=True)), ['add_author'],
)
示例13: setUp
def setUp(self):
super(TestPublishSelectedAction, self).setUp()
self.fp1 = Page.objects.create(slug='fp1', title='FP1')
self.fp2 = Page.objects.create(slug='fp2', title='FP2')
self.fp3 = Page.objects.create(slug='fp3', title='FP3')
self.admin_site = AdminSite('Test Admin')
self.page_admin = PublishableAdmin(Page, self.admin_site)
# override urls, so reverse works
settings.ROOT_URLCONF = patterns(
'',
('^admin/',
include(self.admin_site.urls)),
)
示例14: setUp
def setUp(self):
# Admin objects for all tests.
self.factory = RequestFactory()
self.admin_site = AdminSite()
self.admin_user = User.objects.get(is_superuser=True)
self.settings = override_settings(
MIDDLEWARE_CLASSES = (
'django.middleware.common.CommonMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
)
)
self.settings.enable()
示例15: AttendanceAdmin
list_filter = ["category_id", "designation"]
inlines = [AttendanceInline]
class AttendanceAdmin(admin.ModelAdmin):
list_display = ("employee_id", "date", "shift", "project")
list_filter = ["employee_id", "date", "project"]
class PaymentAdmin(admin.ModelAdmin):
list_display = ("paid_date", "amount", "paid_details", "project_id")
list_filter = ["project_id", "amount", "paid_date"]
class EmpPaymentAdmin(admin.ModelAdmin):
list_display = ("employee", "amount", "type", "month", "year")
list_filter = ["employee", "month", "year"]
site = AdminSite()
site.site_header = "Omar and Assosciates"
site.register(Project, ProjectAdmin)
site.register(Category)
site.register(Dealer)
site.register(Expense, ExpenseAdmin)
site.register(Employee, EmployeeAdmin)
site.register(Attendance, AttendanceAdmin)
site.register(EmployeePayment, EmpPaymentAdmin)
site.register(Payment, PaymentAdmin)