--- a/web/views/basecontrollers.py Mon Apr 12 14:41:01 2010 +0200
+++ b/web/views/basecontrollers.py Tue Apr 13 12:19:24 2010 +0200
@@ -10,22 +10,19 @@
"""
__docformat__ = "restructuredtext en"
-from smtplib import SMTP
-
import simplejson
from logilab.common.decorators import cached
from logilab.common.date import strptime
-from cubicweb import (NoSelectableObject, ValidationError, ObjectNotFound,
- typed_eid)
+from cubicweb import (NoSelectableObject, ObjectNotFound, ValidationError,
+ AuthenticationError, typed_eid)
from cubicweb.utils import CubicWebJsonEncoder
from cubicweb.selectors import authenticated_user, match_form_params
from cubicweb.mail import format_mail
-from cubicweb.web import ExplicitLogin, Redirect, RemoteCallFailed, DirectResponse, json_dumps
+from cubicweb.web import Redirect, RemoteCallFailed, DirectResponse, json_dumps
from cubicweb.web.controller import Controller
-from cubicweb.web.views import vid_from_rset
-from cubicweb.web.views.formrenderers import FormRenderer
+from cubicweb.web.views import vid_from_rset, formrenderers
try:
from cubicweb.web.facet import (FilterRQLBuilder, get_facet,
@@ -59,7 +56,7 @@
user's session data
"""
def wrapper(self, *args, **kwargs):
- data = self._cw.get_session_data(self._cw.pageid)
+ data = self._cw.session.data.get(self._cw.pageid)
if data is None:
raise RemoteCallFailed(self._cw._('pageid-not-found'))
return func(self, *args, **kwargs)
@@ -73,7 +70,7 @@
"""log in the instance"""
if self._cw.vreg.config['auth-mode'] == 'http':
# HTTP authentication
- raise ExplicitLogin()
+ raise AuthenticationError()
else:
# Cookie authentication
return self.appli.need_login_content(self._cw)
@@ -119,7 +116,10 @@
req = self._cw
if rset is None and not hasattr(req, '_rql_processed'):
req._rql_processed = True
- rset = self.process_rql(req.form.get('rql'))
+ if req.cnx is None:
+ rset = None
+ else:
+ rset = self.process_rql(req.form.get('rql'))
if rset and rset.rowcount == 1 and '__method' in req.form:
entity = rset.get_entity(0, 0)
try:
@@ -187,7 +187,7 @@
req.cnx.rollback()
# XXX necessary to remove existant validation error?
# imo (syt), it's not necessary
- req.get_session_data(req.form.get('__errorurl'), pop=True)
+ req.session.data.pop(req.form.get('__errorurl'), None)
foreid = ex.entity
eidmap = req.data.get('eidmap', {})
for var, eid in eidmap.items():
@@ -380,7 +380,7 @@
form = self._cw.vreg['forms'].select('edition', self._cw, entity=entity)
form.build_context()
vfield = form.field_by_name('value')
- renderer = FormRenderer(self._cw)
+ renderer = formrenderers.FormRenderer(self._cw)
return vfield.render(form, renderer, tabindex=tabindex) \
+ renderer.render_help(form, vfield)
@@ -474,7 +474,7 @@
@check_pageid
@jsonize
def js_user_callback(self, cbname):
- page_data = self._cw.get_session_data(self._cw.pageid, {})
+ page_data = self._cw.session.data.get(self._cw.pageid, {})
try:
cb = page_data[cbname]
except KeyError:
@@ -503,7 +503,7 @@
self._cw.unregister_callback(self._cw.pageid, cbname)
def js_unload_page_data(self):
- self._cw.del_session_data(self._cw.pageid)
+ self._cw.session.data.pop(self._cw.pageid, None)
def js_cancel_edition(self, errorurl):
"""cancelling edition from javascript
@@ -548,15 +548,13 @@
def _add_pending(self, eidfrom, rel, eidto, kind):
key = 'pending_%s' % kind
- pendings = self._cw.get_session_data(key, set())
+ pendings = self._cw.session.data.setdefault(key, set())
pendings.add( (typed_eid(eidfrom), rel, typed_eid(eidto)) )
- self._cw.set_session_data(key, pendings)
def _remove_pending(self, eidfrom, rel, eidto, kind):
key = 'pending_%s' % kind
- pendings = self._cw.get_session_data(key)
+ pendings = self._cw.session.data[key]
pendings.remove( (typed_eid(eidfrom), rel, typed_eid(eidto)) )
- self._cw.set_session_data(key, pendings)
def js_remove_pending_insert(self, (eidfrom, rel, eidto)):
self._remove_pending(eidfrom, rel, eidto, 'insert')
@@ -613,7 +611,7 @@
for recipient in self.recipients():
text = body % recipient.as_email_context()
self.sendmail(recipient.get_email(), subject, text)
- # breadcrumbs = self._cw.get_session_data('breadcrumbs', None)
+ #breadcrumbs = self._cw.session.data.get('breadcrumbs', None)
url = self._cw.build_url(__message=self._cw._('emails successfully sent'))
raise Redirect(url)
@@ -644,7 +642,7 @@
def redirect(self):
req = self._cw
- breadcrumbs = req.get_session_data('breadcrumbs', None)
+ breadcrumbs = req.session.data.get('breadcrumbs', None)
if breadcrumbs is not None and len(breadcrumbs) > 1:
url = req.rebuild_url(breadcrumbs[-2],
__message=req._('transaction undoed'))