--- a/web/form.py Thu Feb 19 19:28:44 2009 +0100
+++ b/web/form.py Thu Feb 19 20:33:50 2009 +0100
@@ -435,15 +435,20 @@
def form_build_context(self, values):
self.context = context = {}
+ # on validation error, we get a dictionnary of previously submitted values
+ previous_values = self.req.data.get('formvalues')
+ if previous_values:
+ values.update(previous_values)
for field in self.fields:
- context[field] = {'value': self.form_field_value(field, values),
- 'name': self.form_field_name(field, values),
- 'id': self.form_field_id(field, values),
+ context[field] = {'value': self.form_field_value(field, field_values),
+ 'name': self.form_field_name(field),
+ 'id': self.form_field_id(field),
}
def form_field_value(self, field, values):
"""looks for field's value in
- 1. kw args given to render_form
+ 1. kw args given to render_form (including previously submitted form
+ values if any)
2. req.form
3. field's initial value
"""
@@ -455,10 +460,10 @@
value = field.initial
return field.format_value(self.req, value)
- def form_field_name(self, field, values):
+ def form_field_name(self, field):
return field.name
- def form_field_id(self, field, values):
+ def form_field_id(self, field):
return field.id
def form_field_vocabulary(self, field):
@@ -499,11 +504,12 @@
def form_render(self, entity, **values):
self.entity = entity
return super(EntityFieldsForm, self).form_render(**values)
-
+
def form_field_value(self, field, values):
"""look for field's value with the following rules:
1. handle special __type and eid fields
- 2. looks in kw args given to render_form
+ 2. looks in kw args given to render_form (including previously submitted
+ form values if any)
3. looks in req.form
4. if entity has an eid:
1. looks for an associated attribute / method
@@ -545,12 +551,12 @@
values = value()
return field.format_value(self.req, value)
- def form_field_name(self, field, values):
+ def form_field_name(self, field):
if field.eidparam:
return eid_param(field.name, self.entity.eid)
return field.name
- def form_field_id(self, field, values):
+ def form_field_id(self, field):
if field.eidparam:
return eid_param(field.id, self.entity.eid)
return field.id
--- a/web/views/baseforms.py Thu Feb 19 19:28:44 2009 +0100
+++ b/web/views/baseforms.py Thu Feb 19 20:33:50 2009 +0100
@@ -86,14 +86,18 @@
self.w(u'</li>')
+from cubicweb.web.form import EntityFieldsForm, TextField, RichTextField, HiddenInput
+
class ChangeStateForm(EntityFieldsForm):
- state = TextField(widget=HiddenWidget)
- __method = TextField(widget=HiddenWidget, initial='set_state')
+ state = TextField(widget=HiddenInput)
+ __method = TextField(widget=HiddenInput, initial='set_state')
trcomment = RichTextField(eidparam=True)
def buttons(self):
- return [Button(label=stdmsgs.YES),
- Button(label=stdmsgs.NO)]
+ return [self.button_ok(label=self.req._(stdmsgs.YES),
+ tabindex=self.req.next_tabindex()),
+ self.button_cancel(label=self.req._(stdmsgs.NO),
+ tabindex=self.req.next_tabindex())]
class ChangeStateFormView(FormMixIn, EntityView):
id = 'statuschange'
@@ -115,9 +119,8 @@
'st1': _(state.name),
'st2': _(dest.name)}
self.w(u'<p>%s</p>\n' % msg)
-
form = ChangeStateForm(redirect_path=self.redirectpath(entity)) # self.vreg.select_form('changestateform')
- self.w(form.render(req, entity, state=dest.eid))
+ self.w(form.form_render(req, entity, state=dest.eid))
# self.w(u'<form action="%s" onsubmit="return freezeFormButtons(\'entityForm\');" method="post" id="entityForm">\n'
--- a/web/widgets.py Thu Feb 19 19:28:44 2009 +0100
+++ b/web/widgets.py Thu Feb 19 20:33:50 2009 +0100
@@ -4,7 +4,7 @@
serialization time
:organization: Logilab
-:copyright: 2001-2008 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
+:copyright: 2001-2009 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
:contact: http://www.logilab.fr/ -- mailto:contact@logilab.fr
"""
__docformat__ = "restructuredtext en"