merge
authorAdrien Di Mascio <Adrien.DiMascio@logilab.fr>
Fri, 29 Apr 2011 09:08:30 +0200
changeset 7278 1144a2d90314
parent 7277 acd7f0e9f276 (current diff)
parent 7272 771f594c12a2 (diff)
child 7281 daee8aec3b9b
merge
utils.py
web/request.py
--- a/cwconfig.py	Thu Apr 28 20:41:44 2011 +0200
+++ b/cwconfig.py	Fri Apr 29 09:08:30 2011 +0200
@@ -1070,9 +1070,10 @@
     def instance_md5_version(self):
         import hashlib
         infos = []
-        for pkg in self.cubes():
+        for pkg in sorted(self.cubes()):
             version = self.cube_version(pkg)
             infos.append('%s-%s' % (pkg, version))
+        infos.append('cubicweb-%s' % str(self.cubicweb_version()))
         return hashlib.md5(';'.join(infos)).hexdigest()
 
     def load_configuration(self):
--- a/cwvreg.py	Thu Apr 28 20:41:44 2011 +0200
+++ b/cwvreg.py	Fri Apr 29 09:08:30 2011 +0200
@@ -402,10 +402,8 @@
                      if not isinstance(view, class_deprecated)]
             try:
                 view = self._select_best(views, req, rset=rset, **kwargs)
-                if view.linkable():
+                if view is not None and view.linkable():
                     yield view
-            except NoSelectableObject:
-                continue
             except Exception:
                 self.exception('error while trying to select %s view for %s',
                                vid, rset)
--- a/devtools/testlib.py	Thu Apr 28 20:41:44 2011 +0200
+++ b/devtools/testlib.py	Fri Apr 29 09:08:30 2011 +0200
@@ -562,6 +562,8 @@
             if views:
                 try:
                     view = viewsvreg._select_best(views, req, rset=rset)
+                    if view is None:
+                        raise NoSelectableObject((req,), {'rset':rset}, views)
                     if view.linkable():
                         yield view
                     else:
--- a/misc/migration/3.10.9_Any.py	Thu Apr 28 20:41:44 2011 +0200
+++ b/misc/migration/3.10.9_Any.py	Fri Apr 29 09:08:30 2011 +0200
@@ -15,14 +15,14 @@
     nbops = rset.rowcount
     enabled = interactive_mode
     with progress(title=title, nbops=nbops, size=30, enabled=enabled) as pb:
-        with hooks_control(session, session.HOOKS_DENY_ALL, 'integrity'):
-            for i,  row in enumerate(rset):
+        for i,  row in enumerate(rset):
+            with hooks_control(session, session.HOOKS_DENY_ALL, 'integrity'):
                 data = {'eid': row[0], 'cwuri': row[1].replace(u'/eid', u'')}
                 rql('SET X cwuri %(cwuri)s WHERE X eid %(eid)s', data)
-                if not i % 100: # commit every 100 entities to limit memory consumption
-                    pb.text = "%i committed" % i
-                    commit(ask_confirm=False)
-                pb.update()
+            if not i % 100: # commit every 100 entities to limit memory consumption
+                pb.text = "%i committed" % i
+                commit(ask_confirm=False)
+            pb.update()
         commit(ask_confirm=False)
 
 try:
--- a/utils.py	Thu Apr 28 20:41:44 2011 +0200
+++ b/utils.py	Fri Apr 29 09:08:30 2011 +0200
@@ -230,7 +230,10 @@
     Request objects use a HTMLHead instance to ease adding of
     javascripts and stylesheets
     """
-    js_unload_code = u'jQuery(window).unload(unloadPageData);'
+    js_unload_code = u'''if (typeof(pageDataUnloaded) == 'undefined') {
+    jQuery(window).unload(unloadPageData);
+    pageDataUnloaded = true;
+}'''
     # Making <script> tag content work properly with all possible
     # content-types (xml/html) and all possible browsers is very
     # tricky, see http://www.hixie.ch/advocacy/xhtml for an in-depth discussion
--- a/vregistry.py	Thu Apr 28 20:41:44 2011 +0200
+++ b/vregistry.py	Fri Apr 29 09:08:30 2011 +0200
@@ -184,7 +184,10 @@
 
         raise :exc:`NoSelectableObject` if not object apply
         """
