--- a/goa/skel/views.py Thu Apr 30 17:44:35 2009 +0200
+++ b/goa/skel/views.py Thu Apr 30 17:45:02 2009 +0200
@@ -1,7 +1,7 @@
# custom application views
-from calendar import monthrange
from datetime import date
+from cubicweb.utils import last_day
from cubicweb.web.views import baseviews, boxes, calendar
from cubicweb.web.htmlwidgets import BoxLink, BoxWidget
@@ -36,7 +36,7 @@
box = BoxWidget(_('Blog archives'), id=self.id)
for year, month in blogmonths:
firstday = date(year, month, 1)
- lastday = date(year, month, monthrange(year, month)[1])
+ lastday = last_day(firstday)
rql = ('Any B WHERE B is BlogEntry, B creation_date >= "%s", B creation_date <= "%s"'
% (firstday.strftime('%Y-%m-%d'), lastday.strftime('%Y-%m-%d')))
url = self.build_url(rql=rql)
--- a/server/sqlutils.py Thu Apr 30 17:44:35 2009 +0200
+++ b/server/sqlutils.py Thu Apr 30 17:45:02 2009 +0200
@@ -7,7 +7,7 @@
__docformat__ = "restructuredtext en"
from warnings import warn
-from datetime import datetime, timedelta
+from datetime import datetime, date, timedelta
from logilab.common.shellutils import ProgressBar
from logilab.common import db
@@ -17,6 +17,7 @@
from indexer import get_indexer
from cubicweb import Binary, ConfigurationError
+from cubicweb.utils import todate, todatetime
from cubicweb.common.uilib import remove_html_tags
from cubicweb.server import SQL_CONNECT_HOOKS
from cubicweb.server.utils import crypt_password
@@ -68,8 +69,8 @@
w(grant_schema(schema, user, set_owner, skip_entities=skip_entities, prefix=SQL_PREFIX))
return '\n'.join(output)
-
-def sqlschema(schema, driver, text_index=True,
+
+def sqlschema(schema, driver, text_index=True,
user=None, set_owner=False,
skip_relations=('has_text', 'identity'), skip_entities=()):
"""return the system sql schema, according to the given parameters"""
@@ -86,7 +87,7 @@
w(indexer.sql_init_fti())
w('')
dbhelper = get_adv_func_helper(driver)
- w(schema2sql(dbhelper, schema, prefix=SQL_PREFIX,
+ w(schema2sql(dbhelper, schema, prefix=SQL_PREFIX,
skip_entities=skip_entities, skip_relations=skip_relations))
if dbhelper.users_support and user:
w('')
@@ -94,8 +95,8 @@
skip_relations, skip_entities))
return '\n'.join(output)
-
-def sqldropschema(schema, driver, text_index=True,
+
+def sqldropschema(schema, driver, text_index=True,
skip_relations=('has_text', 'identity'), skip_entities=()):
"""return the sql to drop the schema, according to the given parameters"""
from yams.schema2sql import dropschema2sql
@@ -121,7 +122,7 @@
"""Mixin for SQL data sources, getting a connection from a configuration
dictionary and handling connection locking
"""
-
+
def __init__(self, source_config):
try:
self.dbdriver = source_config['db-driver'].lower()
@@ -138,7 +139,7 @@
self.binary = self.dbapi_module.Binary
self.dbhelper = self.dbapi_module.adv_func_helper
self.sqlgen = SQLGenerator()
-
+
def get_connection(self, user=None, password=None):
"""open and return a connection to the database"""
if user or self.dbuser:
@@ -216,6 +217,11 @@
value = value.getvalue()
else:
value = crypt_password(value)
+ # XXX needed for sqlite but I don't think it is for other backends
+ elif atype == 'Datetime' and isinstance(value, date):
+ value = todatetime(value)
+ elif atype == 'Date' and isinstance(value, datetime):
+ value = todate(value)
elif isinstance(value, Binary):
value = self.binary(value.getvalue())
# XXX <3.2 bw compat
@@ -254,7 +260,7 @@
# some time
cnx.create_aggregate("CONCAT_STRINGS", 1, concat_strings)
cnx.create_aggregate("GROUP_CONCAT", 1, concat_strings)
-
+
def _limit_size(text, maxsize, format='text/plain'):
if len(text) < maxsize:
return text
--- a/utils.py Thu Apr 30 17:44:35 2009 +0200
+++ b/utils.py Thu Apr 30 17:45:02 2009 +0200
@@ -27,7 +27,14 @@
if isinstance(somedate, datetime):
return date(somedate.year, somedate.month, somedate.day)
assert isinstance(somedate, date), repr(somedate)
- return date
+ return somedate
+
+def todatetime(somedate):
+ """return a date from a date (leaving unchanged) or a datetime"""
+ if isinstance(somedate, date):
+ return datetime(somedate.year, somedate.month, somedate.day)
+ assert isinstance(somedate, datetime), repr(somedate)
+ return somedate
ONEDAY = timedelta(days=1)
--- a/web/views/ajaxedit.py Thu Apr 30 17:44:35 2009 +0200
+++ b/web/views/ajaxedit.py Thu Apr 30 17:45:02 2009 +0200
@@ -6,6 +6,7 @@
"""
__docformat__ = "restructuredtext en"
+from cubicweb import role
from cubicweb.selectors import match_form_params, match_kwargs
from cubicweb.web.box import EditRelationBoxTemplate
@@ -24,7 +25,7 @@
expected_kwargs = form_params = ('rtype', 'target')
build_js = EditRelationBoxTemplate.build_reload_js_call
-
+
def cell_call(self, row, col, rtype=None, target=None, etype=None):
self.rtype = rtype or self.req.form['rtype']
self.target = target or self.req.form['target']
@@ -41,7 +42,7 @@
fakebox = []
self.w(u'<div id="%s">' % self.id)
self.w(u'<h1>%s</h1>' % self.req._('relation %(relname)s of %(ent)s')
- % {'relname': rschema.display_name(self.req, self.xtarget()[0]),
+ % {'relname': rschema.display_name(self.req, role(self)),
'ent': entity.view('incontext')})
self.w(u'<ul>')
self.w_unrelated(fakebox, entity)
@@ -55,15 +56,16 @@
if etype is not defined on the Box's class, the default
behaviour is to use the entity's appropraite vocabulary function
"""
- x, target = self.xtarget()
# use entity.unrelated if we've been asked for a particular etype
if getattr(self, 'etype', None):
- rset = entity.unrelated(self.rtype, self.etype, x, ordermethod='fetch_order')
+ rset = entity.unrelated(self.rtype, self.etype, role(self),
+ ordermethod='fetch_order')
self.pagination(self.req, rset, w=self.w)
return rset.entities()
# in other cases, use vocabulary functions
entities = []
- for _, eid in entity.vocabulary(self.rtype, x):
+ # XXX to update for 3.2
+ for _, eid in entity.vocabulary(self.rtype, role(self)):
if eid is not None:
rset = self.req.eid_rset(eid)
entities.append(rset.get_entity(0, 0))