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
a43cfc23
Kaydet (Commit)
a43cfc23
authored
Eyl 09, 2018
tarafından
Tom Carrick
Kaydeden (comit)
Tim Graham
Eyl 11, 2018
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Fixed #29746 -- Fixed misleading FlatpageForm URL help text if APPEND_SLASH is disabled.
üst
5195b99e
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
24 additions
and
3 deletions
+24
-3
forms.py
django/contrib/flatpages/forms.py
+14
-3
test_forms.py
tests/flatpages_tests/test_forms.py
+10
-0
No files found.
django/contrib/flatpages/forms.py
Dosyayı görüntüle @
a43cfc23
...
@@ -22,6 +22,19 @@ class FlatpageForm(forms.ModelForm):
...
@@ -22,6 +22,19 @@ class FlatpageForm(forms.ModelForm):
model
=
FlatPage
model
=
FlatPage
fields
=
'__all__'
fields
=
'__all__'
def
__init__
(
self
,
*
args
,
**
kwargs
):
super
()
.
__init__
(
*
args
,
**
kwargs
)
if
not
self
.
_trailing_slash_required
():
self
.
fields
[
'url'
]
.
help_text
=
_
(
"Example: '/about/contact'. Make sure to have a leading slash."
)
def
_trailing_slash_required
(
self
):
return
(
settings
.
APPEND_SLASH
and
'django.middleware.common.CommonMiddleware'
in
settings
.
MIDDLEWARE
)
def
clean_url
(
self
):
def
clean_url
(
self
):
url
=
self
.
cleaned_data
[
'url'
]
url
=
self
.
cleaned_data
[
'url'
]
if
not
url
.
startswith
(
'/'
):
if
not
url
.
startswith
(
'/'
):
...
@@ -29,9 +42,7 @@ class FlatpageForm(forms.ModelForm):
...
@@ -29,9 +42,7 @@ class FlatpageForm(forms.ModelForm):
gettext
(
"URL is missing a leading slash."
),
gettext
(
"URL is missing a leading slash."
),
code
=
'missing_leading_slash'
,
code
=
'missing_leading_slash'
,
)
)
if
(
settings
.
APPEND_SLASH
and
if
self
.
_trailing_slash_required
()
and
not
url
.
endswith
(
'/'
):
'django.middleware.common.CommonMiddleware'
in
settings
.
MIDDLEWARE
and
not
url
.
endswith
(
'/'
)):
raise
forms
.
ValidationError
(
raise
forms
.
ValidationError
(
gettext
(
"URL is missing a trailing slash."
),
gettext
(
"URL is missing a trailing slash."
),
code
=
'missing_trailing_slash'
,
code
=
'missing_trailing_slash'
,
...
...
tests/flatpages_tests/test_forms.py
Dosyayı görüntüle @
a43cfc23
...
@@ -49,6 +49,11 @@ class FlatpageAdminFormTests(TestCase):
...
@@ -49,6 +49,11 @@ class FlatpageAdminFormTests(TestCase):
def
test_flatpage_requires_trailing_slash_with_append_slash
(
self
):
def
test_flatpage_requires_trailing_slash_with_append_slash
(
self
):
form
=
FlatpageForm
(
data
=
dict
(
url
=
'/no_trailing_slash'
,
**
self
.
form_data
))
form
=
FlatpageForm
(
data
=
dict
(
url
=
'/no_trailing_slash'
,
**
self
.
form_data
))
with
translation
.
override
(
'en'
):
with
translation
.
override
(
'en'
):
self
.
assertEqual
(
form
.
fields
[
'url'
]
.
help_text
,
"Example: '/about/contact/'. Make sure to have leading and "
"trailing slashes."
)
self
.
assertFalse
(
form
.
is_valid
())
self
.
assertFalse
(
form
.
is_valid
())
self
.
assertEqual
(
form
.
errors
[
'url'
],
[
"URL is missing a trailing slash."
])
self
.
assertEqual
(
form
.
errors
[
'url'
],
[
"URL is missing a trailing slash."
])
...
@@ -56,6 +61,11 @@ class FlatpageAdminFormTests(TestCase):
...
@@ -56,6 +61,11 @@ class FlatpageAdminFormTests(TestCase):
def
test_flatpage_doesnt_requires_trailing_slash_without_append_slash
(
self
):
def
test_flatpage_doesnt_requires_trailing_slash_without_append_slash
(
self
):
form
=
FlatpageForm
(
data
=
dict
(
url
=
'/no_trailing_slash'
,
**
self
.
form_data
))
form
=
FlatpageForm
(
data
=
dict
(
url
=
'/no_trailing_slash'
,
**
self
.
form_data
))
self
.
assertTrue
(
form
.
is_valid
())
self
.
assertTrue
(
form
.
is_valid
())
with
translation
.
override
(
'en'
):
self
.
assertEqual
(
form
.
fields
[
'url'
]
.
help_text
,
"Example: '/about/contact'. Make sure to have a leading slash."
)
def
test_flatpage_admin_form_url_uniqueness_validation
(
self
):
def
test_flatpage_admin_form_url_uniqueness_validation
(
self
):
"The flatpage admin form correctly enforces url uniqueness among flatpages of the same site"
"The flatpage admin form correctly enforces url uniqueness among flatpages of the same site"
...
...
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