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
7e5d7a76
Kaydet (Commit)
7e5d7a76
authored
Eki 12, 2013
tarafından
Kathryn Killebrew
Kaydeden (comit)
Tim Graham
Eki 17, 2013
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Fixed #21259 -- Fixed formstools wizard for InlineFormSet.
üst
9833b931
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
57 additions
and
6 deletions
+57
-6
models.py
django/contrib/formtools/tests/models.py
+26
-0
tests.py
django/contrib/formtools/tests/wizard/wizardtests/tests.py
+24
-0
views.py
django/contrib/formtools/wizard/views.py
+7
-6
No files found.
django/contrib/formtools/tests/models.py
0 → 100644
Dosyayı görüntüle @
7e5d7a76
# coding: utf-8
from
django.db
import
models
from
django.utils.encoding
import
python_2_unicode_compatible
@python_2_unicode_compatible
class
Poet
(
models
.
Model
):
name
=
models
.
CharField
(
max_length
=
100
)
class
Meta
:
app_label
=
'formtools'
def
__str__
(
self
):
return
self
.
name
@python_2_unicode_compatible
class
Poem
(
models
.
Model
):
poet
=
models
.
ForeignKey
(
Poet
)
name
=
models
.
CharField
(
max_length
=
100
)
class
Meta
:
app_label
=
'formtools'
def
__str__
(
self
):
return
self
.
name
django/contrib/formtools/tests/wizard/wizardtests/tests.py
Dosyayı görüntüle @
7e5d7a76
...
...
@@ -10,6 +10,7 @@ from django.contrib.auth.models import User
from
django.contrib.auth.tests.utils
import
skipIfCustomUser
from
django.contrib.formtools.wizard.views
import
CookieWizardView
from
django.utils._os
import
upath
from
django.contrib.formtools.tests.models
import
Poet
,
Poem
class
UserForm
(
forms
.
ModelForm
):
...
...
@@ -19,6 +20,7 @@ class UserForm(forms.ModelForm):
UserFormSet
=
forms
.
models
.
modelformset_factory
(
User
,
form
=
UserForm
,
extra
=
2
)
PoemFormSet
=
forms
.
models
.
inlineformset_factory
(
Poet
,
Poem
,
fields
=
"__all__"
)
class
WizardTests
(
object
):
...
...
@@ -405,3 +407,25 @@ class WizardFormKwargsOverrideTests(TestCase):
self
.
assertEqual
(
formset
.
initial_form_count
(),
1
)
self
.
assertEqual
([
'staff@example.com'
],
list
(
formset
.
queryset
.
values_list
(
'email'
,
flat
=
True
)))
class
WizardInlineFormSetTests
(
TestCase
):
def
setUp
(
self
):
self
.
rf
=
RequestFactory
()
self
.
poet
=
Poet
.
objects
.
create
(
name
=
'test'
)
self
.
poem
=
self
.
poet
.
poem_set
.
create
(
name
=
'test poem'
)
def
test_set_instance
(
self
):
# Regression test for #21259
poet
=
self
.
poet
class
InlineFormSetWizard
(
CookieWizardView
):
instance
=
None
def
get_form_instance
(
self
,
step
):
if
self
.
instance
is
None
:
self
.
instance
=
poet
return
self
.
instance
view
=
InlineFormSetWizard
.
as_view
([
PoemFormSet
])
response
=
view
(
self
.
rf
.
get
(
'/'
))
formset
=
response
.
context_data
[
'wizard'
][
'form'
]
self
.
assertEqual
(
formset
.
instance
,
self
.
poet
)
django/contrib/formtools/wizard/views.py
Dosyayı görüntüle @
7e5d7a76
...
...
@@ -398,23 +398,24 @@ class WizardView(TemplateView):
"""
if
step
is
None
:
step
=
self
.
steps
.
current
form_class
=
self
.
form_list
[
step
]
# prepare the kwargs for the form instance.
kwargs
=
self
.
get_form_kwargs
(
step
)
kwargs
.
update
({
'data'
:
data
,
'files'
:
files
,
'prefix'
:
self
.
get_form_prefix
(
step
,
self
.
form_list
[
step
]
),
'prefix'
:
self
.
get_form_prefix
(
step
,
form_class
),
'initial'
:
self
.
get_form_initial
(
step
),
})
if
issubclass
(
self
.
form_list
[
step
],
forms
.
ModelForm
):
# If the form is based on ModelForm
, add instance if available
# and not previously set.
if
issubclass
(
form_class
,
(
forms
.
ModelForm
,
forms
.
models
.
BaseInlineFormSet
)
):
# If the form is based on ModelForm
or InlineFormSet,
# a
dd instance if available a
nd not previously set.
kwargs
.
setdefault
(
'instance'
,
self
.
get_form_instance
(
step
))
elif
issubclass
(
self
.
form_list
[
step
]
,
forms
.
models
.
BaseModelFormSet
):
elif
issubclass
(
form_class
,
forms
.
models
.
BaseModelFormSet
):
# If the form is based on ModelFormSet, add queryset if available
# and not previous set.
kwargs
.
setdefault
(
'queryset'
,
self
.
get_form_instance
(
step
))
return
self
.
form_list
[
step
]
(
**
kwargs
)
return
form_class
(
**
kwargs
)
def
process_step
(
self
,
form
):
"""
...
...
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