Ticket #13385: ticket13385.patch

File ticket13385.patch, 8.2 KB (added by Anssi Kääriäinen, 15 years ago)

patch with tests

  • django/forms/widgets.py

    diff --git a/django/forms/widgets.py b/django/forms/widgets.py
    index 082c11b..2853540 100644
    a b class Textarea(Widget):  
    290290    def render(self, name, value, attrs=None):
    291291        if value is None: value = ''
    292292        final_attrs = self.build_attrs(attrs, name=name)
    293         return mark_safe(u'<textarea%s>%s</textarea>' % (flatatt(final_attrs),
     293        return mark_safe(u'<textarea%s>\n%s</textarea>' % (flatatt(final_attrs),
    294294                conditional_escape(force_unicode(value))))
    295295
    296296class DateInput(Input):
  • tests/modeltests/model_forms/models.py

    diff --git a/tests/modeltests/model_forms/models.py b/tests/modeltests/model_forms/models.py
    index 1087cf8..dd68ac1 100644
    a b Using 'widgets'  
    335335...         }
    336336
    337337>>> str(CategoryForm()['name'])
    338 '<textarea id="id_name" rows="10" cols="40" name="name"></textarea>'
     338'<textarea id="id_name" rows="10" cols="40" name="name">\n</textarea>'
    339339
    340340>>> str(CategoryForm()['url'])
    341341'<input id="id_url" type="text" class="url" name="url" maxlength="40" />'
    fields with the 'choices' attribute are represented by a ChoiceField.  
    543543<option value="...">Mike Royko</option>
    544544<option value="...">Bob Woodward</option>
    545545</select></td></tr>
    546 <tr><th>Article:</th><td><textarea rows="10" cols="40" name="article"></textarea></td></tr>
     546<tr><th>Article:</th><td><textarea rows="10" cols="40" name="article">\n</textarea></td></tr>
    547547<tr><th>Status:</th><td><select name="status">
    548548<option value="" selected="selected">---------</option>
    549549<option value="1">Draft</option>
    inserted as 'initial' data in each Field.  
    598598<option value="..." selected="selected">Mike Royko</option>
    599599<option value="...">Bob Woodward</option>
    600600</select></li>
    601 <li>Article: <textarea rows="10" cols="40" name="article">Hello.</textarea></li>
     601<li>Article: <textarea rows="10" cols="40" name="article">\nHello.</textarea></li>
    602602<li>Status: <select name="status">
    603603<option value="" selected="selected">---------</option>
    604604<option value="1">Draft</option>
    Add some categories and test the many-to-many form output.  
    661661<option value="..." selected="selected">Mike Royko</option>
    662662<option value="...">Bob Woodward</option>
    663663</select></li>
    664 <li>Article: <textarea rows="10" cols="40" name="article">Hello.</textarea></li>
     664<li>Article: <textarea rows="10" cols="40" name="article">\nHello.</textarea></li>
    665665<li>Status: <select name="status">
    666666<option value="" selected="selected">---------</option>
    667667<option value="1">Draft</option>
    Initial values can be provided for model forms  
    685685<option value="...">Mike Royko</option>
    686686<option value="...">Bob Woodward</option>
    687687</select></li>
    688 <li>Article: <textarea rows="10" cols="40" name="article"></textarea></li>
     688<li>Article: <textarea rows="10" cols="40" name="article">\n</textarea></li>
    689689<li>Status: <select name="status">
    690690<option value="" selected="selected">---------</option>
    691691<option value="1">Draft</option>
    the data in the database when the form is instantiated.  
    801801<option value="...">Mike Royko</option>
    802802<option value="...">Bob Woodward</option>
    803803</select></li>
    804 <li>Article: <textarea rows="10" cols="40" name="article"></textarea></li>
     804<li>Article: <textarea rows="10" cols="40" name="article">\n</textarea></li>
    805805<li>Status: <select name="status">
    806806<option value="" selected="selected">---------</option>
    807807<option value="1">Draft</option>
    the data in the database when the form is instantiated.  
    827827<option value="...">Bob Woodward</option>
    828828<option value="...">Carl Bernstein</option>
    829829</select></li>
    830 <li>Article: <textarea rows="10" cols="40" name="article"></textarea></li>
     830<li>Article: <textarea rows="10" cols="40" name="article">\n</textarea></li>
    831831<li>Status: <select name="status">
    832832<option value="" selected="selected">---------</option>
    833833<option value="1">Draft</option>
  • tests/regressiontests/forms/forms.py

    diff --git a/tests/regressiontests/forms/forms.py b/tests/regressiontests/forms/forms.py
    index bb58eaa..d42381a 100644
    a b Any Field can have a Widget class passed to its constructor:  
    321321>>> print f['subject']
    322322<input type="text" name="subject" />
    323323>>> print f['message']
    324 <textarea rows="10" cols="40" name="message"></textarea>
     324<textarea rows="10" cols="40" name="message">\n</textarea>
    325325
    326326as_textarea(), as_text() and as_hidden() are shortcuts for changing the output
    327327widget type:
    328328>>> f['subject'].as_textarea()
    329 u'<textarea rows="10" cols="40" name="subject"></textarea>'
     329u'<textarea rows="10" cols="40" name="subject">\n</textarea>'
    330330>>> f['message'].as_text()
    331331u'<input type="text" name="message" />'
    332332>>> f['message'].as_hidden()
    The 'widget' parameter to a Field can also be an instance:  
    338338...     message = CharField(widget=Textarea(attrs={'rows': 80, 'cols': 20}))
    339339>>> f = ContactForm(auto_id=False)
    340340>>> print f['message']
    341 <textarea rows="80" cols="20" name="message"></textarea>
     341<textarea rows="80" cols="20" name="message">\n</textarea>
    342342
    343343Instance-level attrs are *not* carried over to as_textarea(), as_text() and
    344344as_hidden():
    as_hidden():  
    346346u'<input type="text" name="message" />'
    347347>>> f = ContactForm({'subject': 'Hello', 'message': 'I love you.'}, auto_id=False)
    348348>>> f['subject'].as_textarea()
    349 u'<textarea rows="10" cols="40" name="subject">Hello</textarea>'
     349u'<textarea rows="10" cols="40" name="subject">\nHello</textarea>'
    350350>>> f['message'].as_text()
    351351u'<input type="text" name="message" value="I love you." />'
    352352>>> f['message'].as_hidden()
  • tests/regressiontests/forms/widgets.py

    diff --git a/tests/regressiontests/forms/widgets.py b/tests/regressiontests/forms/widgets.py
    index cc83a88..759b5bb 100644
    a b True  
    243243
    244244>>> w = Textarea()
    245245>>> w.render('msg', '')
    246 u'<textarea rows="10" cols="40" name="msg"></textarea>'
     246u'<textarea rows="10" cols="40" name="msg">\n</textarea>'
     247
     248# A textarea should have \n in it. See ticket 13385
     249>>> w.render('msg', None).count('\n') == 1
     250True
    247251>>> w.render('msg', None)
    248 u'<textarea rows="10" cols="40" name="msg"></textarea>'
     252u'<textarea rows="10" cols="40" name="msg">\n</textarea>'
    249253>>> w.render('msg', 'value')
    250 u'<textarea rows="10" cols="40" name="msg">value</textarea>'
     254u'<textarea rows="10" cols="40" name="msg">\nvalue</textarea>'
    251255>>> w.render('msg', 'some "quoted" & ampersanded value')
    252 u'<textarea rows="10" cols="40" name="msg">some &quot;quoted&quot; &amp; ampersanded value</textarea>'
     256u'<textarea rows="10" cols="40" name="msg">\nsome &quot;quoted&quot; &amp; ampersanded value</textarea>'
    253257>>> w.render('msg', mark_safe('pre &quot;quoted&quot; value'))
    254 u'<textarea rows="10" cols="40" name="msg">pre &quot;quoted&quot; value</textarea>'
     258u'<textarea rows="10" cols="40" name="msg">\npre &quot;quoted&quot; value</textarea>'
    255259>>> w.render('msg', 'value', attrs={'class': 'pretty', 'rows': 20})
    256 u'<textarea class="pretty" rows="20" cols="40" name="msg">value</textarea>'
     260u'<textarea class="pretty" rows="20" cols="40" name="msg">\nvalue</textarea>'
    257261
    258262You can also pass 'attrs' to the constructor:
    259263>>> w = Textarea(attrs={'class': 'pretty'})
    260264>>> w.render('msg', '')
    261 u'<textarea rows="10" cols="40" name="msg" class="pretty"></textarea>'
     265u'<textarea rows="10" cols="40" name="msg" class="pretty">\n</textarea>'
    262266>>> w.render('msg', 'example')
    263 u'<textarea rows="10" cols="40" name="msg" class="pretty">example</textarea>'
     267u'<textarea rows="10" cols="40" name="msg" class="pretty">\nexample</textarea>'
    264268
    265269'attrs' passed to render() get precedence over those passed to the constructor:
    266270>>> w = Textarea(attrs={'class': 'pretty'})
    267271>>> w.render('msg', '', attrs={'class': 'special'})
    268 u'<textarea rows="10" cols="40" name="msg" class="special"></textarea>'
     272u'<textarea rows="10" cols="40" name="msg" class="special">\n</textarea>'
    269273
    270274>>> w.render('msg', 'ŠĐĆŽćžšđ', attrs={'class': 'fun'})
    271 u'<textarea rows="10" cols="40" name="msg" class="fun">\u0160\u0110\u0106\u017d\u0107\u017e\u0161\u0111</textarea>'
     275u'<textarea rows="10" cols="40" name="msg" class="fun">\n\u0160\u0110\u0106\u017d\u0107\u017e\u0161\u0111</textarea>'
    272276
    273277# CheckboxInput Widget ########################################################
    274278
Back to Top