-        return self._select_best(self[__oid], *args, **kwargs)
+        obj =  self._select_best(self[__oid], *args, **kwargs)
+        if obj is None:
+            raise NoSelectableObject(args, kwargs, self[__oid] )
+        return obj
 
     def select_or_none(self, __oid, *args, **kwargs):
         """return the most specific object among those with the given oid
@@ -202,16 +205,18 @@
         context
         """
         for appobjects in self.itervalues():
-            try:
-                yield self._select_best(appobjects, *args, **kwargs)
-            except NoSelectableObject:
+            obj = self._select_best(appobjects,  *args, **kwargs)
+            if obj is None:
                 continue
+            yield obj
 
     def _select_best(self, appobjects, *args, **kwargs):
         """return an instance of the most specific object according
         to parameters
 
-        raise `NoSelectableObject` if not object apply
+        return None if not object apply (don't raise `NoSelectableObject` since
+        it's costly when searching appobjects using `possible_objects`
+        (e.g. searching for hooks).
         """
         if len(args) > 1:
             warn('[3.5] only the request param can not be named when calling select*',
@@ -224,7 +229,7 @@
             elif appobjectscore > 0 and appobjectscore == score:
                 winners.append(appobject)
         if winners is None:
-            raise NoSelectableObject(args, kwargs, appobjects)
+            return None
         if len(winners) > 1:
             # log in production environement / test, error while debugging
             msg = 'select ambiguity: %s\n(args: %s, kwargs: %s)'
--- a/web/request.py	Thu Apr 28 20:41:44 2011 +0200
+++ b/web/request.py	Fri Apr 29 09:08:30 2011 +0200
@@ -135,12 +135,12 @@
         """
         return self.set_varmaker()
 
-    def _get_tabindex_func(self):
+    def next_tabindex(self):
         nextfunc = self.get_page_data('nexttabfunc')
         if nextfunc is None:
             nextfunc = count(1).next
             self.set_page_data('nexttabfunc', nextfunc)
-        return nextfunc
+        return nextfunc()
 
     def set_varmaker(self):
         varmaker = self.get_page_data('rql_varmaker')
@@ -154,8 +154,6 @@
         or an anonymous connection is open
         """
         super(CubicWebRequestBase, self).set_session(session, user)
-        # tabindex generator
-        self.next_tabindex = self._get_tabindex_func()
         # set request language
         vreg = self.vreg
         if self.user:
--- a/web/views/startup.py	Thu Apr 28 20:41:44 2011 +0200
+++ b/web/views/startup.py	Fri Apr 29 09:08:30 2011 +0200
@@ -125,7 +125,7 @@
     def create_links(self):
         self.w(u'<ul class="createLink">')
         for etype in self.add_etype_links:
-            eschema = self.schema.eschema(etype)
+            eschema = self._cw.vreg.schema.eschema(etype)
             if eschema.has_perm(self._cw, 'add'):
                 self.w(u'<li><a href="%s">%s</a></li>' % (
                         self._cw.build_url('add/%s' % eschema),
--- a/web/views/urlpublishing.py	Thu Apr 28 20:41:44 2011 +0200
+++ b/web/views/urlpublishing.py	Fri Apr 29 09:08:30 2011 +0200
@@ -260,9 +260,8 @@
             else:
                 try:
                     action = actionsreg._select_best(actions, req, rset=rset)
+                    if action is not None:
+                        raise Redirect(action.url())
                 except RegistryException:
-                    continue
-                else:
-                    # XXX avoid redirect
-                    raise Redirect(action.url())
+                    pass # continue searching
         raise PathDontMatch()