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
0b908b92
Kaydet (Commit)
0b908b92
authored
Eki 18, 2012
tarafından
Ramiro Morales
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Fixed #8001 -- Made redirections after add/edit in admin customizable.
Also fixes #18310.
üst
db598dd8
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
84 additions
and
4 deletions
+84
-4
options.py
django/contrib/admin/options.py
+0
-0
admin.py
django/contrib/auth/admin.py
+2
-3
models.py
tests/regressiontests/admin_custom_urls/models.py
+37
-0
tests.py
tests/regressiontests/admin_custom_urls/tests.py
+45
-1
No files found.
django/contrib/admin/options.py
Dosyayı görüntüle @
0b908b92
This diff is collapsed.
Click to expand it.
django/contrib/auth/admin.py
Dosyayı görüntüle @
0b908b92
...
...
@@ -153,7 +153,7 @@ class UserAdmin(admin.ModelAdmin):
'admin/auth/user/change_password.html'
],
context
,
current_app
=
self
.
admin_site
.
name
)
def
response_add
(
self
,
request
,
obj
,
post_url_continue
=
'../
%
s/'
):
def
response_add
(
self
,
request
,
obj
,
**
kwargs
):
"""
Determines the HttpResponse for the add_view stage. It mostly defers to
its superclass implementation but is customized because the User model
...
...
@@ -166,8 +166,7 @@ class UserAdmin(admin.ModelAdmin):
# * We are adding a user in a popup
if
'_addanother'
not
in
request
.
POST
and
'_popup'
not
in
request
.
POST
:
request
.
POST
[
'_continue'
]
=
1
return
super
(
UserAdmin
,
self
)
.
response_add
(
request
,
obj
,
post_url_continue
)
return
super
(
UserAdmin
,
self
)
.
response_add
(
request
,
obj
,
**
kwargs
)
admin
.
site
.
register
(
Group
,
GroupAdmin
)
admin
.
site
.
register
(
User
,
UserAdmin
)
tests/regressiontests/admin_custom_urls/models.py
Dosyayı görüntüle @
0b908b92
...
...
@@ -50,3 +50,40 @@ class ActionAdmin(admin.ModelAdmin):
admin
.
site
.
register
(
Action
,
ActionAdmin
)
class
Person
(
models
.
Model
):
nick
=
models
.
CharField
(
max_length
=
20
)
class
PersonAdmin
(
admin
.
ModelAdmin
):
"""A custom ModelAdmin that customizes the deprecated post_url_continue
argument to response_add()"""
def
response_add
(
self
,
request
,
obj
,
post_url_continue
=
'../
%
s/continue/'
,
continue_url
=
None
,
add_url
=
None
,
hasperm_url
=
None
,
noperm_url
=
None
):
return
super
(
PersonAdmin
,
self
)
.
response_add
(
request
,
obj
,
post_url_continue
,
continue_url
,
add_url
,
hasperm_url
,
noperm_url
)
admin
.
site
.
register
(
Person
,
PersonAdmin
)
class
City
(
models
.
Model
):
name
=
models
.
CharField
(
max_length
=
20
)
class
CityAdmin
(
admin
.
ModelAdmin
):
"""A custom ModelAdmin that redirects to the changelist when the user
presses the 'Save and add another' button when adding a model instance."""
def
response_add
(
self
,
request
,
obj
,
add_another_url
=
'admin:admin_custom_urls_city_changelist'
,
**
kwargs
):
return
super
(
CityAdmin
,
self
)
.
response_add
(
request
,
obj
,
add_another_url
=
add_another_url
,
**
kwargs
)
admin
.
site
.
register
(
City
,
CityAdmin
)
tests/regressiontests/admin_custom_urls/tests.py
Dosyayı görüntüle @
0b908b92
from
__future__
import
absolute_import
,
unicode_literals
import
warnings
from
django.contrib.admin.util
import
quote
from
django.core.urlresolvers
import
reverse
from
django.template.response
import
TemplateResponse
from
django.test
import
TestCase
from
django.test.utils
import
override_settings
from
.models
import
Action
from
.models
import
Action
,
Person
,
City
@override_settings
(
PASSWORD_HASHERS
=
(
'django.contrib.auth.hashers.SHA1PasswordHasher'
,))
...
...
@@ -81,3 +83,45 @@ class AdminCustomUrlsTest(TestCase):
self
.
assertEqual
(
response
.
status_code
,
200
)
self
.
assertContains
(
response
,
'Change action'
)
self
.
assertContains
(
response
,
'value="path/to/html/document.html"'
)
@override_settings
(
PASSWORD_HASHERS
=
(
'django.contrib.auth.hashers.SHA1PasswordHasher'
,))
class
CustomUrlsWorkflowTests
(
TestCase
):
fixtures
=
[
'users.json'
]
def
setUp
(
self
):
self
.
client
.
login
(
username
=
'super'
,
password
=
'secret'
)
def
tearDown
(
self
):
self
.
client
.
logout
()
def
test_old_argument_deprecation
(
self
):
"""Test reporting of post_url_continue deprecation."""
post_data
=
{
'nick'
:
'johndoe'
,
}
cnt
=
Person
.
objects
.
count
()
with
warnings
.
catch_warnings
(
record
=
True
)
as
w
:
warnings
.
simplefilter
(
"always"
)
response
=
self
.
client
.
post
(
reverse
(
'admin:admin_custom_urls_person_add'
),
post_data
)
self
.
assertEqual
(
response
.
status_code
,
302
)
self
.
assertEqual
(
Person
.
objects
.
count
(),
cnt
+
1
)
# We should get a DeprecationWarning
self
.
assertEqual
(
len
(
w
),
1
)
self
.
assertTrue
(
isinstance
(
w
[
0
]
.
message
,
DeprecationWarning
))
def
test_custom_add_another_redirect
(
self
):
"""Test customizability of post-object-creation redirect URL."""
post_data
=
{
'name'
:
'Rome'
,
'_addanother'
:
'1'
,
}
cnt
=
City
.
objects
.
count
()
with
warnings
.
catch_warnings
(
record
=
True
)
as
w
:
# POST to the view whose post-object-creation redir URL argument we
# are customizing (object creation)
response
=
self
.
client
.
post
(
reverse
(
'admin:admin_custom_urls_city_add'
),
post_data
)
self
.
assertEqual
(
City
.
objects
.
count
(),
cnt
+
1
)
# Check that it redirected to the URL we set
self
.
assertRedirects
(
response
,
reverse
(
'admin:admin_custom_urls_city_changelist'
))
self
.
assertEqual
(
len
(
w
),
0
)
# We should get no DeprecationWarning
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