# HG changeset patch # User sylvain.thenault@logilab.fr # Date 1235072030 -3600 # Node ID 8591d896db7e573b2a61d4a41e6e3a003008cbaa # Parent f5aca5c5f6ca197c40eab0e924417e9844bb85de update some prototype, ChangeStateForm diff -r f5aca5c5f6ca -r 8591d896db7e web/form.py --- 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 diff -r f5aca5c5f6ca -r 8591d896db7e web/views/baseforms.py --- 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'') +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'

%s

\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'
\n' diff -r f5aca5c5f6ca -r 8591d896db7e web/widgets.py --- 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"