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
bcf700b4
Kaydet (Commit)
bcf700b4
authored
Mar 13, 2015
tarafından
Riccardo Magliocchetti
Kaydeden (comit)
Tim Graham
Nis 15, 2015
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Removed code duplication between AdminSite.index() and app_index().
üst
a429a502
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
70 additions
and
83 deletions
+70
-83
sites.py
django/contrib/admin/sites.py
+70
-83
No files found.
django/contrib/admin/sites.py
Dosyayı görüntüle @
bcf700b4
...
...
@@ -394,53 +394,80 @@ class AdminSite(object):
}
return
login
(
request
,
**
defaults
)
@never_cache
def
index
(
self
,
request
,
extra_context
=
None
):
def
_build_app_dict
(
self
,
request
,
label
=
None
):
"""
Displays the main admin index page, which lists all of the installed
apps that have been registered in this site
.
Builds the app dictionary. Takes an optional label parameters to filter
models of a specific app
.
"""
app_dict
=
{}
for
model
,
model_admin
in
self
.
_registry
.
items
():
if
label
:
models
=
{
m
:
m_a
for
m
,
m_a
in
self
.
_registry
.
items
()
if
m
.
_meta
.
app_label
==
label
}
else
:
models
=
self
.
_registry
for
model
,
model_admin
in
models
.
items
():
app_label
=
model
.
_meta
.
app_label
has_module_perms
=
model_admin
.
has_module_permission
(
request
)
if
not
has_module_perms
:
if
label
:
raise
PermissionDenied
continue
perms
=
model_admin
.
get_model_perms
(
request
)
# Check whether user has any perm for this module.
# If so, add the module to the model_list.
if
True
not
in
perms
.
values
():
continue
info
=
(
app_label
,
model
.
_meta
.
model_name
)
model_dict
=
{
'name'
:
capfirst
(
model
.
_meta
.
verbose_name_plural
),
'object_name'
:
model
.
_meta
.
object_name
,
'perms'
:
perms
,
}
if
perms
.
get
(
'change'
):
try
:
model_dict
[
'admin_url'
]
=
reverse
(
'admin:
%
s_
%
s_changelist'
%
info
,
current_app
=
self
.
name
)
except
NoReverseMatch
:
pass
if
perms
.
get
(
'add'
):
try
:
model_dict
[
'add_url'
]
=
reverse
(
'admin:
%
s_
%
s_add'
%
info
,
current_app
=
self
.
name
)
except
NoReverseMatch
:
pass
if
app_label
in
app_dict
:
app_dict
[
app_label
][
'models'
]
.
append
(
model_dict
)
else
:
app_dict
[
app_label
]
=
{
'name'
:
apps
.
get_app_config
(
app_label
)
.
verbose_name
,
'app_label'
:
app_label
,
'app_url'
:
reverse
(
'admin:app_list'
,
kwargs
=
{
'app_label'
:
app_label
},
current_app
=
self
.
name
,
),
'has_module_perms'
:
has_module_perms
,
'models'
:
[
model_dict
],
}
if
label
:
return
app_dict
.
get
(
label
)
return
app_dict
if
has_module_perms
:
perms
=
model_admin
.
get_model_perms
(
request
)
# Check whether user has any perm for this module.
# If so, add the module to the model_list.
if
True
in
perms
.
values
():
info
=
(
app_label
,
model
.
_meta
.
model_name
)
model_dict
=
{
'name'
:
capfirst
(
model
.
_meta
.
verbose_name_plural
),
'object_name'
:
model
.
_meta
.
object_name
,
'perms'
:
perms
,
}
if
perms
.
get
(
'change'
,
False
):
try
:
model_dict
[
'admin_url'
]
=
reverse
(
'admin:
%
s_
%
s_changelist'
%
info
,
current_app
=
self
.
name
)
except
NoReverseMatch
:
pass
if
perms
.
get
(
'add'
,
False
):
try
:
model_dict
[
'add_url'
]
=
reverse
(
'admin:
%
s_
%
s_add'
%
info
,
current_app
=
self
.
name
)
except
NoReverseMatch
:
pass
if
app_label
in
app_dict
:
app_dict
[
app_label
][
'models'
]
.
append
(
model_dict
)
else
:
app_dict
[
app_label
]
=
{
'name'
:
apps
.
get_app_config
(
app_label
)
.
verbose_name
,
'app_label'
:
app_label
,
'app_url'
:
reverse
(
'admin:app_list'
,
kwargs
=
{
'app_label'
:
app_label
},
current_app
=
self
.
name
,
),
'has_module_perms'
:
has_module_perms
,
'models'
:
[
model_dict
],
}
@never_cache
def
index
(
self
,
request
,
extra_context
=
None
):
"""
Displays the main admin index page, which lists all of the installed
apps that have been registered in this site.
"""
app_dict
=
self
.
_build_app_dict
(
request
)
# Sort the apps alphabetically.
app_list
=
list
(
six
.
itervalues
(
app_dict
))
...
...
@@ -463,52 +490,12 @@ class AdminSite(object):
'admin/index.html'
,
context
)
def
app_index
(
self
,
request
,
app_label
,
extra_context
=
None
):
app_name
=
apps
.
get_app_config
(
app_label
)
.
verbose_name
app_dict
=
{}
for
model
,
model_admin
in
self
.
_registry
.
items
():
if
app_label
==
model
.
_meta
.
app_label
:
has_module_perms
=
model_admin
.
has_module_permission
(
request
)
if
not
has_module_perms
:
raise
PermissionDenied
perms
=
model_admin
.
get_model_perms
(
request
)
# Check whether user has any perm for this module.
# If so, add the module to the model_list.
if
True
in
perms
.
values
():
info
=
(
app_label
,
model
.
_meta
.
model_name
)
model_dict
=
{
'name'
:
capfirst
(
model
.
_meta
.
verbose_name_plural
),
'object_name'
:
model
.
_meta
.
object_name
,
'perms'
:
perms
,
}
if
perms
.
get
(
'change'
):
try
:
model_dict
[
'admin_url'
]
=
reverse
(
'admin:
%
s_
%
s_changelist'
%
info
,
current_app
=
self
.
name
)
except
NoReverseMatch
:
pass
if
perms
.
get
(
'add'
):
try
:
model_dict
[
'add_url'
]
=
reverse
(
'admin:
%
s_
%
s_add'
%
info
,
current_app
=
self
.
name
)
except
NoReverseMatch
:
pass
if
app_dict
:
app_dict
[
'models'
]
.
append
(
model_dict
),
else
:
# First time around, now that we know there's
# something to display, add in the necessary meta
# information.
app_dict
=
{
'name'
:
app_name
,
'app_label'
:
app_label
,
'app_url'
:
''
,
'has_module_perms'
:
has_module_perms
,
'models'
:
[
model_dict
],
}
app_dict
=
self
.
_build_app_dict
(
request
,
app_label
)
if
not
app_dict
:
raise
Http404
(
'The requested admin page does not exist.'
)
# Sort the models alphabetically within each app.
app_dict
[
'models'
]
.
sort
(
key
=
lambda
x
:
x
[
'name'
])
app_name
=
apps
.
get_app_config
(
app_label
)
.
verbose_name
context
=
dict
(
self
.
each_context
(
request
),
title
=
_
(
'
%(app)
s administration'
)
%
{
'app'
:
app_name
},
app_list
=
[
app_dict
],
...
...
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