Hi all,

what is the preferred form generation tool for repoze.bfg? I tried chameleon.formish, which seems a nice solution.
I found the fileupload-widget is broken, attached is a patch to fix it.

This is probably the wrong list to ask about i18n support of formish, but since chameleon is involved the key is maybe there. I solved the localization issue of the form labels with the following monkey patch, but I'm not really happy to use monkey patches in general. does anyone know of a better solution?

-Tom

from formish.forms import Field
from zope.i18nmessageid.message import Message
from zope.i18n import translate

@property
def title(self):
    title = self._orig_title
    if isinstance(title, Message):
        lang = getattr(self.form, 'target_language', 'en')
        return translate(title, target_language=lang)
    return title

Field._orig_title = Field.title
Field.title = title

@property
def description(self):
    description = self._orig_description
    if isinstance(description, Message):
        lang = getattr(self.form, 'target_language', 'en')
        return translate(description, target_language=lang)
    return description

Field._orig_description = Field.description
Field.description = description
Index: 
chameleon.formish/chameleon/formish/templates/zpt/formish/widgets/FileUpload/widget.html
===================================================================
--- 
chameleon.formish/chameleon/formish/templates/zpt/formish/widgets/FileUpload/widget.html
    (Revision 7981)
+++ 
chameleon.formish/chameleon/formish/templates/zpt/formish/widgets/FileUpload/widget.html
    (Arbeitskopie)
@@ -1,19 +1,17 @@
-<div class="preview"
-     tal:define="star ('*' in field.name);
+<tal:var define="star ('*' in field.name);
                  value_name (not star) and field.value['name'][0] or '';
                  value_default (not star) and field.value['default'][0] or '';
-                 mimetype (not star) and field.value['mimetype'][0] or '';
-                 mimetype mimetype or '';"
-     >
+                 mimetype (not star) and field.value['mimetype'][0] or '';">
+<div class="preview">
   <div tal:condition="field.widget.show_file_preview"
        class="icon ${mimetype.replace('/','_')}">
-    <img tal:condition="field.widget.show_image_thumbnail and value name != '' 
and mimetype.startswith('image')"
+    <img tal:condition="field.widget.show_image_thumbnail and value_name != '' 
and mimetype.startswith('image')"
          src="${field.widget.urlfactory(value_name)}?size=20x20"/>
-    <img tal:condition="not (field.widget.show_image_thumbnail and value name 
!= '' and mimetype.startswith('image')) and field.widget_thumbnail_default is 
not None"
-         src="${field.widget.image_thumbnail_default"/>
+         <img tal:condition="not (field.widget.show_image_thumbnail and 
value_name != '' and mimetype.startswith('image')) and 
field.widget.image_thumbnail_default is not None"
+    src="${field.widget.image_thumbnail_default}"/>
   </div>
   <a tal:condition="field.widget.show_download_link"
-     href="${field.widget.urlfactory(value_name)">download</a>
+      href="${field.widget.urlfactory(value_name)}">download</a>
 </div>
 
 <input id="${field.cssname}-remove" type="checkbox" 
name="${field.name}.remove" value="true" />
@@ -21,3 +19,4 @@
 <input id="${field.cssname}-mimetype" type="hidden" 
name="${field.name}.mimetype" value="${mimetype}" />
 <input id="${field.cssname}-default" type="hidden" 
name="${field.name}.default" value="${value_default}" />
 <input id="${field.cssname}" type="file" name="${field.name}.file" />
+</tal:var>
_______________________________________________
Repoze-dev mailing list
Repoze-dev@lists.repoze.org
http://lists.repoze.org/listinfo/repoze-dev

Reply via email to