backport stable
authorSylvain Thénault <sylvain.thenault@logilab.fr>
Fri, 20 May 2011 17:29:50 +0200
changeset 7412 9179ae452159
parent 7406 e772a2c57b00 (current diff)
parent 7411 238da9684f99 (diff)
child 7413 94ad9523abb7
backport stable
server/migractions.py
web/request.py
--- a/req.py	Thu May 19 18:48:26 2011 +0200
+++ b/req.py	Fri May 20 17:29:50 2011 +0200
@@ -88,7 +88,7 @@
         rset = ResultSet([('A',)]*size, '%s X' % etype,
                          description=[(etype,)]*size)
         def get_entity(row, col=0, etype=etype, req=self, rset=rset):
-            return req.vreg.etype_class(etype)(req, rset, row, col)
+            return req.vreg['etypes'].etype_class(etype)(req, rset, row, col)
         rset.get_entity = get_entity
         rset.req = self
         return rset
--- a/server/migractions.py	Thu May 19 18:48:26 2011 +0200
+++ b/server/migractions.py	Fri May 20 17:29:50 2011 +0200
@@ -1423,7 +1423,7 @@
         return self.cmd_create_entity(etype, *args, **kwargs).eid
 
     @contextmanager
-    def cmd_dropped_constraints(self, etype, attrname, cstrtype,
+    def cmd_dropped_constraints(self, etype, attrname, cstrtype=None,
                                 droprequired=False):
         """context manager to drop constraints temporarily on fs_schema
 
@@ -1443,8 +1443,9 @@
         rdef = self.fs_schema.eschema(etype).rdef(attrname)
         original_constraints = rdef.constraints
         # remove constraints
-        rdef.constraints = [cstr for cstr in original_constraints
-                            if not (cstrtype and isinstance(cstr, cstrtype))]
+        if cstrtype:
+            rdef.constraints = [cstr for cstr in original_constraints
+                                if not (cstrtype and isinstance(cstr, cstrtype))]
         if droprequired:
             original_cardinality = rdef.cardinality
             rdef.cardinality = '?' + rdef.cardinality[1]
@@ -1514,13 +1515,13 @@
         rschema = self.repo.schema.rschema(attr)
         oldtype = rschema.objects(etype)[0]
         rdefeid = rschema.rproperty(etype, oldtype, 'eid')
-        sql = ("UPDATE CWAttribute "
-               "SET to_entity=(SELECT eid FROM CWEType WHERE name='%s')"
-               "WHERE eid=%s") % (newtype, rdefeid)
+        sql = ("UPDATE cw_CWAttribute "
+               "SET cw_to_entity=(SELECT cw_eid FROM cw_CWEType WHERE cw_name='%s')"
+               "WHERE cw_eid=%s") % (newtype, rdefeid)
         self.sqlexec(sql, ask_confirm=False)
         dbhelper = self.repo.system_source.dbhelper
         sqltype = dbhelper.TYPE_MAPPING[newtype]
-        sql = 'ALTER TABLE %s ALTER COLUMN %s TYPE %s' % (etype, attr, sqltype)
+        sql = 'ALTER TABLE cw_%s ALTER COLUMN cw_%s TYPE %s' % (etype, attr, sqltype)
         self.sqlexec(sql, ask_confirm=False)
         if commit:
             self.commit()
--- a/uilib.py	Thu May 19 18:48:26 2011 +0200
+++ b/uilib.py	Fri May 20 17:29:50 2011 +0200
@@ -1,5 +1,5 @@
 # -*- coding: utf-8 -*-
-# copyright 2003-2010 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
+# copyright 2003-2011 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
 # contact http://www.logilab.fr/ -- mailto:contact@logilab.fr
 #
 # This file is part of CubicWeb.
--- a/web/formwidgets.py	Thu May 19 18:48:26 2011 +0200
+++ b/web/formwidgets.py	Fri May 20 17:29:50 2011 +0200
@@ -1,4 +1,4 @@
-# copyright 2003-2010 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
+# copyright 2003-2011 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
 # contact http://www.logilab.fr/ -- mailto:contact@logilab.fr
 #
 # This file is part of CubicWeb.
--- a/web/request.py	Thu May 19 18:48:26 2011 +0200
+++ b/web/request.py	Fri May 20 17:29:50 2011 +0200
@@ -1,4 +1,4 @@
-# copyright 2003-2010 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
+# copyright 2003-2011 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
 # contact http://www.logilab.fr/ -- mailto:contact@logilab.fr
 #
 # This file is part of CubicWeb.
--- a/web/schemaviewer.py	Thu May 19 18:48:26 2011 +0200
+++ b/web/schemaviewer.py	Fri May 20 17:29:50 2011 +0200
@@ -151,9 +151,9 @@
                     continue
                 label = rschema.type
                 if role == 'subject':
-                    cards = rschema.rproperty(eschema, oeschema, 'cardinality')
+                    cards = rschema.rdef(eschema, oeschema).cardinality
                 else:
-                    cards = rschema.rproperty(oeschema, eschema, 'cardinality')
+                    cards = rschema.rdef(oeschema, eschema).cardinality
                     cards = cards[::-1]
                 label = '%s %s %s' % (CARD_MAP[cards[1]], label,
                                       CARD_MAP[cards[0]])
--- a/web/views/autoform.py	Thu May 19 18:48:26 2011 +0200
+++ b/web/views/autoform.py	Fri May 20 17:29:50 2011 +0200
@@ -1,4 +1,4 @@
-# copyright 2003-2010 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
+# copyright 2003-2011 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
 # contact http://www.logilab.fr/ -- mailto:contact@logilab.fr
 #
 # This file is part of CubicWeb.
--- a/web/views/formrenderers.py	Thu May 19 18:48:26 2011 +0200
+++ b/web/views/formrenderers.py	Fri May 20 17:29:50 2011 +0200
@@ -1,4 +1,4 @@
-# copyright 2003-2010 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
+# copyright 2003-2011 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
 # contact http://www.logilab.fr/ -- mailto:contact@logilab.fr
 #
 # This file is part of CubicWeb.
@@ -40,7 +40,7 @@
 from logilab.common import dictattr
 from logilab.mtconverter import xml_escape
 
-from cubicweb import tags
+from cubicweb import tags, uilib
 from cubicweb.appobject import AppObject
 from cubicweb.selectors import is_instance, yes
 from cubicweb.utils import json_dumps, support_args
@@ -112,18 +112,21 @@
         data = []
         _w = data.append
         _w(self.open_form(form, values))
-        if self.display_progress_div:
-            _w(u'<div id="progress">%s</div>' % self._cw._('validating...'))
-        _w(u'\n<fieldset>\n')
-        self.render_fields(_w, form, values)
-        self.render_buttons(_w, form)
-        _w(u'\n</fieldset>\n')
+        self.render_content(_w, form, values)
         _w(self.close_form(form, values))
         errormsg = self.error_message(form)
         if errormsg:
             data.insert(0, errormsg)
         w(''.join(data))
 
+    def render_content(self, w, form, values):
+        if self.display_progress_div:
+            w(u'<div id="progress">%s</div>' % self._cw._('validating...'))
+        w(u'\n<fieldset>\n')
+        self.render_fields(w, form, values)
+        self.render_buttons(w, form)
+        w(u'\n</fieldset>\n')
+
     def render_label(self, form, field):
         if field.label is None:
             return u''
@@ -179,24 +182,25 @@
             return u'<div class="errorMessage">%s</div>' % errormsg
         return u''
 
-    def open_form(self, form, values):
+    def open_form(self, form, values, **attrs):
         if form.needs_multipart:
             enctype = u'multipart/form-data'
         else:
             enctype = u'application/x-www-form-urlencoded'
-        tag = (u'<form action="%s" method="post" enctype="%s"' % (
-            xml_escape(form.form_action() or '#'), enctype))
+        attrs.setdefault('enctype', enctype)
+        attrs.setdefault('method', 'post')
+        attrs.setdefault('action', form.form_action() or '#')
         if form.domid:
-            tag += u' id="%s"' % form.domid
+            attrs.setdefault('id', form.domid)
         if form.onsubmit:
-            tag += u' onsubmit="%s"' % xml_escape(form.onsubmit % dictattr(form))
+            attrs.setdefault('onsubmit',  form.onsubmit % dictattr(form))
         if form.cssstyle:
-            tag += u' style="%s"' % xml_escape(form.cssstyle)
+            attrs.setdefault('style', form.cssstyle)
         if form.cssclass:
-            tag += u' class="%s"' % xml_escape(form.cssclass)
+            attrs.setdefault('class', form.cssclass)
         if form.cwtarget:
-            tag += u' cubicweb:target="%s"' % xml_escape(form.cwtarget)
-        return tag + u'>'
+            attrs.setdefault('cubicweb:target', form.cwtarget)
+        return '<form %s>' % uilib.sgml_attributes(attrs)
 
     def close_form(self, form, values):
         """seems dumb but important for consistency w/ close form, and necessary
--- a/web/views/workflow.py	Thu May 19 18:48:26 2011 +0200
+++ b/web/views/workflow.py	Fri May 20 17:29:50 2011 +0200
@@ -1,4 +1,4 @@
-# copyright 2003-2010 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
+# copyright 2003-2011 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
 # contact http://www.logilab.fr/ -- mailto:contact@logilab.fr
 #
 # This file is part of CubicWeb.
@@ -114,7 +114,7 @@
 
     def get_form(self, entity, transition, **kwargs):
         # XXX used to specify both rset/row/col and entity in case implements
-        # selector (and not implements) is used on custom form
+        # selector (and not is_instance) is used on custom form
         form = self._cw.vreg['forms'].select(
             'changestate', self._cw, entity=entity, transition=transition,
             redirect_path=self.redirectpath(entity), **kwargs)