work in progress, draft for manual registration tls-sprint
authorAdrien Di Mascio <Adrien.DiMascio@logilab.fr>
Tue, 17 Feb 2009 14:28:14 +0100
branchtls-sprint
changeset 660 5233a9457f6b
parent 659 5d754a1933cb
child 661 4f61eb8a96b7
work in progress, draft for manual registration
common/view.py
selectors.py
vregistry.py
web/views/actions.py
web/views/facets.py
web/views/tableview.py
--- a/common/view.py	Tue Feb 17 14:00:17 2009 +0100
+++ b/common/view.py	Tue Feb 17 14:28:14 2009 +0100
@@ -418,7 +418,7 @@
     is only used globally (i.e. no result set adaptation)
     """
     __registry__ = 'templates'
-    __registerer__ = priority_registerer
+    # __registerer__ = priority_registerer
     __selectors__ = (yes,)
 
     registered = require_group_compat(View.registered.im_func)
--- a/selectors.py	Tue Feb 17 14:00:17 2009 +0100
+++ b/selectors.py	Tue Feb 17 14:28:14 2009 +0100
@@ -483,12 +483,16 @@
         self.expected_ifaces = expected_ifaces
 
     def score_class(self, eclass, req):
+        print '***********************************'
         score = 0
         for iface in self.expected_ifaces:
+            print 'TESTING', iface, 'on', eclass
             if isinstance(iface, basestring):
                 # entity type
                 iface = eclass.vreg.etype_class(iface)
+                print 'found iface ===', iface
             if implements_iface(eclass, iface):
+                print 'and implementing !!!'
                 score += 1
                 if getattr(iface, '__registry__', None) == 'etypes':
                     score += 1
@@ -504,6 +508,7 @@
                                 score += index
 #                                print 'etype majoration', index
                                 break
+        print '***********************************', score
         return score
 
 
--- a/vregistry.py	Tue Feb 17 14:00:17 2009 +0100
+++ b/vregistry.py	Tue Feb 17 14:28:14 2009 +0100
@@ -204,7 +204,47 @@
 
     def __contains__(self, key):
         return key in self._registries
-        
+
+
+    ##########
+    def register(self, obj, registryname=None):
+        registryname = registryname or obj.__registry__
+        registry = self._registries.setdefault(registryname, {})
+        registry.setdefault(obj.id, []).append(obj)
+        # XXX automatic reloading management
+        self._registered['%s.%s' % (obj.__module__, obj.id)] = obj
+
+    def register_if_interface_found(self, obj, registryname, iface):
+        registry = self._registries.setdefault(registryname, {})
+        for etype in self.registry_object('etypes'):
+            if implements(etype, iface):
+                registry.setdefault(obj.id, []).append(obj)
+                # XXX automatic reloading management
+                self._registered['%s.%s' % (obj.__module__, obj.id)] = obj
+                break
+
+    def unregister(self, obj, registryname=None):
+        registryname = registryname or obj.__registry__
+        registry = self.registry(registryname)
+        removed_id = obj.classid()
+        for registered in registry[obj.id]:
+            # use classid() to compare classes because vreg will probably
+            # have its own version of the class, loaded through execfile
+            if registered.classid() == removed_id:
+                # XXX automatic reloading management
+                registry[obj.id].remove(registered)
+                break
+    
+    def register_and_replace(self, obj, replaced, registryname=None):
+        registryname = registryname or obj.__registry__
+        registry = self.registry(registryname)
+        registered_objs = registry[obj.id]
+        for index, registered in enumerate(registered_objs):
+            if registered.classid() == replaced:
+                registry[obj.id][index] = obj
+                self._registered['%s.%s' % (obj.__module__, obj.id)] = obj
+    ##########
+    
     def register_vobject_class(self, cls, _kicked=set()):
         """handle vobject class registration
         
@@ -473,13 +513,20 @@
         return True
 
     def load_module(self, module):
-        registered = {}
-        self.info('loading %s', module)
-        for objname, obj in vars(module).items():
-            if objname.startswith('_'):
-                continue
-            self.load_ancestors_then_object(module.__name__, registered, obj)
-        return registered
+        if hasattr(module, 'cw_register_objects'):
+            self._registered = {}
+            module.cw_register_objects(self)
+            registered = self._resigtered
+            del self._registered
+            return registered
+        else:
+            registered = {}
+            self.info('loading %s', module)
+            for objname, obj in vars(module).items():
+                if objname.startswith('_'):
+                    continue
+                self.load_ancestors_then_object(module.__name__, registered, obj)
+            return registered
     
     def load_ancestors_then_object(self, modname, registered, obj):
         # skip imported classes
--- a/web/views/actions.py	Tue Feb 17 14:00:17 2009 +0100
+++ b/web/views/actions.py	Tue Feb 17 14:28:14 2009 +0100
@@ -143,7 +143,7 @@
     
 class DeleteAction(Action):
     id = 'delete'
-    __selectors__ = (has_permission('delete'),)
+    __selectors__ = (one_line_rset, has_permission('delete'))
     
     title = _('delete')
     category = 'moreactions' 
@@ -158,7 +158,7 @@
         
 class CopyAction(Action):
     id = 'copy'
-    __selectors__ = (has_permission('add'),)
+    __selectors__ = (one_line_rset, has_permission('add'))
     
     title = _('copy')
     category = 'moreactions'
--- a/web/views/facets.py	Tue Feb 17 14:00:17 2009 +0100
+++ b/web/views/facets.py	Tue Feb 17 14:28:14 2009 +0100
@@ -27,8 +27,7 @@
 class FilterBox(BoxTemplate):
     """filter results of a query"""
     id = 'filter_box'
-    __selectors__ = (chainfirst(contextview_selector,
-                                chainall(non_final_entity, two_lines_rset)),
+    __selectors__ = ((non_final_entity() & two_lines_rset) | contextview_selector,
                      match_context_prop)
     context = 'left'
     title = _('boxes_filter_box')
--- a/web/views/tableview.py	Tue Feb 17 14:00:17 2009 +0100
+++ b/web/views/tableview.py	Tue Feb 17 14:28:14 2009 +0100
@@ -5,6 +5,8 @@
 :copyright: 2001-2009 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
 :contact: http://www.logilab.fr/ -- mailto:contact@logilab.fr
 """
+from __future__ import with_statement
+
 __docformat__ = "restructuredtext en"
 
 from simplejson import dumps
@@ -222,7 +224,9 @@
         
 
     def render(self, cellvid, row, col, w):
-        self.view('cell', self.rset, row=row, col=col, cellvid=cellvid, w=w)
+        from cubicweb.selectors import traced_selection
+        with traced_selection( ('cell',) ):
+            self.view('cell', self.rset, row=row, col=col, cellvid=cellvid, w=w)
         
     def get_rows(self):
         return self.rset