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
32586b0b
Kaydet (Commit)
32586b0b
authored
May 23, 2014
tarafından
Guillaume Pannatier
Kaydeden (comit)
Tim Graham
May 28, 2014
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Fixed #22684 -- Added `empty_label` option on `django.forms.extras.widets.SelectDateWidget`
Thanks danielsamuels for the report
üst
fd427f1f
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
26 additions
and
1 deletion
+26
-1
AUTHORS
AUTHORS
+1
-0
widgets.py
django/forms/extras/widgets.py
+4
-1
widgets.txt
docs/ref/forms/widgets.txt
+12
-0
1.8.txt
docs/releases/1.8.txt
+4
-0
test_extra.py
tests/forms_tests/tests/test_extra.py
+5
-0
No files found.
AUTHORS
Dosyayı görüntüle @
32586b0b
...
...
@@ -484,6 +484,7 @@ answer newbie questions, and generally made Django that much better:
oggy <ognjen.maric@gmail.com>
Tomek Paczkowski <tomek@hauru.eu>
Jens Page
Guillaume Pannatier <guillaume.pannatier@gmail.com>
Jay Parlar <parlar@gmail.com>
Carlos Eduardo de Paula <carlosedp@gmail.com>
John Paulett <john@paulett.org>
...
...
django/forms/extras/widgets.py
Dosyayı görüntüle @
32586b0b
...
...
@@ -48,7 +48,7 @@ class SelectDateWidget(Widget):
day_field
=
'
%
s_day'
year_field
=
'
%
s_year'
def
__init__
(
self
,
attrs
=
None
,
years
=
None
,
months
=
None
):
def
__init__
(
self
,
attrs
=
None
,
years
=
None
,
months
=
None
,
empty_label
=
None
):
self
.
attrs
=
attrs
or
{}
# Optional list or tuple of years to use in the "year" select box.
...
...
@@ -64,6 +64,9 @@ class SelectDateWidget(Widget):
else
:
self
.
months
=
MONTHS
if
empty_label
is
not
None
:
self
.
none_value
=
(
0
,
empty_label
)
def
render
(
self
,
name
,
value
,
attrs
=
None
):
try
:
year_val
,
month_val
,
day_val
=
value
.
year
,
value
.
month
,
value
.
day
...
...
docs/ref/forms/widgets.txt
Dosyayı görüntüle @
32586b0b
...
...
@@ -781,3 +781,15 @@ Composite widgets
5:_('may'), 6:_('jun'), 7:_('jul'), 8:_('aug'),
9:_('sep'), 10:_('oct'), 11:_('nov'), 12:_('dec')
}
.. attribute:: SelectDateWidget.empty_label
.. versionadded:: 1.8
If the :class:`~django.forms.DateField` is not required,
:class:`SelectDateWidget` will have an empty choice at the top of
the list. You can change the text of this label
(which is ``---`` by default) with the ``empty_label`` attribute::
# A custom empty label
field1 = forms.DateField(widget=SelectDateWidget(empty_label="Nothing"))
docs/releases/1.8.txt
Dosyayı görüntüle @
32586b0b
...
...
@@ -136,6 +136,10 @@ Forms
a form's :attr:`~django.forms.Form.label_suffix` while using shortcuts such
as ``{{ form.as_p }}`` in templates.
* :class:`~django.forms.extras.widgets.SelectDateWidget` now accepts an
:attr:`~django.forms.extras.widgets.SelectDateWidget.empty_label` argument, which will
override the top list choice label when :class:`~django.forms.DateField` is not required.
Internationalization
^^^^^^^^^^^^^^^^^^^^
...
...
tests/forms_tests/tests/test_extra.py
Dosyayı görüntüle @
32586b0b
...
...
@@ -297,6 +297,11 @@ class FormsExtraTestCase(TestCase, AssertFormErrorsMixin):
<option value="2013">2013</option>
</select>"""
)
w
=
SelectDateWidget
(
years
=
(
'2014'
,),
empty_label
=
'empty_label'
)
# Rendering the default state with empty_label setted.
self
.
assertInHTML
(
'<option value="0">empty_label</option>'
,
w
.
render
(
'mydate'
,
''
),
count
=
3
)
a
=
GetDate
({
'mydate_month'
:
'4'
,
'mydate_day'
:
'1'
,
'mydate_year'
:
'2008'
})
self
.
assertTrue
(
a
.
is_valid
())
self
.
assertEqual
(
a
.
cleaned_data
[
'mydate'
],
datetime
.
date
(
2008
,
4
,
1
))
...
...
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