--- a/web/form.py Wed Dec 09 15:19:14 2009 +0100
+++ b/web/form.py Wed Dec 09 15:19:48 2009 +0100
@@ -36,158 +36,6 @@
return False
-# XXX should disappear
-class FormMixIn(object):
- """abstract form mix-in
- XXX: you should inherit from this FIRST (obscure pb with super call)
- """
- force_session_key = None
-
- def session_key(self):
- """return the key that may be used to store / retreive data about a
- previous post which failed because of a validation error
- """
- if self.force_session_key is None:
- return '%s#%s' % (self.req.url(), self.domid)
- return self.force_session_key
-
- def restore_previous_post(self, sessionkey):
- # get validation session data which may have been previously set.
- # deleting validation errors here breaks form reloading (errors are
- # no more available), they have to be deleted by application's publish
- # method on successful commit
- forminfo = self.req.get_session_data(sessionkey, pop=True)
- if forminfo:
- # XXX remove req.data assigment once cw.web.widget is killed
- self.req.data['formvalues'] = self._form_previous_values = forminfo['values']
- self.req.data['formerrors'] = self._form_valerror = forminfo['errors']
- self.req.data['displayederrors'] = self.form_displayed_errors = set()
- # if some validation error occured on entity creation, we have to
- # get the original variable name from its attributed eid
- foreid = self.form_valerror.entity
- for var, eid in forminfo['eidmap'].items():
- if foreid == eid:
- self.form_valerror.eid = var
- break
- else:
- self.form_valerror.eid = foreid
- else:
- self._form_previous_values = {}
- self._form_valerror = None
-
- @property
- def form_previous_values(self):
- if self.parent_form is None:
- return self._form_previous_values
- return self.parent_form.form_previous_values
-
- @property
- def form_valerror(self):
- if self.parent_form is None:
- return self._form_valerror
- return self.parent_form.form_valerror
-
- # XXX deprecated with new form system. Should disappear
-
- domid = 'entityForm'
- category = 'form'
- controller = 'edit'
- http_cache_manager = httpcache.NoHTTPCacheManager
- add_to_breadcrumbs = False
-
- def html_headers(self):
- """return a list of html headers (eg something to be inserted between
- <head> and </head> of the returned page
-
- by default forms are neither indexed nor followed
- """
- return [NOINDEX, NOFOLLOW]
-
- def linkable(self):
- """override since forms are usually linked by an action,
- so we don't want them to be listed by appli.possible_views
- """
- return False
-
-
- def button(self, label, klass='validateButton', tabindex=None, **kwargs):
- if tabindex is None:
- tabindex = self.req.next_tabindex()
- return tags.input(value=label, klass=klass, **kwargs)
-
- def action_button(self, label, onclick=None, __action=None, **kwargs):
- if onclick is None:
- onclick = "postForm('__action_%s', \'%s\', \'%s\')" % (
- __action, label, self.domid)
- return self.button(label, onclick=onclick, **kwargs)
-
- def button_ok(self, label=None, type='submit', name='defaultsubmit',
- **kwargs):
- label = self.req._(label or stdmsgs.BUTTON_OK).capitalize()
- return self.button(label, name=name, type=type, **kwargs)
-
- def button_apply(self, label=None, type='button', **kwargs):
- label = self.req._(label or stdmsgs.BUTTON_APPLY).capitalize()
- return self.action_button(label, __action='apply', type=type, **kwargs)
-
- def button_delete(self, label=None, type='button', **kwargs):
- label = self.req._(label or stdmsgs.BUTTON_DELETE).capitalize()
- return self.action_button(label, __action='delete', type=type, **kwargs)
-
- def button_cancel(self, label=None, type='button', **kwargs):
- label = self.req._(label or stdmsgs.BUTTON_CANCEL).capitalize()
- return self.action_button(label, __action='cancel', type=type, **kwargs)
-
- def button_reset(self, label=None, type='reset', name='__action_cancel',
- **kwargs):
- label = self.req._(label or stdmsgs.BUTTON_CANCEL).capitalize()
- return self.button(label, type=type, **kwargs)
-
- def need_multipart(self, entity, categories=('primary', 'secondary')):
- """return a boolean indicating if form's enctype should be multipart
- """
- for rschema, _, x in entity.relations_by_category(categories):
- if entity.get_widget(rschema, x).need_multipart:
- return True
- # let's find if any of our inlined entities needs multipart
- for rschema, targettypes, x in entity.relations_by_category('inlineview'):
- assert len(targettypes) == 1, \
- "I'm not able to deal with several targets and inlineview"
- ttype = targettypes[0]
- inlined_entity = self.vreg.etype_class(ttype)(self.req, None, None)
- for irschema, _, x in inlined_entity.relations_by_category(categories):
- if inlined_entity.get_widget(irschema, x).need_multipart:
- return True
- return False
-
- def error_message(self):
- """return formatted error message
-
- This method should be called once inlined field errors has been consumed
- """
- errex = self.req.data.get('formerrors') or self.form_valerror
- # get extra errors
- if errex is not None:
- errormsg = self.req._('please correct the following errors:')
- displayed = self.req.data.get('displayederrors') or self.form_displayed_errors
- errors = sorted((field, err) for field, err in errex.errors.items()
- if not field in displayed)
- if errors:
- if len(errors) > 1:
- templstr = '<li>%s</li>\n'
- else:
- templstr = ' %s\n'
- for field, err in errors:
- if field is None:
- errormsg += templstr % err
- else:
- errormsg += templstr % '%s: %s' % (self.req._(field), err)
- if len(errors) > 1:
- errormsg = '<ul>%s</ul>' % errormsg
- return u'<div class="errorMessage">%s</div>' % errormsg
- return u''
-
-
###############################################################################
class metafieldsform(type):
@@ -295,7 +143,7 @@
previous post which failed because of a validation error
"""
if self.force_session_key is None:
- return '%s#%s' % (self.req.url(), self.domid)
+ return '%s#%s' % (self._cw.url(), self.domid)
return self.force_session_key
def restore_previous_post(self, sessionkey):
--- a/web/views/autoform.py Wed Dec 09 15:19:14 2009 +0100
+++ b/web/views/autoform.py Wed Dec 09 15:19:48 2009 +0100
@@ -286,7 +286,7 @@
# to add new related entities
if self.should_display_add_new_relation_link(rschema, formviews, card):
addnewlink = self.vreg['views'].select(
- 'inline-addnew-link', self.req,
+ 'inline-addnew-link', self._cw,
etype=ttype, rtype=rschema, role=role,
peid=self.edited_entity.eid, pform=self, card=card)
formviews.append(addnewlink)
--- a/web/views/editforms.py Wed Dec 09 15:19:14 2009 +0100
+++ b/web/views/editforms.py Wed Dec 09 15:19:48 2009 +0100
@@ -483,13 +483,13 @@
@cached
def form(self):
entity = self._entity()
- form = self.vreg['forms'].select('edition', self._cw,
- entity=entity,
- form_renderer_id='inline',
- copy_nav_params=False,
- mainform=False,
- parent_form=self.pform,
- **self.extra_kwargs)
+ form = self._cw.vreg['forms'].select('edition', self._cw,
+ entity=entity,
+ form_renderer_id='inline',
+ copy_nav_params=False,
+ mainform=False,
+ parent_form=self.pform,
+ **self.cw_extra_kwargs)
if self.pform is None:
form.restore_previous_post(form.session_key())
#assert form.parent_form
@@ -519,16 +519,13 @@
self._cw.data[countkey] += 1
except KeyError:
self._cw.data[countkey] = 1
- self.w(self.form.form.render(
- divid=divid, title=title, removejs=removejs, i18nctx=i18nctx,
- counter=self.req.data[countkey], **kwargs))
self.w(self.form.render(
rendervalues=dict(divid=divid, title=title, removejs=removejs,
i18nctx=i18nctx, counter=self._cw.data[countkey]),
formvalues=kwargs))
def form_title(self, entity, i18nctx):
- return self.req.pgettext(i18nctx, 'This %s' % entity.e_schema)
+ return self._cw.pgettext(i18nctx, 'This %s' % entity.e_schema)
def add_hiddens(self, form, entity):
"""to ease overriding (see cubes.vcsfile.views.forms for instance)"""
@@ -581,9 +578,8 @@
except:
self.w(self._cw._('no such entity type %s') % etype)
return
- self.initialize_varmaker()
- entity = cls(self.req)
- entity.eid = self.varmaker.next()
+ entity = cls(self._cw)
+ entity.eid = self._cw.varmaker.next()
return entity
def call(self, i18nctx, **kwargs):
@@ -609,7 +605,7 @@
self.peid, self.etype, self.rtype, self.role, i18nctx)
if self.pform.should_hide_add_new_relation_link(self.rtype, self.card):
js = "toggleVisibility('%s'); %s" % (divid, js)
- __ = self.req.pgettext
+ __ = self._cw.pgettext
self.w(u'<a class="addEntity" id="add%s:%slink" href="javascript: %s" >+ %s.</a>'
% (self.rtype, self.peid, js, __(i18nctx, 'add a %s' % self.etype)))
self.w(u'</div>')
--- a/web/views/forms.py Wed Dec 09 15:19:14 2009 +0100
+++ b/web/views/forms.py Wed Dec 09 15:19:48 2009 +0100
@@ -84,7 +84,7 @@
elif hasattr(self.__class__, key) and not key[0] == '_':
setattr(self, key, val)
else:
- self.extra_kwargs[key] = val
+ self.cw_extra_kwargs[key] = val
# skip other parameters, usually given for selection
# (else write a custom class to handle them)
if mainform:
@@ -185,7 +185,7 @@
if field.name in rendervalues:
value = rendervalues[field.name]
elif field.name in self.cw_extra_kwargs:
- value = self.extra_kwargs[field.name]
+ value = self.cw_extra_kwargs[field.name]
else:
value = self.form_field_value(field, load_bytes)
if callable(value):