Ticket #13385: 13385.diff
File 13385.diff, 9.9 KB (added by , 13 years ago) |
---|
-
django/forms/widgets.py
commit 1d34921fa970a12c6c2869a526fb766c1d4adea4 Author: Claude Paroz <claude@2xlibre.net> Date: Sat Oct 22 17:43:41 2011 +0200 Add newline as first textarea content diff --git a/django/forms/widgets.py b/django/forms/widgets.py index 5b50f37..a5edda7 100644
a b class Textarea(Widget): 368 368 def render(self, name, value, attrs=None): 369 369 if value is None: value = '' 370 370 final_attrs = self.build_attrs(attrs, name=name) 371 return mark_safe(u'<textarea%s> %s</textarea>' % (flatatt(final_attrs),371 return mark_safe(u'<textarea%s>\n%s</textarea>' % (flatatt(final_attrs), 372 372 conditional_escape(force_unicode(value)))) 373 373 374 374 class DateInput(Input): -
tests/modeltests/model_forms/tests.py
diff --git a/tests/modeltests/model_forms/tests.py b/tests/modeltests/model_forms/tests.py index c4abdbb..6484ab3 100644
a b class TestWidgets(TestCase): 346 346 frm = TestWidgetForm() 347 347 self.assertEqual( 348 348 str(frm['name']), 349 '<textarea id="id_name" rows="10" cols="40" name="name"> </textarea>'349 '<textarea id="id_name" rows="10" cols="40" name="name">\n</textarea>' 350 350 ) 351 351 self.assertEqual( 352 352 str(frm['url']), … … class OldFormForXTests(TestCase): 661 661 <option value="%s">Bob Woodward</option> 662 662 <option value="%s">Mike Royko</option> 663 663 </select></td></tr> 664 <tr><th>Article:</th><td><textarea rows="10" cols="40" name="article"> </textarea></td></tr>664 <tr><th>Article:</th><td><textarea rows="10" cols="40" name="article">\n</textarea></td></tr> 665 665 <tr><th>Categories:</th><td><select multiple="multiple" name="categories"> 666 666 <option value="%s">Entertainment</option> 667 667 <option value="%s">It's a test</option> … … class OldFormForXTests(TestCase): 709 709 <option value="%s">Bob Woodward</option> 710 710 <option value="%s" selected="selected">Mike Royko</option> 711 711 </select></li> 712 <li>Article: <textarea rows="10" cols="40" name="article"> Hello.</textarea></li>712 <li>Article: <textarea rows="10" cols="40" name="article">\nHello.</textarea></li> 713 713 <li>Categories: <select multiple="multiple" name="categories"> 714 714 <option value="%s">Entertainment</option> 715 715 <option value="%s">It's a test</option> … … class OldFormForXTests(TestCase): 763 763 <option value="%s">Bob Woodward</option> 764 764 <option value="%s" selected="selected">Mike Royko</option> 765 765 </select></li> 766 <li>Article: <textarea rows="10" cols="40" name="article"> Hello.</textarea></li>766 <li>Article: <textarea rows="10" cols="40" name="article">\nHello.</textarea></li> 767 767 <li>Categories: <select multiple="multiple" name="categories"> 768 768 <option value="%s" selected="selected">Entertainment</option> 769 769 <option value="%s">It's a test</option> … … class OldFormForXTests(TestCase): 791 791 <option value="%s">Bob Woodward</option> 792 792 <option value="%s">Mike Royko</option> 793 793 </select></li> 794 <li>Article: <textarea rows="10" cols="40" name="article"> </textarea></li>794 <li>Article: <textarea rows="10" cols="40" name="article">\n</textarea></li> 795 795 <li>Categories: <select multiple="multiple" name="categories"> 796 796 <option value="%s" selected="selected">Entertainment</option> 797 797 <option value="%s" selected="selected">It's a test</option> … … class OldFormForXTests(TestCase): 885 885 <option value="%s">Bob Woodward</option> 886 886 <option value="%s">Mike Royko</option> 887 887 </select></li> 888 <li>Article: <textarea rows="10" cols="40" name="article"> </textarea></li>888 <li>Article: <textarea rows="10" cols="40" name="article">\n</textarea></li> 889 889 <li>Categories: <select multiple="multiple" name="categories"> 890 890 <option value="%s">Entertainment</option> 891 891 <option value="%s">It's a test</option> … … class OldFormForXTests(TestCase): 911 911 <option value="%s">Carl Bernstein</option> 912 912 <option value="%s">Mike Royko</option> 913 913 </select></li> 914 <li>Article: <textarea rows="10" cols="40" name="article"> </textarea></li>914 <li>Article: <textarea rows="10" cols="40" name="article">\n</textarea></li> 915 915 <li>Categories: <select multiple="multiple" name="categories"> 916 916 <option value="%s">Entertainment</option> 917 917 <option value="%s">It's a test</option> -
tests/regressiontests/forms/tests/forms.py
diff --git a/tests/regressiontests/forms/tests/forms.py b/tests/regressiontests/forms/tests/forms.py index 91db449..d38ede2 100644
a b class FormsTestCase(TestCase): 282 282 283 283 f = ContactForm(auto_id=False) 284 284 self.assertEqual(str(f['subject']), '<input type="text" name="subject" />') 285 self.assertEqual(str(f['message']), '<textarea rows="10" cols="40" name="message"> </textarea>')285 self.assertEqual(str(f['message']), '<textarea rows="10" cols="40" name="message">\n</textarea>') 286 286 287 287 # as_textarea(), as_text() and as_hidden() are shortcuts for changing the output 288 288 # widget type: 289 self.assertEqual(f['subject'].as_textarea(), u'<textarea rows="10" cols="40" name="subject"> </textarea>')289 self.assertEqual(f['subject'].as_textarea(), u'<textarea rows="10" cols="40" name="subject">\n</textarea>') 290 290 self.assertEqual(f['message'].as_text(), u'<input type="text" name="message" />') 291 291 self.assertEqual(f['message'].as_hidden(), u'<input type="hidden" name="message" />') 292 292 … … class FormsTestCase(TestCase): 296 296 message = CharField(widget=Textarea(attrs={'rows': 80, 'cols': 20})) 297 297 298 298 f = ContactForm(auto_id=False) 299 self.assertEqual(str(f['message']), '<textarea rows="80" cols="20" name="message"> </textarea>')299 self.assertEqual(str(f['message']), '<textarea rows="80" cols="20" name="message">\n</textarea>') 300 300 301 301 # Instance-level attrs are *not* carried over to as_textarea(), as_text() and 302 302 # as_hidden(): 303 303 self.assertEqual(f['message'].as_text(), u'<input type="text" name="message" />') 304 304 f = ContactForm({'subject': 'Hello', 'message': 'I love you.'}, auto_id=False) 305 self.assertEqual(f['subject'].as_textarea(), u'<textarea rows="10" cols="40" name="subject"> Hello</textarea>')305 self.assertEqual(f['subject'].as_textarea(), u'<textarea rows="10" cols="40" name="subject">\nHello</textarea>') 306 306 self.assertEqual(f['message'].as_text(), u'<input type="text" name="message" value="I love you." />') 307 307 self.assertEqual(f['message'].as_hidden(), u'<input type="hidden" name="message" value="I love you." />') 308 308 -
tests/regressiontests/forms/tests/widgets.py
diff --git a/tests/regressiontests/forms/tests/widgets.py b/tests/regressiontests/forms/tests/widgets.py index 2424bea..8830db1 100644
a b class FormsWidgetTestCase(TestCase): 164 164 165 165 def test_textarea(self): 166 166 w = Textarea() 167 self.assertEqual(w.render('msg', ''), u'<textarea rows="10" cols="40" name="msg"> </textarea>')168 self.assertEqual(w.render('msg', None), u'<textarea rows="10" cols="40" name="msg"> </textarea>')169 self.assertEqual(w.render('msg', 'value'), u'<textarea rows="10" cols="40" name="msg"> value</textarea>')170 self.assertEqual(w.render('msg', 'some "quoted" & ampersanded value'), u'<textarea rows="10" cols="40" name="msg"> some "quoted" & ampersanded value</textarea>')171 self.assertEqual(w.render('msg', mark_safe('pre "quoted" value')), u'<textarea rows="10" cols="40" name="msg"> pre "quoted" value</textarea>')172 self.assertEqual(w.render('msg', 'value', attrs={'class': 'pretty', 'rows': 20}), u'<textarea class="pretty" rows="20" cols="40" name="msg"> value</textarea>')167 self.assertEqual(w.render('msg', ''), u'<textarea rows="10" cols="40" name="msg">\n</textarea>') 168 self.assertEqual(w.render('msg', None), u'<textarea rows="10" cols="40" name="msg">\n</textarea>') 169 self.assertEqual(w.render('msg', 'value'), u'<textarea rows="10" cols="40" name="msg">\nvalue</textarea>') 170 self.assertEqual(w.render('msg', 'some "quoted" & ampersanded value'), u'<textarea rows="10" cols="40" name="msg">\nsome "quoted" & ampersanded value</textarea>') 171 self.assertEqual(w.render('msg', mark_safe('pre "quoted" value')), u'<textarea rows="10" cols="40" name="msg">\npre "quoted" value</textarea>') 172 self.assertEqual(w.render('msg', 'value', attrs={'class': 'pretty', 'rows': 20}), u'<textarea class="pretty" rows="20" cols="40" name="msg">\nvalue</textarea>') 173 173 174 174 # You can also pass 'attrs' to the constructor: 175 175 w = Textarea(attrs={'class': 'pretty'}) 176 self.assertEqual(w.render('msg', ''), u'<textarea rows="10" cols="40" name="msg" class="pretty"> </textarea>')177 self.assertEqual(w.render('msg', 'example'), u'<textarea rows="10" cols="40" name="msg" class="pretty"> example</textarea>')176 self.assertEqual(w.render('msg', ''), u'<textarea rows="10" cols="40" name="msg" class="pretty">\n</textarea>') 177 self.assertEqual(w.render('msg', 'example'), u'<textarea rows="10" cols="40" name="msg" class="pretty">\nexample</textarea>') 178 178 179 179 # 'attrs' passed to render() get precedence over those passed to the constructor: 180 180 w = Textarea(attrs={'class': 'pretty'}) 181 self.assertEqual(w.render('msg', '', attrs={'class': 'special'}), u'<textarea rows="10" cols="40" name="msg" class="special"> </textarea>')181 self.assertEqual(w.render('msg', '', attrs={'class': 'special'}), u'<textarea rows="10" cols="40" name="msg" class="special">\n</textarea>') 182 182 183 self.assertEqual(w.render('msg', 'ŠĐĆŽćžšđ', attrs={'class': 'fun'}), u'<textarea rows="10" cols="40" name="msg" class="fun">\ u0160\u0110\u0106\u017d\u0107\u017e\u0161\u0111</textarea>')183 self.assertEqual(w.render('msg', 'ŠĐĆŽćžšđ', attrs={'class': 'fun'}), u'<textarea rows="10" cols="40" name="msg" class="fun">\n\u0160\u0110\u0106\u017d\u0107\u017e\u0161\u0111</textarea>') 184 184 185 185 def test_checkboxinput(self): 186 186 w = CheckboxInput()