diff -r f36d43f00f32 -r 874a055c373b web/views/basecontrollers.py --- 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'\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'\n' + dt return head + u'
%s
' % 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 """""" % 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)