Ticket #13385: 13385.diff

File 13385.diff, 9.9 KB (added by Claude Paroz, 13 years ago)

Patch updated to current trunk

  • 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):  
    368368    def render(self, name, value, attrs=None):
    369369        if value is None: value = ''
    370370        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),
    372372                conditional_escape(force_unicode(value))))
    373373
    374374class 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):  
    346346        frm = TestWidgetForm()
    347347        self.assertEqual(
    348348            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>'
    350350        )
    351351        self.assertEqual(
    352352            str(frm['url']),
    class OldFormForXTests(TestCase):  
    661661<option value="%s">Bob Woodward</option>
    662662<option value="%s">Mike Royko</option>
    663663</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>
    665665<tr><th>Categories:</th><td><select multiple="multiple" name="categories">
    666666<option value="%s">Entertainment</option>
    667667<option value="%s">It&#39;s a test</option>
    class OldFormForXTests(TestCase):  
    709709<option value="%s">Bob Woodward</option>
    710710<option value="%s" selected="selected">Mike Royko</option>
    711711</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>
    713713<li>Categories: <select multiple="multiple" name="categories">
    714714<option value="%s">Entertainment</option>
    715715<option value="%s">It&#39;s a test</option>
    class OldFormForXTests(TestCase):  
    763763<option value="%s">Bob Woodward</option>
    764764<option value="%s" selected="selected">Mike Royko</option>
    765765</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>
    767767<li>Categories: <select multiple="multiple" name="categories">
    768768<option value="%s" selected="selected">Entertainment</option>
    769769<option value="%s">It&#39;s a test</option>
    class OldFormForXTests(TestCase):  
    791791<option value="%s">Bob Woodward</option>
    792792<option value="%s">Mike Royko</option>
    793793</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>
    795795<li>Categories: <select multiple="multiple" name="categories">
    796796<option value="%s" selected="selected">Entertainment</option>
    797797<option value="%s" selected="selected">It&#39;s a test</option>
    class OldFormForXTests(TestCase):  
    885885<option value="%s">Bob Woodward</option>
    886886<option value="%s">Mike Royko</option>
    887887</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>
    889889<li>Categories: <select multiple="multiple" name="categories">
    890890<option value="%s">Entertainment</option>
    891891<option value="%s">It&#39;s a test</option>
    class OldFormForXTests(TestCase):  
    911911<option value="%s">Carl Bernstein</option>
    912912<option value="%s">Mike Royko</option>
    913913</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>
    915915<li>Categories: <select multiple="multiple" name="categories">
    916916<option value="%s">Entertainment</option>
    917917<option value="%s">It&#39;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):  
    282282
    283283        f = ContactForm(auto_id=False)
    284284        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>')
    286286
    287287        # as_textarea(), as_text() and as_hidden() are shortcuts for changing the output
    288288        # 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>')
    290290        self.assertEqual(f['message'].as_text(), u'<input type="text" name="message" />')
    291291        self.assertEqual(f['message'].as_hidden(), u'<input type="hidden" name="message" />')
    292292
    class FormsTestCase(TestCase):  
    296296            message = CharField(widget=Textarea(attrs={'rows': 80, 'cols': 20}))
    297297
    298298        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>')
    300300
    301301        # Instance-level attrs are *not* carried over to as_textarea(), as_text() and
    302302        # as_hidden():
    303303        self.assertEqual(f['message'].as_text(), u'<input type="text" name="message" />')
    304304        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>')
    306306        self.assertEqual(f['message'].as_text(), u'<input type="text" name="message" value="I love you." />')
    307307        self.assertEqual(f['message'].as_hidden(), u'<input type="hidden" name="message" value="I love you." />')
    308308
  • 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):  
    164164
    165165    def test_textarea(self):
    166166        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 &quot;quoted&quot; &amp; ampersanded value</textarea>')
    171         self.assertEqual(w.render('msg', mark_safe('pre &quot;quoted&quot; value')), u'<textarea rows="10" cols="40" name="msg">pre &quot;quoted&quot; 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 &quot;quoted&quot; &amp; ampersanded value</textarea>')
     171        self.assertEqual(w.render('msg', mark_safe('pre &quot;quoted&quot; value')), u'<textarea rows="10" cols="40" name="msg">\npre &quot;quoted&quot; 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>')
    173173
    174174        # You can also pass 'attrs' to the constructor:
    175175        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>')
    178178
    179179        # 'attrs' passed to render() get precedence over those passed to the constructor:
    180180        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>')
    182182
    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>')
    184184
    185185    def test_checkboxinput(self):
    186186        w = CheckboxInput()
Back to Top