make forms selectable (appobject) tls-sprint
authorsylvain.thenault@logilab.fr
Wed, 11 Mar 2009 11:15:08 +0100
branchtls-sprint
changeset 1047 21d4d5e6aa45
parent 1046 52ee022d87e3
child 1048 2a93712a6f8b
make forms selectable (appobject)
web/form.py
web/views/baseforms.py
--- a/web/form.py	Wed Mar 11 11:13:41 2009 +0100
+++ b/web/form.py	Wed Mar 11 11:15:08 2009 +0100
@@ -17,8 +17,9 @@
 from yams.constraints import SizeConstraint, StaticVocabularyConstraint
 
 from cubicweb import typed_eid
+from cubicweb.appobject import AppObject
 from cubicweb.utils import ustrftime
-from cubicweb.selectors import match_form_params
+from cubicweb.selectors import yes, match_form_params, non_final_entity
 from cubicweb.view import NOINDEX, NOFOLLOW, View, EntityView, AnyRsetView
 from cubicweb.common.registerers import accepts_registerer
 from cubicweb.common.uilib import toggle_action
@@ -718,14 +719,17 @@
         return super(metafieldsform, mcs).__new__(mcs, name, bases, classdict)
     
 
-class FieldsForm(FormMixIn):
+class FieldsForm(FormMixIn, AppObject):
     __metaclass__ = metafieldsform
+    __registry__ = 'forms'
+    __select__ = yes()
     
-    def __init__(self, req, domid=None, title=None, action='edit',
-                 onsubmit="return freezeFormButtons('%s');",
+    def __init__(self, req, rset=None, domid=None, title=None, action='edit',
+                 onsubmit="return freezeFormButtons('%(domid)s');",
                  cssclass=None, cssstyle=None, cwtarget=None, buttons=None,
                  redirect_path=None, set_error_url=True, copy_nav_params=False):
         self.req = req
+        self.rset = rset
         self.config = req.vreg.config
         self.domid = domid or 'form'
         self.title = title
@@ -805,6 +809,7 @@
 
    
 class EntityFieldsForm(FieldsForm):
+    __select__ = non_final_entity()
     
     def __init__(self, *args, **kwargs):
         kwargs.setdefault('domid', 'entityForm')
--- a/web/views/baseforms.py	Wed Mar 11 11:13:41 2009 +0100
+++ b/web/views/baseforms.py	Wed Mar 11 11:15:08 2009 +0100
@@ -74,6 +74,7 @@
 
 
 class ChangeStateForm(EntityFieldsForm):
+    id = 'changestate'
     __method = StringField(name='__method', initial='set_state', widget=HiddenInput)
     state = StringField(widget=HiddenInput, eidparam=True)
     # XXX format field
@@ -101,8 +102,8 @@
         self.req.add_js('cubicweb.edition.js')
         self.req.add_css('cubicweb.form.css')
         _ = self.req._
-        form = ChangeStateForm(self.req, entity=entity,
-                               redirect_path=self.redirectpath(entity))
+        form = self.select_object('forms', 'changestate', self.req, self.rset, row, col,
+                                  entity=entity, redirect_path=self.redirectpath(entity))
         self.w(form.error_message())
         self.w(u'<h4>%s %s</h4>\n' % (_(transition.name), entity.view('oneline')))
         msg = _('status will change from %(st1)s to %(st2)s') % {