web/test/unittest_form.py
changeset 1983 5edd22d0e61a
parent 1977 606923dff11b
child 1995 ec95eaa2b711
equal deleted inserted replaced
1982:27e81d0c7d05 1983:5edd22d0e61a
   151         self._test_richtextfield('<input name="description_format:%(eid)s" style="display: block" type="hidden" value="text/rest"/><textarea cols="80" cubicweb:type="wysiwyg" id="description:%(eid)s" name="description:%(eid)s" onkeypress="autogrow(this)" rows="20" tabindex="0"/>')
   151         self._test_richtextfield('<input name="description_format:%(eid)s" style="display: block" type="hidden" value="text/rest"/><textarea cols="80" cubicweb:type="wysiwyg" id="description:%(eid)s" name="description:%(eid)s" onkeypress="autogrow(this)" rows="20" tabindex="0"/>')
   152 
   152 
   153 
   153 
   154     def test_filefield(self):
   154     def test_filefield(self):
   155         class FFForm(EntityFieldsForm):
   155         class FFForm(EntityFieldsForm):
   156             data = FileField(format_field=StringField(name='data_format'),
   156             data = FileField(format_field=StringField(name='data_format', max_length=50),
   157                              encoding_field=StringField(name='data_encoding'))
   157                              encoding_field=StringField(name='data_encoding', max_length=20))
   158         file = self.add_entity('File', name=u"pouet.txt", data_encoding=u'UTF-8',
   158         file = self.add_entity('File', name=u"pouet.txt", data_encoding=u'UTF-8',
   159                                data=Binary('new widgets system'))
   159                                data=Binary('new widgets system'))
   160         form = FFForm(self.req, redirect_path='perdu.com', entity=file)
   160         form = FFForm(self.req, redirect_path='perdu.com', entity=file)
   161         self.assertTextEquals(self._render_entity_field('data', form),
   161         self.assertTextEquals(self._render_entity_field('data', form),
   162                               '''<input id="data:%(eid)s" name="data:%(eid)s" tabindex="0" type="file" value=""/>
   162                               '''<input id="data:%(eid)s" name="data:%(eid)s" tabindex="0" type="file" value=""/>
   163 <a href="javascript: toggleVisibility(&#39;data:%(eid)s-advanced&#39;)" title="show advanced fields"><img src="http://testing.fr/cubicweb/data/puce_down.png" alt="show advanced fields"/></a>
   163 <a href="javascript: toggleVisibility(&#39;data:%(eid)s-advanced&#39;)" title="show advanced fields"><img src="http://testing.fr/cubicweb/data/puce_down.png" alt="show advanced fields"/></a>
   164 <div id="data:%(eid)s-advanced" class="hidden">
   164 <div id="data:%(eid)s-advanced" class="hidden">
   165 <label for="data_format:%(eid)s">data_format</label><input id="data_format:%(eid)s" name="data_format:%(eid)s" tabindex="1" type="text" value="text/plain"/><br/><br/>
   165 <label for="data_format:%(eid)s">data_format</label><input id="data_format:%(eid)s" name="data_format:%(eid)s" tabindex="1" type="text" value="text/plain"/><br/>
   166 <label for="data_encoding:%(eid)s">data_encoding</label><input id="data_encoding:%(eid)s" name="data_encoding:%(eid)s" tabindex="2" type="text" value="UTF-8"/><br/><br/>
   166 <label for="data_encoding:%(eid)s">data_encoding</label><input id="data_encoding:%(eid)s" name="data_encoding:%(eid)s" tabindex="2" type="text" value="UTF-8"/><br/>
   167 </div>
   167 </div>
   168 <br/>
   168 <br/>
   169 <input name="data:%(eid)s__detach" type="checkbox"/>
   169 <input name="data:%(eid)s__detach" type="checkbox"/>
   170 detach attached file
   170 detach attached file
   171 ''' % {'eid': file.eid})
   171 ''' % {'eid': file.eid})
   172 
   172 
   173 
   173 
   174     def test_editablefilefield(self):
   174     def test_editablefilefield(self):
   175         class EFFForm(EntityFieldsForm):
   175         class EFFForm(EntityFieldsForm):
   176             data = EditableFileField(format_field=StringField(name='data_format'),
   176             data = EditableFileField(format_field=StringField(name='data_format', max_length=50),
   177                                      encoding_field=StringField(name='data_encoding'))
   177                                      encoding_field=StringField(name='data_encoding', max_length=20))
   178             def form_field_encoding(self, field):
   178             def form_field_encoding(self, field):
   179                 return 'ascii'
   179                 return 'ascii'
   180             def form_field_format(self, field):
   180             def form_field_format(self, field):
   181                 return 'text/plain'
   181                 return 'text/plain'
   182         file = self.add_entity('File', name=u"pouet.txt", data_encoding=u'UTF-8', 
   182         file = self.add_entity('File', name=u"pouet.txt", data_encoding=u'UTF-8', 
   184         form = EFFForm(self.req, redirect_path='perdu.com', entity=file)
   184         form = EFFForm(self.req, redirect_path='perdu.com', entity=file)
   185         self.assertTextEquals(self._render_entity_field('data', form),
   185         self.assertTextEquals(self._render_entity_field('data', form),
   186                               '''<input id="data:%(eid)s" name="data:%(eid)s" tabindex="0" type="file" value=""/>
   186                               '''<input id="data:%(eid)s" name="data:%(eid)s" tabindex="0" type="file" value=""/>
   187 <a href="javascript: toggleVisibility(&#39;data:%(eid)s-advanced&#39;)" title="show advanced fields"><img src="http://testing.fr/cubicweb/data/puce_down.png" alt="show advanced fields"/></a>
   187 <a href="javascript: toggleVisibility(&#39;data:%(eid)s-advanced&#39;)" title="show advanced fields"><img src="http://testing.fr/cubicweb/data/puce_down.png" alt="show advanced fields"/></a>
   188 <div id="data:%(eid)s-advanced" class="hidden">
   188 <div id="data:%(eid)s-advanced" class="hidden">
   189 <label for="data_format:%(eid)s">data_format</label><input id="data_format:%(eid)s" name="data_format:%(eid)s" tabindex="1" type="text" value="text/plain"/><br/><br/>
   189 <label for="data_format:%(eid)s">data_format</label><input id="data_format:%(eid)s" name="data_format:%(eid)s" tabindex="1" type="text" value="text/plain"/><br/>
   190 <label for="data_encoding:%(eid)s">data_encoding</label><input id="data_encoding:%(eid)s" name="data_encoding:%(eid)s" tabindex="2" type="text" value="UTF-8"/><br/><br/>
   190 <label for="data_encoding:%(eid)s">data_encoding</label><input id="data_encoding:%(eid)s" name="data_encoding:%(eid)s" tabindex="2" type="text" value="UTF-8"/><br/>
   191 </div>
   191 </div>
   192 <br/>
   192 <br/>
   193 <input name="data:%(eid)s__detach" type="checkbox"/>
   193 <input name="data:%(eid)s__detach" type="checkbox"/>
   194 detach attached file
   194 detach attached file
   195 <p><b>You can either submit a new file using the browse button above, or choose to remove already uploaded file by checking the "detach attached file" check-box, or edit file content online with the widget below.</b></p>
   195 <p><b>You can either submit a new file using the browse button above, or choose to remove already uploaded file by checking the "detach attached file" check-box, or edit file content online with the widget below.</b></p>