Skip to content
Projeler
Gruplar
Parçacıklar
Yardım
Yükleniyor...
Oturum aç / Kaydol
Gezinmeyi değiştir
D
django
Proje
Proje
Ayrıntılar
Etkinlik
Cycle Analytics
Depo (repository)
Depo (repository)
Dosyalar
Kayıtlar (commit)
Dallar (branch)
Etiketler
Katkıda bulunanlar
Grafik
Karşılaştır
Grafikler
Konular (issue)
0
Konular (issue)
0
Liste
Pano
Etiketler
Kilometre Taşları
Birleştirme (merge) Talepleri
0
Birleştirme (merge) Talepleri
0
CI / CD
CI / CD
İş akışları (pipeline)
İşler
Zamanlamalar
Grafikler
Paketler
Paketler
Wiki
Wiki
Parçacıklar
Parçacıklar
Üyeler
Üyeler
Collapse sidebar
Close sidebar
Etkinlik
Grafik
Grafikler
Yeni bir konu (issue) oluştur
İşler
Kayıtlar (commit)
Konu (issue) Panoları
Kenar çubuğunu aç
Batuhan Osman TASKAYA
django
Commits
4c02e3cd
Kaydet (Commit)
4c02e3cd
authored
Şub 28, 2018
tarafından
Tim Graham
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Refs #27728 -- Made cosmetic edits to admin template tag template overriding.
üst
fa352626
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
43 additions
and
48 deletions
+43
-48
admin_list.py
django/contrib/admin/templatetags/admin_list.py
+2
-8
admin_modify.py
django/contrib/admin/templatetags/admin_modify.py
+2
-8
base.py
django/contrib/admin/templatetags/base.py
+8
-7
index.txt
docs/ref/contrib/admin/index.txt
+3
-1
2.1.txt
docs/releases/2.1.txt
+9
-6
test_templatetags.py
tests/admin_views/test_templatetags.py
+19
-18
No files found.
django/contrib/admin/templatetags/admin_list.py
Dosyayı görüntüle @
4c02e3cd
...
...
@@ -475,17 +475,11 @@ def admin_actions_tag(parser, token):
return
InclusionAdminNode
(
parser
,
token
,
func
=
admin_actions
,
template_name
=
'actions.html'
)
def
change_list_object_tools
(
context
):
"""
Displays the row of change list object tools.
"""
return
context
@register.tag
(
name
=
'change_list_object_tools'
)
def
change_list_object_tools_tag
(
parser
,
token
):
"""Display the row of change list object tools."""
return
InclusionAdminNode
(
parser
,
token
,
func
=
change_list_object_tools
,
func
=
lambda
context
:
context
,
template_name
=
'change_list_object_tools.html'
,
)
django/contrib/admin/templatetags/admin_modify.py
Dosyayı görüntüle @
4c02e3cd
...
...
@@ -76,18 +76,12 @@ def submit_row_tag(parser, token):
return
InclusionAdminNode
(
parser
,
token
,
func
=
submit_row
,
template_name
=
'submit_line.html'
)
def
change_form_object_tools
(
context
):
"""
Displays the row of change form object tools.
"""
return
context
@register.tag
(
name
=
'change_form_object_tools'
)
def
change_form_object_tools_tag
(
parser
,
token
):
"""Display the row of change form object tools."""
return
InclusionAdminNode
(
parser
,
token
,
func
=
change_form_object_tools
,
func
=
lambda
context
:
context
,
template_name
=
'change_form_object_tools.html'
,
)
...
...
django/contrib/admin/templatetags/base.py
Dosyayı görüntüle @
4c02e3cd
...
...
@@ -4,19 +4,20 @@ from django.template.library import InclusionNode, parse_bits
class
InclusionAdminNode
(
InclusionNode
):
"""
Template tag that allows its template to be overridden per model, per app,
or globally.
"""
def
__init__
(
self
,
parser
,
token
,
func
,
template_name
,
takes_context
=
True
):
self
.
template_name
=
template_name
params
,
varargs
,
varkw
,
defaults
,
kwonly
,
kwonly_defaults
,
_
=
getfullargspec
(
func
)
if
len
(
params
)
>
0
and
params
[
0
]
==
'self'
:
params
=
params
[
1
:]
# ignore 'self'
bits
=
token
.
split_contents
()
args
,
kwargs
=
parse_bits
(
parser
,
bits
[
1
:],
params
,
varargs
,
varkw
,
defaults
,
kwonly
,
kwonly_defaults
,
takes_context
,
bits
[
0
]
)
super
()
.
__init__
(
func
=
func
,
takes_context
=
takes_context
,
args
=
args
,
kwargs
=
kwargs
,
filename
=
None
parser
,
bits
[
1
:],
params
,
varargs
,
varkw
,
defaults
,
kwonly
,
kwonly_defaults
,
takes_context
,
bits
[
0
],
)
super
()
.
__init__
(
func
,
takes_context
,
args
,
kwargs
,
filename
=
None
)
def
render
(
self
,
context
):
opts
=
context
[
'opts'
]
...
...
docs/ref/contrib/admin/index.txt
Dosyayı görüntüle @
4c02e3cd
...
...
@@ -2674,6 +2674,8 @@ And that's it! If we placed this file in the ``templates/admin/my_app``
directory, our link would appear on the change form for all models within
my_app.
.. _admin-templates-overridden-per-app-or-model:
Templates which may be overridden per app or model
--------------------------------------------------
...
...
@@ -2701,7 +2703,7 @@ app or per model. The following can:
The ability to override the ``actions.html``, ``change_form_object_tools.html``,
``change_list_object_tools.html``, ``change_list_results.html``,
``date_hierarchy.html``, ``pagination.html``, ``prepopulated_fields_js.html``,
``search_form.html``,
``submit_line.html`` templates were
added.
``search_form.html``,
and ``submit_line.html`` templates was
added.
For those templates that cannot be overridden in this way, you may still
override them for your entire project. Just place the new version in your
...
...
docs/releases/2.1.txt
Dosyayı görüntüle @
4c02e3cd
...
...
@@ -52,13 +52,16 @@ Minor features
* The new :meth:`.ModelAdmin.get_deleted_objects()` method allows customizing
the deletion process of the delete view and the "delete selected" action.
* The ``actions.html``, ``change_list_results.html``, ``date_hierarchy.html``,
``pagination.html``, ``prepopulated_fields_js.html``, ``search_form.html``
and ``submit_line.html`` templates can be overridden even per app or
per model, other than globally.
* The admin change list and change form object tools can now be overridden per app,
per model or globally with ``change_list_object_tools.html`` and
* The ``actions.html``, ``change_list_results.html``, ``date_hierarchy.html``,
``pagination.html``, ``prepopulated_fields_js.html``, ``search_form.html``,
and ``submit_line.html`` templates can now be :ref:`overridden per app or
per model <admin-templates-overridden-per-app-or-model>` (besides overridden
globally).
* The admin change list and change form object tools can now be :ref:`overridden
per app, per model, or globally <admin-templates-overridden-per-app-or-model>`
with ``change_list_object_tools.html`` and
``change_form_object_tools.html`` templates.
:mod:`django.contrib.admindocs`
...
...
tests/admin_views/test_templatetags.py
Dosyayı görüntüle @
4c02e3cd
...
...
@@ -7,7 +7,6 @@ from django.contrib.auth.admin import UserAdmin
from
django.contrib.auth.models
import
User
from
django.test
import
RequestFactory
,
TestCase
from
django.urls
import
reverse
from
django.utils.encoding
import
force_text
from
.admin
import
ArticleAdmin
,
site
from
.models
import
Article
,
Question
...
...
@@ -29,9 +28,10 @@ class AdminTemplateTagsTest(AdminViewBasicTestCase):
self
.
assertIs
(
template_context
[
'extra'
],
True
)
self
.
assertIs
(
template_context
[
'show_save'
],
True
)
def
test_
can_override_change_form_template
tags
(
self
):
def
test_
override_change_form_template_
tags
(
self
):
"""
admin_modify templatetags can follow the 'standard' search patter admin/app_label/model/template.html
admin_modify template tags follow the standard search pattern
admin/app_label/model/template.html.
"""
factory
=
RequestFactory
()
article
=
Article
.
objects
.
all
()[
0
]
...
...
@@ -43,31 +43,32 @@ class AdminTemplateTagsTest(AdminViewBasicTestCase):
response
.
render
()
self
.
assertIs
(
response
.
context_data
[
'show_publish'
],
True
)
self
.
assertIs
(
response
.
context_data
[
'extra'
],
True
)
content
=
force_text
(
response
.
content
)
self
.
assertI
s
(
'name="_save"'
in
content
,
True
)
self
.
assertI
s
(
'name="_publish"'
in
content
,
True
)
self
.
assertI
s
(
'override-change_form_object_tools'
in
content
,
True
)
self
.
assertI
s
(
'override-prepopulated_fields_js'
in
content
,
True
)
content
=
str
(
response
.
content
)
self
.
assertI
n
(
'name="_save"'
,
content
)
self
.
assertI
n
(
'name="_publish"'
,
content
)
self
.
assertI
n
(
'override-change_form_object_tools'
,
content
)
self
.
assertI
n
(
'override-prepopulated_fields_js'
,
content
)
def
test_
can_override_change_list_template
tags
(
self
):
def
test_
override_change_list_template_
tags
(
self
):
"""
admin_list templatetags can follow the 'standard' search patter admin/app_label/model/template.html
admin_list template tags follow the standard search pattern
admin/app_label/model/template.html.
"""
factory
=
RequestFactory
()
request
=
factory
.
get
(
reverse
(
'admin:admin_views_article_changelist'
))
request
.
user
=
self
.
superuser
admin
=
ArticleAdmin
(
Article
,
site
)
admin
.
date_hierarchy
=
'date'
admin
.
search_fields
=
(
'title'
,
'content'
,
)
admin
.
search_fields
=
(
'title'
,
'content'
)
response
=
admin
.
changelist_view
(
request
)
response
.
render
()
content
=
force_text
(
response
.
content
)
self
.
assertI
s
(
'override-actions'
in
content
,
True
)
self
.
assertI
s
(
'override-change_list_object_tools'
in
content
,
True
)
self
.
assertI
s
(
'override-change_list_results'
in
content
,
True
)
self
.
assertI
s
(
'override-date_hierarchy'
in
content
,
True
)
self
.
assertI
s
(
'override-pagination'
in
content
,
True
)
self
.
assertI
s
(
'override-search_form'
in
content
,
True
)
content
=
str
(
response
.
content
)
self
.
assertI
n
(
'override-actions'
,
content
)
self
.
assertI
n
(
'override-change_list_object_tools'
,
content
)
self
.
assertI
n
(
'override-change_list_results'
,
content
)
self
.
assertI
n
(
'override-date_hierarchy'
,
content
)
self
.
assertI
n
(
'override-pagination'
,
content
)
self
.
assertI
n
(
'override-search_form'
,
content
)
class
DateHierarchyTests
(
TestCase
):
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment