# HG changeset patch # User Adrien Di Mascio # Date 1253744661 -7200 # Node ID e4843535db25a792676dd933981ad6acb097b53a # Parent e134d2dd9992a5f0a608781ad554584d257b5bbe [api] some more _cw / __regid__, automatic tests now pass again diff -r e134d2dd9992 -r e4843535db25 common/mixins.py --- a/common/mixins.py Thu Sep 24 00:23:32 2009 +0200 +++ b/common/mixins.py Thu Sep 24 00:24:21 2009 +0200 @@ -207,7 +207,7 @@ """handle an infinite recursion safety belt""" if done is None: done = set() - entity = view.rset.get_entity(row, col) + entity = view.cw_rset.get_entity(row, col) if entity.eid in done: msg = entity._cw._('loop in %(rel)s relation (%(eid)s)') % { 'rel': entity.tree_attribute, diff -r e134d2dd9992 -r e4843535db25 entities/lib.py --- a/entities/lib.py Thu Sep 24 00:23:32 2009 +0200 +++ b/entities/lib.py Thu Sep 24 00:24:21 2009 +0200 @@ -109,11 +109,11 @@ rest_attr = 'pkey' def typed_value(self): - return self.vreg.typed_value(self.pkey, self.value) + return self._cw.vreg.typed_value(self.pkey, self.value) def dc_description(self, format='text/plain'): try: - return self._cw._(self.vreg.property_info(self.pkey)['help']) + return self._cw._(self._cw.vreg.property_info(self.pkey)['help']) except UnknownProperty: return u'' diff -r e134d2dd9992 -r e4843535db25 web/action.py --- a/web/action.py Thu Sep 24 00:23:32 2009 +0200 +++ b/web/action.py Thu Sep 24 00:24:21 2009 +0200 @@ -91,7 +91,7 @@ def url(self): current_entity = self.cw_rset.get_entity(self.cw_row or 0, self.cw_col or 0) linkto = '%s:%s:%s' % (self.rtype, current_entity.eid, target(self)) - return self.build_url('add/%s' % self.etype, __linkto=linkto, - __redirectpath=current_entity.rest_path(), # should not be url quoted! - __redirectvid=self._cw.form.get('__redirectvid', '')) + return self._cw.build_url('add/%s' % self.etype, __linkto=linkto, + __redirectpath=current_entity.rest_path(), # should not be url quoted! + __redirectvid=self._cw.form.get('__redirectvid', '')) diff -r e134d2dd9992 -r e4843535db25 web/controller.py --- a/web/controller.py Thu Sep 24 00:23:32 2009 +0200 +++ b/web/controller.py Thu Sep 24 00:24:21 2009 +0200 @@ -198,7 +198,7 @@ path = self._edited_entity.rest_path() else: path = 'view' - url = self.build_url(path, **newparams) + url = self._cw.build_url(path, **newparams) url = append_url_params(url, self.req.form.get('__redirectparams')) raise Redirect(url) @@ -223,7 +223,7 @@ for redirectparam in NAV_FORM_PARAMETERS: if redirectparam in form: newparams[redirectparam] = form[redirectparam] - raise Redirect(self.build_url(path, **newparams)) + raise Redirect(self._cw.build_url(path, **newparams)) def _return_to_lastpage(self, newparams): @@ -235,7 +235,7 @@ if '__redirectpath' in self.req.form: # if redirect path was explicitly specified in the form, use it path = self.req.form['__redirectpath'] - url = self.build_url(path, **newparams) + url = self._cw.build_url(path, **newparams) url = append_url_params(url, self.req.form.get('__redirectparams')) else: url = self.req.last_visited_page() diff -r e134d2dd9992 -r e4843535db25 web/httpcache.py --- a/web/httpcache.py Thu Sep 24 00:23:32 2009 +0200 +++ b/web/httpcache.py Thu Sep 24 00:24:21 2009 +0200 @@ -17,7 +17,7 @@ """default cache manager: set no-cache cache control policy""" def __init__(self, view): self.view = view - self.req = view.req + self.req = view._cw self.cw_rset = view.rset def set_headers(self): @@ -42,7 +42,7 @@ date_format = "%a, %d %b %Y %H:%M:%S GMT" def etag(self): - return self.view.id + '/' + ','.join(sorted(self.req.user.groups)) + return self.view.__regid__ + '/' + ','.join(sorted(self.req.user.groups)) def max_age(self): # 0 to actually force revalidation diff -r e134d2dd9992 -r e4843535db25 web/test/unittest_breadcrumbs.py --- a/web/test/unittest_breadcrumbs.py Thu Sep 24 00:23:32 2009 +0200 +++ b/web/test/unittest_breadcrumbs.py Thu Sep 24 00:24:21 2009 +0200 @@ -1,6 +1,6 @@ -from cubicweb.devtools.testlib import WebTest +from cubicweb.devtools.testlib import CubicWebTC -class BreadCrumbsTC(WebTest): +class BreadCrumbsTC(CubicWebTC): def test_base(self): f1 = self.add_entity('Folder', name=u'par&ent') diff -r e134d2dd9992 -r e4843535db25 web/test/unittest_controller.py --- a/web/test/unittest_controller.py Thu Sep 24 00:23:32 2009 +0200 +++ b/web/test/unittest_controller.py Thu Sep 24 00:24:21 2009 +0200 @@ -13,7 +13,7 @@ def test_parse_datetime_ok(self): ctrl = self.vreg['controllers'].select('view', self.request()) - pd = ctrl.parse_datetime + pd = ctrl._cw.parse_datetime self.assertIsInstance(pd('2006/06/24 12:18'), datetime) self.assertIsInstance(pd('2006/06/24'), date) self.assertIsInstance(pd('2006/06/24 12:18', 'Datetime'), datetime) @@ -23,7 +23,7 @@ def test_parse_datetime_ko(self): ctrl = self.vreg['controllers'].select('view', self.request()) - pd = ctrl.parse_datetime + pd = ctrl._cw.parse_datetime self.assertRaises(ValueError, pd, '2006/06/24 12:188', 'Datetime') self.assertRaises(ValueError, diff -r e134d2dd9992 -r e4843535db25 web/views/authentication.py --- a/web/views/authentication.py Thu Sep 24 00:23:32 2009 +0200 +++ b/web/views/authentication.py Thu Sep 24 00:24:21 2009 +0200 @@ -73,19 +73,19 @@ login, password = req.get_authorization() if not login: # No session and no login -> try anonymous - login, password = self._cw.vreg.config.anonymous_user() + login, password = self.vreg.config.anonymous_user() if not login: # anonymous not authorized raise ExplicitLogin() # remove possibly cached cursor coming from closed connection clear_cache(req, 'cursor') - cnxprops = ConnectionProperties(self._cw.vreg.config.repo_method, + cnxprops = ConnectionProperties(self.vreg.config.repo_method, close=False, log=self.log_queries) try: cnx = repo_connect(self.repo, login, password, cnxprops=cnxprops) except AuthenticationError: req.set_message(req._('authentication failure')) # restore an anonymous connection if possible - anonlogin, anonpassword = self._cw.vreg.config.anonymous_user() + anonlogin, anonpassword = self.vreg.config.anonymous_user() if anonlogin and anonlogin != login: cnx = repo_connect(self.repo, anonlogin, anonpassword, cnxprops=cnxprops) @@ -100,9 +100,9 @@ def _init_cnx(self, cnx, login, password): # decorate connection - if login == self._cw.vreg.config.anonymous_user()[0]: + if login == self.vreg.config.anonymous_user()[0]: cnx.anonymous_connection = True - cnx.vreg = self._cw.vreg + cnx.vreg = self.vreg cnx.login = login cnx.password = password diff -r e134d2dd9992 -r e4843535db25 web/views/basecontrollers.py --- a/web/views/basecontrollers.py Thu Sep 24 00:23:32 2009 +0200 +++ b/web/views/basecontrollers.py Thu Sep 24 00:24:21 2009 +0200 @@ -422,7 +422,7 @@ def js_format_date(self, strdate): """returns the formatted date for `msgid`""" date = strptime(strdate, '%Y-%m-%d %H:%M:%S') - return self.format_date(date) + return self._cw.format_date(date) @jsonize def js_external_resource(self, resource): @@ -563,7 +563,7 @@ except Exception, ex: self.exception("can't connect to smtp server %s:%s (%s)", mailhost, port, ex) - url = self.build_url(__message=self._cw._('could not connect to the SMTP server')) + url = self._cw.build_url(__message=self._cw._('could not connect to the SMTP server')) raise Redirect(url) def sendmail(self, recipient, subject, body): @@ -583,7 +583,7 @@ text = body % recipient.as_email_context() self.sendmail(recipient.get_email(), subject, text) # breadcrumbs = self._cw.get_session_data('breadcrumbs', None) - url = self.build_url(__message=self._cw._('emails successfully sent')) + url = self._cw.build_url(__message=self._cw._('emails successfully sent')) raise Redirect(url) @@ -594,6 +594,6 @@ def publish(self, rset=None): body = self._cw.form['description'] self.sendmail(self._cw.config['submit-mail'], _('%s error report') % self._cw.config.appid, body) - url = self.build_url(__message=self._cw._('bug report sent')) + url = self._cw.build_url(__message=self._cw._('bug report sent')) raise Redirect(url) diff -r e134d2dd9992 -r e4843535db25 web/views/basetemplates.py --- a/web/views/basetemplates.py Thu Sep 24 00:23:32 2009 +0200 +++ b/web/views/basetemplates.py Thu Sep 24 00:24:21 2009 +0200 @@ -59,7 +59,7 @@ msg = self._cw._('you have been logged out') w(u'

%s

\n' % msg) if self._cw.config['anonymous-user']: - indexurl = self.build_url('view', vid='index', __message=msg) + indexurl = self._cw.build_url('view', vid='index', __message=msg) w(u'

%s

' % ( xml_escape(indexurl), self._cw._('go back to the index page'))) diff -r e134d2dd9992 -r e4843535db25 web/views/calendar.py --- a/web/views/calendar.py Thu Sep 24 00:23:32 2009 +0200 +++ b/web/views/calendar.py Thu Sep 24 00:24:21 2009 +0200 @@ -285,13 +285,13 @@ if len(self.cw_rset.column_types(0)) == 1: etype = list(self.cw_rset.column_types(0))[0] - url = self.build_url(vid='creation', etype=etype, - schedule=True, - start=self._cw.format_date(celldate), stop=self._cw.format_date(celldate), - __redirectrql=self.cw_rset.printable_rql(), - __redirectparams=self._cw.build_url_params(year=curdate.year, month=curmonth), - __redirectvid=self.__regid__ - ) + url = self._cw.build_url(vid='creation', etype=etype, + schedule=True, + start=self._cw.format_date(celldate), stop=self._cw.format_date(celldate), + __redirectrql=self.cw_rset.printable_rql(), + __redirectparams=self._cw.build_url_params(year=curdate.year, month=curmonth), + __redirectvid=self.__regid__ + ) self.w(u'

