merge stable branch into default
authorNicolas Chauvat <nicolas.chauvat@logilab.fr>
Thu, 28 May 2009 15:09:35 +0200
changeset 1990 59507a12a7f4
parent 1980 35394365b6c1 (current diff)
parent 1981 e6eed4324357 (diff)
child 1991 8a9d8f1ee100
merge stable branch into default
__pkginfo__.py
server/schemahooks.py
server/test/unittest_hooks.py
web/views/basecontrollers.py
--- a/.hgtags	Thu May 28 11:37:27 2009 +0200
+++ b/.hgtags	Thu May 28 15:09:35 2009 +0200
@@ -36,3 +36,5 @@
 9b21e068fef73c37bcb4e53d006a7bde485f390b cubicweb-version-3_2_2
 92d1a15f08f7c5fa87643ffb4273d12cb3f41c63 cubicweb-debian-version-3_2_2-1
 0e07514264aa1b0b671226f41725ea4c066c210a cubicweb-debian-version-3_2_2-1
+f60bb84b86cf371f1f25197e00c778b469297721 cubicweb-version-3_2_3
+4003d24974f15f17bd03b7efd6a5047cad4e4c41 cubicweb-debian-version-3_2_3-1
--- a/__pkginfo__.py	Thu May 28 11:37:27 2009 +0200
+++ b/__pkginfo__.py	Thu May 28 15:09:35 2009 +0200
@@ -7,7 +7,7 @@
 distname = "cubicweb"
 modname = "cubicweb"
 
-numversion = (3, 2, 2)
+numversion = (3, 2, 3)
 version = '.'.join(str(num) for num in numversion)
 
 license = 'LGPL v2'
--- a/debian/changelog	Thu May 28 11:37:27 2009 +0200
+++ b/debian/changelog	Thu May 28 15:09:35 2009 +0200
@@ -1,4 +1,4 @@
-cubicweb (3.2.2-1) unstable; urgency=low
+cubicweb (3.2.3-1) unstable; urgency=low
 
   * new upstream release
 
--- a/server/schemahooks.py	Thu May 28 11:37:27 2009 +0200
+++ b/server/schemahooks.py	Thu May 28 15:09:35 2009 +0200
@@ -188,7 +188,7 @@
     DeleteCWRTypeOp(session, name)
 
 
-class DelErdefOp(SchemaOperation):
+class DelRelationDefOp(SchemaOperation):
     """actually remove the relation definition from the application's schema"""
     def commit_event(self):
         subjtype, rtype, objtype = self.kobj
@@ -237,7 +237,7 @@
     # if this is the last instance, drop associated relation type
     if lastrel and not rteid in pendings:
         execute('DELETE CWRType X WHERE X eid %(x)s', {'x': rteid}, 'x')
-    DelErdefOp(session, (subjschema, rschema, objschema))
+    DelRelationDefOp(session, (subjschema, rschema, objschema))
 
 
 # addition ####################################################################
@@ -562,7 +562,7 @@
         self.session.repo.schema.rename_entity_type(self.oldname, self.newname)
 
 
-class UpdateRdefOp(SchemaOperation):
+class UpdateRelationDefOp(SchemaOperation):
     """actually update some properties of a relation definition"""
     rschema = values = None # make pylint happy
 
@@ -576,6 +576,19 @@
                 sysource.create_index(self.session, table, column)
             else:
                 sysource.drop_index(self.session, table, column)
+        if 'cardinality' in self.values and self.rschema.is_final():
+            if self.session.pool.source('system').dbdriver == 'sqlite':
+                # not supported (and NOT NULL not set by yams in that case, so
+                # no worry)
+                return
+            sqlexec = self.session.system_sql
+            etype, rtype = self.kobj[0], self.rschema.type
+            if self.values['cardinality'][0] == '1':
+                cmd = 'SET'
+            else:
+                cmd = 'DROP'
+            sqlexec('ALTER TABLE %s ALTER COLUMN %s %s NOT NULL' % (
+                table, SQL_PREFIX + etype, SQL_PREFIX + rtype))
 
     def commit_event(self):
         # structure should be clean, not need to remove entity's relations
@@ -596,8 +609,8 @@
             newvalues[prop] = entity[prop]
     if newvalues:
         subjtype = entity.from_entity[0].name
-        UpdateRdefOp(session, (subjtype, desttype), rschema=rschema,
-                     values=newvalues)
+        UpdateRelationDefOp(session, (subjtype, desttype),
+                            rschema=rschema, values=newvalues)
 
 
 class UpdateRtypeOp(SchemaOperation):
--- a/server/test/unittest_hooks.py	Thu May 28 11:37:27 2009 +0200
+++ b/server/test/unittest_hooks.py	Thu May 28 15:09:35 2009 +0200
@@ -455,6 +455,23 @@
             self.failIf(self.schema['Affaire'].has_unique_values('sujet'))
             self.failIf(self.index_exists('Affaire', 'sujet', unique=True))
 
+    def test_required_change_1(self):
+        self.execute('SET DEF cardinality "?1" '
+                     'WHERE DEF relation_type RT, DEF from_entity E,'
+                     'RT name "nom", E name "Personne"')
+        self.commit()
+        # should now be able to add personne without nom
+        self.execute('INSERT Personne X')
+        self.commit()
+
+    def test_required_change_2(self):
+        self.execute('SET DEF cardinality "11" '
+                     'WHERE DEF relation_type RT, DEF from_entity E,'
+                     'RT name "prenom", E name "Personne"')
+        self.commit()
+        # should not be able anymore to add personne without prenom
+        self.assertRaises(ValidationError, self.execute, 'INSERT Personne X: X nom "toto"')
+
 
 class WorkflowHooksTC(RepositoryBasedTC):
 
--- a/web/data/cubicweb.edition.js	Thu May 28 11:37:27 2009 +0200
+++ b/web/data/cubicweb.edition.js	Thu May 28 15:09:35 2009 +0200
@@ -505,7 +505,7 @@
 	return false;
     }
     d.addCallback(function (result, req) {
-	    handleFormValidationResponse(formid, noop, noop, result);
+        handleFormValidationResponse(formid, noop, noop, result);
 	var fieldview = getNode(divid);
         fieldview.innerHTML = result[2];
 	// switch inline form off only if no error
--- a/web/views/basecontrollers.py	Thu May 28 11:37:27 2009 +0200
+++ b/web/views/basecontrollers.py	Thu May 28 15:09:35 2009 +0200
@@ -15,6 +15,7 @@
 import simplejson
 
 from logilab.common.decorators import cached
+from logilab.mtconverter import html_escape
 
 from cubicweb import NoSelectableObject, ValidationError, ObjectNotFound, typed_eid
 from cubicweb.utils import strptime
@@ -417,6 +418,8 @@
             rset = entity.related(rtype, role)
             if rset:
                 output = self.view(vid, rset)
+                if vid == 'textoutofcontext':
+                    output = html_escape(output)
             else:
                 output = default
             return (success, args, output)