本文整理匯總了Python中django.contrib.admin.AdminSite.each_context方法的典型用法代碼示例。如果您正苦於以下問題:Python AdminSite.each_context方法的具體用法?Python AdminSite.each_context怎麽用?Python AdminSite.each_context使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類django.contrib.admin.AdminSite
的用法示例。
在下文中一共展示了AdminSite.each_context方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: test_history_form_view_accepts_additional_context
# 需要導入模塊: from django.contrib.admin import AdminSite [as 別名]
# 或者: from django.contrib.admin.AdminSite import each_context [as 別名]
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
)
示例2: test_history_form_view_getting_history_abstract_external
# 需要導入模塊: from django.contrib.admin import AdminSite [as 別名]
# 或者: from django.contrib.admin.AdminSite import each_context [as 別名]
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
)