Ticket #16179: 16179.diff
File 16179.diff, 5.6 KB (added by , 13 years ago) |
---|
-
django/contrib/formtools/wizard/tests/wizardtests/tests.py
244 244 'cookie_contact_wizard-current_step': 'form4', 245 245 } 246 246 ) 247 248 class WizardTestKwargs(TestCase): 249 wizard_url = '/wiz_extra_context/' 250 wizard_step_1_data = { 251 'cookie_contact_wizard-current_step': 'form1', 252 } 253 wizard_step_data = ( 254 { 255 'form1-name': 'Pony', 256 'form1-thirsty': '2', 257 'cookie_contact_wizard-current_step': 'form1', 258 }, 259 { 260 'form2-address1': '123 Main St', 261 'form2-address2': 'Djangoland', 262 'cookie_contact_wizard-current_step': 'form2', 263 }, 264 { 265 'form3-random_crap': 'blah blah', 266 'cookie_contact_wizard-current_step': 'form3', 267 }, 268 { 269 'form4-INITIAL_FORMS': '0', 270 'form4-TOTAL_FORMS': '2', 271 'form4-MAX_NUM_FORMS': '0', 272 'form4-0-random_crap': 'blah blah', 273 'form4-1-random_crap': 'blah blah', 274 'cookie_contact_wizard-current_step': 'form4', 275 } 276 ) 277 urls = 'django.contrib.formtools.wizard.tests.wizardtests.urls' 278 279 def setUp(self): 280 self.testuser, created = User.objects.get_or_create(username='testuser1') 281 self.wizard_step_data[0]['form1-user'] = self.testuser.pk 282 283 wizard_template_dirs = [os.path.join(os.path.dirname(__file__), 'templates')] 284 settings.TEMPLATE_DIRS = list(settings.TEMPLATE_DIRS) + wizard_template_dirs 285 286 def tearDown(self): 287 del settings.TEMPLATE_DIRS[-1] 288 289 def test_context(self): 290 response = self.client.get(self.wizard_url) 291 self.assertEqual(response.context['extra_title'], 'Hello World!') 292 293 def test_template(self): 294 response = self.client.get(self.wizard_url) 295 self.assertNotEqual(response.content.find('<h1>Hello World!</h1>'), -1) 296 297 298 299 247 300 248 301 -
django/contrib/formtools/wizard/tests/wizardtests/urls.py
13 13 ('form2', Page2), 14 14 ('form3', Page3), 15 15 ('form4', Page4)])), 16 17 url(r'^wiz_extra_context/$', CookieContactWizard.as_view( 18 [('form1', Page1), 19 ('form2', Page2), 20 ('form3', Page3), 21 ('form4', Page4)], 22 extra_context={'extra_title': 'Hello World!'}, 23 template_name='some_other_template.html')), 16 24 ) -
django/contrib/formtools/wizard/tests/wizardtests/templates/some_other_template.html
1 {% load i18n %} 2 {% csrf_token %} 3 {% if extra_title %}<h1>{{ extra_title }}</h1>{% endif %} 4 {{ wizard.management_form }} 5 {% if wizard.form.forms %} 6 {{ wizard.form.management_form }} 7 {% for form in wizard.form.forms %} 8 {{ form.as_p }} 9 {% endfor %} 10 {% else %} 11 {{ wizard.form.as_p }} 12 {% endif %} 13 14 {% if wizard.steps.prev %} 15 <button name="wizard_prev_step" value="{{ wizard.steps.first }}">{% trans "first step" %}</button> 16 <button name="wizard_prev_step" value="{{ wizard.steps.prev }}">{% trans "prev step" %}</button> 17 {% endif %} 18 <input type="submit" name="submit" value="{% trans "submit" %}" /> -
django/contrib/formtools/wizard/views.py
96 96 instance_dict = None 97 97 condition_dict = None 98 98 template_name = 'formtools/wizard/wizard_form.html' 99 extra_context = None 99 100 100 101 def __repr__(self): 101 102 return '<%s: forms: %s>' % (self.__class__.__name__, self.form_list) … … 112 113 113 114 @classmethod 114 115 def get_initkwargs(cls, form_list, 115 initial_dict=None, instance_dict=None, condition_dict=None ):116 initial_dict=None, instance_dict=None, condition_dict=None, **kwargs): 116 117 """ 117 118 Creates a dict with all needed parameters for the form wizard instances. 118 119 … … 134 135 will be called with the formwizard instance as the only argument. 135 136 If the return value is true, the step's form will be used. 136 137 """ 137 kwargs ={138 kwargs.update({ 138 139 'initial_dict': initial_dict or {}, 139 140 'instance_dict': instance_dict or {}, 140 141 'condition_dict': condition_dict or {}, 141 } 142 }) 142 143 init_form_list = SortedDict() 143 144 144 145 assert len(form_list) > 0, 'at least one form is needed' … … 512 513 context.update({'another_var': True}) 513 514 return context 514 515 """ 515 context = super(WizardView, self).get_context_data(*args, **kwargs) 516 context = super(WizardView, self).get_context_data(*args, **kwargs) 517 context.update(self.extra_context or {}) 516 518 context.update(self.storage.extra_data) 517 519 context['wizard'] = { 518 520 'form': form,