--- a/web/views/basecontrollers.py Thu May 21 00:44:57 2009 +0200
+++ b/web/views/basecontrollers.py Thu May 21 00:50:24 2009 +0200
@@ -18,7 +18,7 @@
from cubicweb import NoSelectableObject, ValidationError, ObjectNotFound, typed_eid
from cubicweb.utils import strptime
from cubicweb.selectors import yes, match_user_groups
-from cubicweb.view import STRICT_DOCTYPE
+from cubicweb.view import STRICT_DOCTYPE, STRICT_DOCTYPE_NOEXT
from cubicweb.common.mail import format_mail
from cubicweb.web import ExplicitLogin, Redirect, RemoteCallFailed, json_dumps
from cubicweb.web.formrenderers import FormRenderer
@@ -32,8 +32,13 @@
HAS_SEARCH_RESTRICTION = False
-def xhtml_wrap(source):
- head = u'<?xml version="1.0"?>\n' + STRICT_DOCTYPE
+def xhtml_wrap(self, source):
+ # XXX factor out, watch view.py ~ Maintemplate.doctype
+ if self.req.xhtml_browser():
+ dt = STRICT_DOCTYPE
+ else:
+ dt = STRICT_DOCTYPE_NOEXT
+ head = u'<?xml version="1.0"?>\n' + dt
return head + u'<div xmlns="http://www.w3.org/1999/xhtml" xmlns:cubicweb="http://www.logilab.org/2008/cubicweb">%s</div>' % source.strip()
def jsonize(func):
@@ -51,7 +56,7 @@
def wrapper(self, *args, **kwargs):
self.req.set_content_type(self.req.html_content_type())
result = func(self, *args, **kwargs)
- return xhtml_wrap(result)
+ return xhtml_wrap(self, result)
wrapper.__name__ = func.__name__
return wrapper
@@ -205,7 +210,7 @@
self.req.set_content_type('text/html')
jsarg = simplejson.dumps( (status, args) )
return """<script type="text/javascript">
- window.parent.handleFormValidationResponse('entityForm', null, %s);
+ window.parent.handleFormValidationResponse('entityForm', null, null, %s);
</script>""" % simplejson.dumps( (status, args) )
def validation_error(self, err):
@@ -379,11 +384,7 @@
ctrl.publish(None, fromjson=True)
except ValidationError, err:
self.req.cnx.rollback()
- if not err.entity or isinstance(err.entity, (long, int)):
- eid = err.entity
- else:
- eid = err.entity.eid
- return (False, (eid, err.errors))
+ return (False, (err.entity, err.errors))
except Redirect, redir:
return (True, redir.location)
except Exception, err:
@@ -484,6 +485,24 @@
rql = 'DELETE B bookmarked_by U WHERE B eid %(b)s, U eid %(u)s'
self.req.execute(rql, {'b': typed_eid(beid), 'u' : self.req.user.eid})
+ def js_node_clicked(self, treeid, nodeeid):
+ """add/remove eid in treestate cookie"""
+ from cubicweb.web.views.treeview import treecookiename
+ cookies = self.req.get_cookie()
+ statename = treecookiename(treeid)
+ treestate = cookies.get(statename)
+ if treestate is None:
+ cookies[statename] = nodeeid
+ self.req.set_cookie(cookies, statename)
+ else:
+ marked = set(filter(None, treestate.value.split(';')))
+ if nodeeid in marked:
+ marked.remove(nodeeid)
+ else:
+ marked.add(nodeeid)
+ cookies[statename] = ';'.join(marked)
+ self.req.set_cookie(cookies, statename)
+
def js_set_cookie(self, cookiename, cookievalue):
# XXX we should consider jQuery.Cookie
cookiename, cookievalue = str(cookiename), str(cookievalue)