%s
' % (xml_escape(url), self._cw._(u'add'))) self.w(u' ') self.w(u'') @@ -422,12 +422,12 @@ self.w(u'' % (classes, day)) if len(self.cw_rset.column_types(0)) == 1: etype = list(self.cw_rset.column_types(0))[0] - url = self.build_url(vid='creation', etype=etype, - schedule=True, - __redirectrql=self.cw_rset.printable_rql(), - __redirectparams=self._cw.build_url_params(year=year, week=week), - __redirectvid=self.__regid__ - ) + url = self._cw.build_url(vid='creation', etype=etype, + schedule=True, + __redirectrql=self.cw_rset.printable_rql(), + __redirectparams=self._cw.build_url_params(year=year, week=week), + __redirectvid=self.__regid__ + ) extra = ' ondblclick="addCalendarItem(event, hmin=8, hmax=20, year=%s, month=%s, day=%s, duration=2, baseurl=\'%s\')"' % ( wdate.year, wdate.month, wdate.day, xml_escape(url)) else: diff -r e134d2dd9992 -r e4843535db25 web/views/cwproperties.py --- a/web/views/cwproperties.py Thu Sep 24 00:23:32 2009 +0200 +++ b/web/views/cwproperties.py Thu Sep 24 00:24:21 2009 +0200 @@ -211,10 +211,10 @@ else: label = key subform = self._cw.vreg['forms'].select('base', self._cw, entity=entity, - mainform=False) + mainform=False) subform.append_field(PropertyValueField(name='value', label=label, eidparam=True)) - subform.vreg = self._cw.vreg + #subform.vreg = self._cw.vreg subform.form_add_hidden('pkey', key, eidparam=True) form.form_add_subform(subform) return subform @@ -265,7 +265,7 @@ # empty span as well else html validation fail (label is refering to # this id) return '
%s
' % ( - domid, domid, form.req._('select a key first')) + domid, domid, form._cw._('select a key first')) class NotEditableWidget(object): @@ -289,17 +289,17 @@ def render(self, form, renderer): wdg = self.get_widget(form) - wdg.attrs['tabindex'] = form.req.next_tabindex() + wdg.attrs['tabindex'] = form._cw.next_tabindex() wdg.attrs['onchange'] = "javascript:setPropValueWidget('%s', %s)" % ( - form.edited_entity.eid, form.req.next_tabindex()) + form.edited_entity.eid, form._cw.next_tabindex()) return wdg.render(form, self, renderer) def vocabulary(self, form): entity = form.edited_entity - _ = form.req._ + _ = form._cw._ if entity.has_eid(): return [(_(entity.pkey), entity.pkey)] - choices = entity.vreg.user_property_keys() + choices = entity._cw.vreg.user_property_keys() return [(u'', u'')] + sorted(zip((_(v) for v in choices), choices)) @@ -322,15 +322,15 @@ # on key selection return try: - pdef = form.vreg.property_info(entity.pkey) + pdef = form._cw.vreg.property_info(entity.pkey) except UnknownProperty, ex: self.warning('%s (you should probably delete that property ' 'from the database)', ex) - msg = form.req._('you should probably delete that property') + msg = form._cw._('you should probably delete that property') self.widget = NotEditableWidget(entity.printable_value('value'), '%s (%s)' % (msg, ex)) if entity.pkey.startswith('system.'): - msg = form.req._('value associated to this key is not editable ' + msg = form._cw._('value associated to this key is not editable ' 'manually') self.widget = NotEditableWidget(entity.printable_value('value'), msg) # XXX race condition when used from CWPropertyForm, should not rely on @@ -341,7 +341,7 @@ if vocab is not None: if callable(vocab): # list() just in case its a generator function - self.choices = list(vocab(form.req)) + self.choices = list(vocab(form._cw)) else: self.choices = vocab wdg = Select() diff -r e134d2dd9992 -r e4843535db25 web/views/cwuser.py --- a/web/views/cwuser.py Thu Sep 24 00:23:32 2009 +0200 +++ b/web/views/cwuser.py Thu Sep 24 00:24:21 2009 +0200 @@ -25,8 +25,8 @@ category = 'mainactions' def url(self): - login = self.cw_rset.get_entity(self.cw_row or 0, self.col or 0).login - return self.build_url('cwuser/%s'%login, vid='propertiesform') + login = self.cw_rset.get_entity(self.cw_row or 0, self.cw_col or 0).login + return self._cw.build_url('cwuser/%s'%login, vid='propertiesform') class FoafView(EntityView): diff -r e134d2dd9992 -r e4843535db25 web/views/editforms.py --- a/web/views/editforms.py Thu Sep 24 00:23:32 2009 +0200 +++ b/web/views/editforms.py Thu Sep 24 00:24:21 2009 +0200 @@ -297,8 +297,9 @@ def render_form(self, entity): """fetch and render the form""" self.form_title(entity) - form = self._cw.vreg['forms'].select('edition', self._cw, rset=entity.rset, - row=entity.row, col=entity.col, entity=entity, + form = self._cw.vreg['forms'].select('edition', self._cw, rset=entity.cw_rset, + row=entity.cw_row, col=entity.cw_col, + entity=entity, submitmsg=self.submited_message()) self.init_form(form, entity) self.w(form.form_render(formvid=u'edition')) diff -r e134d2dd9992 -r e4843535db25 web/views/editviews.py --- a/web/views/editviews.py Thu Sep 24 00:23:32 2009 +0200 +++ b/web/views/editviews.py Thu Sep 24 00:24:21 2009 +0200 @@ -141,7 +141,7 @@ _ = self._cw._ for eschema in targettypes: mode = '%s:%s:%s:%s' % (target, entity.eid, rschema.type, eschema) - url = self.build_url(entity.rest_path(), vid='search-associate', + url = self._cw.build_url(entity.rest_path(), vid='search-associate', __mode=mode) options.append((eschema.display_name(self._cw), '' % ( diff -r e134d2dd9992 -r e4843535db25 web/views/embedding.py --- a/web/views/embedding.py Thu Sep 24 00:23:32 2009 +0200 +++ b/web/views/embedding.py Thu Sep 24 00:24:21 2009 +0200 @@ -103,8 +103,8 @@ entity = self.cw_rset.get_entity(row, 0) url = urljoin(self._cw.base_url(), entity.embeded_url()) if self._cw.form.has_key('rql'): - return self.build_url('embed', url=url, rql=self._cw.form['rql']) - return self.build_url('embed', url=url) + return self._cw.build_url('embed', url=url, rql=self._cw.form['rql']) + return self._cw.build_url('embed', url=url) diff -r e134d2dd9992 -r e4843535db25 web/views/facets.py --- a/web/views/facets.py Thu Sep 24 00:23:32 2009 +0200 +++ b/web/views/facets.py Thu Sep 24 00:24:21 2009 +0200 @@ -109,8 +109,8 @@ bk_path = 'view?rql=%s' % rset.printable_rql() bk_title = self._cw._('my custom search') linkto = 'bookmarked_by:%s:subject' % self._cw.user.eid - bk_add_url = self.build_url('add/Bookmark', path=bk_path, title=bk_title, __linkto=linkto) - bk_base_url = self.build_url('add/Bookmark', title=bk_title, __linkto=linkto) + bk_add_url = self._cw.build_url('add/Bookmark', path=bk_path, title=bk_title, __linkto=linkto) + bk_base_url = self._cw.build_url('add/Bookmark', title=bk_title, __linkto=linkto) bk_link = u'%s' % ( xml_escape(bk_base_url), xml_escape(bk_add_url), diff -r e134d2dd9992 -r e4843535db25 web/views/ibreadcrumbs.py --- a/web/views/ibreadcrumbs.py Thu Sep 24 00:23:32 2009 +0200 +++ b/web/views/ibreadcrumbs.py Thu Sep 24 00:24:21 2009 +0200 @@ -44,7 +44,7 @@ def render_breadcrumbs(self, contextentity, path): root = path.pop(0) if isinstance(root, Entity): - self.w(u'%s' % (self._cw.build_url(root.id), + self.w(u'%s' % (self._cw.build_url(root.__regid__), root.dc_type('plural'))) self.w(self.separator) self.wpath_part(root, contextentity, not path) @@ -76,7 +76,7 @@ # XXX hack: only display etype name or first non entity path part root = path.pop(0) if isinstance(root, Entity): - self.w(u'%s' % (self._cw.build_url(root.id), + self.w(u'%s' % (self._cw.build_url(root.__regid__), root.dc_type('plural'))) else: self.wpath_part(root, contextentity, not path) diff -r e134d2dd9992 -r e4843535db25 web/views/idownloadable.py --- a/web/views/idownloadable.py Thu Sep 24 00:23:32 2009 +0200 +++ b/web/views/idownloadable.py Thu Sep 24 00:24:21 2009 +0200 @@ -26,7 +26,7 @@ return 1 def download_box(w, entity, title=None, label=None): - req = entity.req + req = entity._cw w(u'