merge
authorSylvain Thénault <sylvain.thenault@logilab.fr>
Thu, 28 May 2009 20:07:18 +0200
changeset 1996 2490e18fd3c8
parent 1995 ec95eaa2b711 (current diff)
parent 1993 b3b51389566b (diff)
child 1997 554eb4dd533d
merge
web/views/basecontrollers.py
--- a/.hgtags	Thu May 28 20:06:45 2009 +0200
+++ b/.hgtags	Thu May 28 20:07:18 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 20:06:45 2009 +0200
+++ b/__pkginfo__.py	Thu May 28 20:07:18 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 20:06:45 2009 +0200
+++ b/debian/changelog	Thu May 28 20:07:18 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 20:06:45 2009 +0200
+++ b/server/schemahooks.py	Thu May 28 20:07:18 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 20:06:45 2009 +0200
+++ b/server/test/unittest_hooks.py	Thu May 28 20:07:18 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 20:06:45 2009 +0200
+++ b/web/data/cubicweb.edition.js	Thu May 28 20:07:18 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/data/cubicweb.preferences.js	Thu May 28 20:06:45 2009 +0200
+++ b/web/data/cubicweb.preferences.js	Thu May 28 20:07:18 2009 +0200
@@ -84,10 +84,8 @@
     jQuery(form).find('[type=text]').each(function () {
 	    unfreezeButtons = _checkValue(jQuery(this), unfreezeButtons);
 	});
-    jQuery(form).find('input[type=radio]').each(function () {
-	    if (jQuery(this).attr('checked')){
-		unfreezeButtons = _checkValue(jQuery(this), unfreezeButtons);
-	    }
+    jQuery(form).find('input[type=radio]:checked').each(function () {
+            unfreezeButtons = _checkValue(jQuery(this), unfreezeButtons);
      });
 
     if (unfreezeButtons){
@@ -103,7 +101,7 @@
 
 function _checkValue(input, unfreezeButtons){
      var currentValueInput = jQuery("input[name=current-" + input.attr('name') + "]");
-     if (currentValueInput.attr('value') != input.attr('value')){
+     if (currentValueInput.val() != input.val()){
 	 input.addClass('changed');
 	 unfreezeButtons = true;
      }else{
@@ -121,12 +119,15 @@
 	    var name = currentValueInput.attr('name').split('-')[1];
 	    jQuery(form).find("[name=" + name + "]").each(function (){
 		    var input = jQuery(this);
-		    if(input.attr('type')=='radio'){
-			if(input.attr('checked')){
-			    currentValueInput.attr('value', input.attr('value'));
+		    if(input.attr('type') == 'radio'){
+			// NOTE: there seems to be a bug with jQuery(input).attr('checked')
+			//       in our case, we can't rely on its value, we use
+			//       the DOM API instead.
+			if(input[0].checked){
+			    currentValueInput.val(input.val());
 			}
 		    }else{
-			currentValueInput.attr('value', input.attr('value'));
+			currentValueInput.val(input.val());
 		    }
 		});
     });
--- a/web/views/basecontrollers.py	Thu May 28 20:06:45 2009 +0200
+++ b/web/views/basecontrollers.py	Thu May 28 20:07:18 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)
--- a/web/views/plots.py	Thu May 28 20:06:45 2009 +0200
+++ b/web/views/plots.py	Thu May 28 20:07:18 2009 +0200
@@ -139,7 +139,7 @@
         nbcols = len(self.rset.rows[0])
         for col in xrange(1, nbcols):
             data = [row[col] for row in self.rset]
-            plots.append(filterout_nulls(abscissa, plot))
+            plots.append(filterout_nulls(abscissa, data))
         plotwidget = FlotPlotWidget(varnames, plots, timemode=self.timemode)
         plotwidget.render(self.req, width, height, w=self.w)