use dbhelper functions to get default date / datetime (closes #2094544)
authorAlexandre Fayolle <alexandre.fayolle@logilab.fr>
Mon, 21 Nov 2011 17:58:18 +0100
changeset 8097 7e0d1fb1092d
parent 8096 e1b21db042d6
child 8099 4fce19f0305b
use dbhelper functions to get default date / datetime (closes #2094544)
__pkginfo__.py
debian/control
hooks/syncschema.py
--- a/__pkginfo__.py	Tue Nov 22 11:26:06 2011 +0100
+++ b/__pkginfo__.py	Mon Nov 21 17:58:18 2011 +0100
@@ -52,7 +52,7 @@
     'Twisted': '',
     # XXX graphviz
     # server dependencies
-    'logilab-database': '>= 1.5.0',
+    'logilab-database': '>= 1.8.1',
     'pysqlite': '>= 2.5.5', # XXX install pysqlite2
     }
 
--- a/debian/control	Tue Nov 22 11:26:06 2011 +0100
+++ b/debian/control	Mon Nov 21 17:58:18 2011 +0100
@@ -35,7 +35,7 @@
 Conflicts: cubicweb-multisources
 Replaces: cubicweb-multisources
 Provides: cubicweb-multisources
-Depends: ${misc:Depends}, ${python:Depends}, cubicweb-common (= ${source:Version}), cubicweb-ctl (= ${source:Version}), python-logilab-database (>= 1.5.0), cubicweb-postgresql-support | cubicweb-mysql-support | python-pysqlite2
+Depends: ${misc:Depends}, ${python:Depends}, cubicweb-common (= ${source:Version}), cubicweb-ctl (= ${source:Version}), python-logilab-database (>= 1.8.1), cubicweb-postgresql-support | cubicweb-mysql-support | python-pysqlite2
 Recommends: pyro (<< 4.0.0), cubicweb-documentation (= ${source:Version})
 Description: server part of the CubicWeb framework
  CubicWeb is a semantic web application framework.
--- a/hooks/syncschema.py	Tue Nov 22 11:26:06 2011 +0100
+++ b/hooks/syncschema.py	Mon Nov 21 17:58:18 2011 +0100
@@ -484,6 +484,11 @@
         # set default value, using sql for performance and to avoid
         # modification_date update
         if default:
+            if  rdefdef.object in ('Date', 'Datetime'):
+                if default == 'TODAY':
+                    default = syssource.dbhelper.sql_current_date()
+                elif default == 'NOW':
+                    default = syssource.dbhelper.sql_current_timestamp()
             session.system_sql('UPDATE %s SET %s=%%(default)s' % (table, column),
                                {'default': default})