properly kill/depreciate component base class, only keep Component tls-sprint
authorsylvain.thenault@logilab.fr
Tue, 17 Feb 2009 14:45:54 +0100
branchtls-sprint
changeset 661 4f61eb8a96b7
parent 660 5233a9457f6b
child 662 6f867ab70e3d
properly kill/depreciate component base class, only keep Component
common/appobject.py
common/view.py
sobjects/notification.py
sobjects/supervising.py
web/action.py
web/application.py
web/component.py
web/views/apacherewrite.py
web/views/basecomponents.py
web/views/magicsearch.py
web/views/urlpublishing.py
--- a/common/appobject.py	Tue Feb 17 14:28:14 2009 +0100
+++ b/common/appobject.py	Tue Feb 17 14:45:54 2009 +0100
@@ -73,6 +73,7 @@
         instance = cls(req, rset)
         instance.row = row
         instance.col = col
+        instance.sel_kwargs = kwargs
         return instance
 
     # Eproperties definition:
@@ -323,56 +324,3 @@
         self.req = req
         self.rset = rset
         self.__dict__.update(kwargs)
-
-
-class ReloadableMixIn(object):
-    """simple mixin for reloadable parts of UI"""
-    
-    def user_callback(self, cb, args, msg=None, nonify=False):
-        """register the given user callback and return an url to call it ready to be
-        inserted in html
-        """
-        self.req.add_js('cubicweb.ajax.js')
-        if nonify:
-            _cb = cb
-            def cb(*args):
-                _cb(*args)
-        cbname = self.req.register_onetime_callback(cb, *args)
-        return self.build_js(cbname, html_escape(msg or ''))
-        
-    def build_update_js_call(self, cbname, msg):
-        rql = html_escape(self.rset.printable_rql())
-        return "javascript:userCallbackThenUpdateUI('%s', '%s', '%s', '%s', '%s', '%s')" % (
-            cbname, self.id, rql, msg, self.__registry__, self.div_id())
-    
-    def build_reload_js_call(self, cbname, msg):
-        return "javascript:userCallbackThenReloadPage('%s', '%s')" % (cbname, msg)
-
-    build_js = build_update_js_call # expect updatable component by default
-    
-    def div_id(self):
-        return ''
-
-
-class ComponentMixIn(ReloadableMixIn):
-    """simple mixin for component object"""
-    __registry__ = 'components'
-    __registerer__ = yes_registerer
-    __selectors__ = (yes,)
-    __select__ = classmethod(*__selectors__)
-
-    def div_class(self):
-        return '%s %s' % (self.propval('htmlclass'), self.id)
-
-    def div_id(self):
-        return '%sComponent' % self.id
-
-
-class Component(ComponentMixIn, AppObject):
-    """base class for non displayable components
-    """
-
-class SingletonComponent(Component):
-    """base class for non displayable unique components
-    """
-    __registerer__ = priority_registerer
--- a/common/view.py	Tue Feb 17 14:28:14 2009 +0100
+++ b/common/view.py	Tue Feb 17 14:45:54 2009 +0100
@@ -69,6 +69,8 @@
 
 STRICT_DOCTYPE = u'<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd" %s>\n'
 
+# base view object ############################################################
+
 class View(AppRsetObject):
     """abstract view class, used as base for every renderable object such
     as views, templates, some components...web
@@ -466,3 +468,50 @@
         self._stream.doctype = self.doctype
         if not xmldecl:
             self._stream.xmldecl = u''
+
+# concrete component base classes #############################################
+
+class ReloadableMixIn(object):
+    """simple mixin for reloadable parts of UI"""
+    
+    def user_callback(self, cb, args, msg=None, nonify=False):
+        """register the given user callback and return an url to call it ready to be
+        inserted in html
+        """
+        self.req.add_js('cubicweb.ajax.js')
+        if nonify:
+            _cb = cb
+            def cb(*args):
+                _cb(*args)
+        cbname = self.req.register_onetime_callback(cb, *args)
+        return self.build_js(cbname, html_escape(msg or ''))
+        
+    def build_update_js_call(self, cbname, msg):
+        rql = html_escape(self.rset.printable_rql())
+        return "javascript:userCallbackThenUpdateUI('%s', '%s', '%s', '%s', '%s', '%s')" % (
+            cbname, self.id, rql, msg, self.__registry__, self.div_id())
+    
+    def build_reload_js_call(self, cbname, msg):
+        return "javascript:userCallbackThenReloadPage('%s', '%s')" % (cbname, msg)
+
+    build_js = build_update_js_call # expect updatable component by default
+    
+    def div_id(self):
+        return ''
+
+
+class Component(ReloadableMixIn, View):
+    """base class for components"""
+    __registry__ = 'components'
+    __registerer__ = yes_registerer
+    __selectors__ = (yes,)
+    property_defs = {
+        _('visible'):  dict(type='Boolean', default=True,
+                            help=_('display the box or not')),
+        }    
+
+    def div_class(self):
+        return '%s %s' % (self.propval('htmlclass'), self.id)
+
+    def div_id(self):
+        return '%sComponent' % self.id
--- a/sobjects/notification.py	Tue Feb 17 14:28:14 2009 +0100
+++ b/sobjects/notification.py	Tue Feb 17 14:45:54 2009 +0100
@@ -18,8 +18,7 @@
 from logilab.common.textutils import normalize_text
 
 from cubicweb import RegistryException
-from cubicweb.common.view import EntityView
-from cubicweb.common.appobject import Component
+from cubicweb.common.view import EntityView, Component
 from cubicweb.common.registerers import accepts_registerer
 from cubicweb.common.selectors import implements
 from cubicweb.common.mail import format_mail
--- a/sobjects/supervising.py	Tue Feb 17 14:28:14 2009 +0100
+++ b/sobjects/supervising.py	Tue Feb 17 14:45:54 2009 +0100
@@ -8,7 +8,7 @@
 __docformat__ = "restructuredtext en"
 
 from cubicweb import UnknownEid
-from cubicweb.common.appobject import ComponentMixIn
+from cubicweb.common.appobject import Component
 from cubicweb.common.view import StartupView
 from cubicweb.common.mail import format_mail
 from cubicweb.server.hooksmanager import Hook
@@ -138,9 +138,10 @@
             yield change
 
 
-class SupervisionEmailView(ComponentMixIn, StartupView):
+class SupervisionEmailView(Component):
     """view implementing the email API for data changes supervision notification
     """
+    __selectors__ = (none_rset,)
     id = 'supervision_notif'
 
     def recipients(self):
--- a/web/action.py	Tue Feb 17 14:28:14 2009 +0100
+++ b/web/action.py	Tue Feb 17 14:45:54 2009 +0100
@@ -6,8 +6,6 @@
 """
 __docformat__ = "restructuredtext en"
 
-from logilab.common.deprecation import class_moved
-
 from cubicweb import role, target
 from cubicweb.selectors import (relation_possible, match_search_state,
                                 one_line_rset, may_add_relation, yes,
--- a/web/application.py	Tue Feb 17 14:28:14 2009 +0100
+++ b/web/application.py	Tue Feb 17 14:45:54 2009 +0100
@@ -18,13 +18,13 @@
 from cubicweb.cwvreg import CubicWebRegistry
 from cubicweb.web import (LOGGER, StatusResponse, DirectResponse, Redirect, NotFound,
                        RemoteCallFailed, ExplicitLogin, InvalidSession)
-from cubicweb.web.component import SingletonComponent
+from cubicweb.web.component import Component
 
 # make session manager available through a global variable so the debug view can
 # print information about web session
 SESSION_MANAGER = None
 
-class AbstractSessionManager(SingletonComponent):
+class AbstractSessionManager(Component):
     """manage session data associated to a session identifier"""
     id = 'sessionmanager'
     
@@ -87,7 +87,7 @@
         raise NotImplementedError()
 
 
-class AbstractAuthenticationManager(SingletonComponent):
+class AbstractAuthenticationManager(Component):
     """authenticate user associated to a request and check session validity"""
     id = 'authmanager'
 
--- a/web/component.py	Tue Feb 17 14:28:14 2009 +0100
+++ b/web/component.py	Tue Feb 17 14:45:54 2009 +0100
@@ -6,10 +6,12 @@
 """
 __docformat__ = "restructuredtext en"
 
+from logilab.common.deprecation import class_moved
+
 from cubicweb.selectors import (
     paginated_rset, one_line_rset, primary_view, match_context_prop,
     condition_compat, accepts_compat, has_relation_compat)
-from cubicweb.common.appobject import Component, SingletonComponent, ComponentMixIn
+from cubicweb.common.appobject import Component
 from cubicweb.common.utils import merge_dicts
 from cubicweb.common.view import View
 from cubicweb.common.registerers import action_registerer
@@ -17,13 +19,7 @@
 
 _ = unicode
 
-class VComponent(ComponentMixIn, View):
-    property_defs = {
-        _('visible'):  dict(type='Boolean', default=True,
-                            help=_('display the box or not')),
-        }    
-
-class EntityVComponent(VComponent):
+class EntityVComponent(Component):
     """abstract base class for additinal components displayed in content
     headers and footer according to:
     
@@ -62,7 +58,7 @@
         raise NotImplementedError()
 
     
-class NavigationComponent(ComponentMixIn, View):
+class NavigationComponent(Component):
     """abstract base class for navigation components"""
     id = 'navigation'
     __selectors__ = (paginated_rset,)
@@ -175,3 +171,9 @@
         self.w(u'<div class="%s">' % self.div_class())
         self.wview(self.vid, rset, title=self.req._(self.title).capitalize())
         self.w(u'</div>')
+
+
+VComponent = class_moved('VComponent', VComponent,
+                         'VComponent is deprecated, use Component')
+SingletonVComponent = class_moved('SingletonVComponent', VComponent,
+                                  'SingletonVComponent is deprecated, use Component and explicit registration control')
--- a/web/views/apacherewrite.py	Tue Feb 17 14:28:14 2009 +0100
+++ b/web/views/apacherewrite.py	Tue Feb 17 14:45:54 2009 +0100
@@ -2,7 +2,7 @@
 are much more limited for the moment)
 
 :organization: Logilab
-:copyright: 2007-2008 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
+:copyright: 2007-2009 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
 :contact: http://www.logilab.fr/ -- mailto:contact@logilab.fr
 """
 
@@ -11,7 +11,7 @@
 from re import compile
 
 from cubicweb.web import Redirect
-from cubicweb.web.component import SingletonComponent
+from cubicweb.web.component import Component
 
 class RewriteCond(object):
     def __init__(self, condition, match='host', rules=(), action='rewrite'):
@@ -46,7 +46,7 @@
         return path
 
     
-class ApacheURLRewrite(SingletonComponent):
+class ApacheURLRewrite(Component):
     """inherit from this class with actual rules to activate apache style rewriting
 
     rules should have the form :
--- a/web/views/basecomponents.py	Tue Feb 17 14:28:14 2009 +0100
+++ b/web/views/basecomponents.py	Tue Feb 17 14:45:54 2009 +0100
@@ -20,13 +20,13 @@
                                     match_form_params)
 
 from cubicweb.web.htmlwidgets import MenuWidget, PopupBoxMenu, BoxSeparator, BoxLink
-from cubicweb.web.component import (VComponent, EntityVComponent, 
+from cubicweb.web.component import (Component, EntityVComponent, 
                                     RelatedObjectsVComponent)
 
 _ = unicode
 
 
-class RQLInputForm(VComponent):
+class RQLInputForm(Component):
     """build the rql input form, usually displayed in the header"""
     id = 'rqlinput'
     visible = False
@@ -55,7 +55,7 @@
         self.w(u'</form></div>')
 
 
-class ApplLogo(VComponent):
+class ApplLogo(Component):
     """build the application logo, usually displayed in the header"""
     id = 'logo'
     site_wide = True # don't want user to hide this component using an eproperty
@@ -64,7 +64,7 @@
                % (self.req.base_url(), self.req.external_resource('LOGO')))
 
 
-class ApplHelp(VComponent):
+class ApplHelp(Component):
     """build the help button, usually displayed in the header"""
     id = 'help'
     def call(self):
@@ -73,7 +73,7 @@
                   self.req._(u'help'),))
 
 
-class UserLink(VComponent):
+class UserLink(Component):
     """if the user is the anonymous user, build a link to login
     else a link to the connected user object with a loggout link
     """
@@ -114,7 +114,7 @@
                    % (self.build_url('login'), self.req._('login')))
 
 
-class ApplicationMessage(VComponent):
+class ApplicationMessage(Component):
     """display application's messages given using the __message parameter
     into a special div section
     """
@@ -169,7 +169,7 @@
                        displaycols=displaycols, headers=headers)
 
 
-class ApplicationName(VComponent):
+class ApplicationName(Component):
     """display the application name"""
     id = 'appliname'
 
@@ -190,7 +190,7 @@
     help = _('contentnavigation_seealso_description')
 
     
-class EtypeRestrictionComponent(VComponent):
+class EtypeRestrictionComponent(Component):
     """displays the list of entity types contained in the resultset
     to be able to filter accordingly.
     """
@@ -240,14 +240,14 @@
         
 
 
-class RSSFeedURL(VComponent):
+class RSSFeedURL(Component):
     id = 'rss_feed_url'
     __selectors__ = (non_final_entity(),)
     
     def feed_url(self):
         return self.build_url(rql=self.limited_rql(), vid='rss')
 
-class RSSEntityFeedURL(VComponent):
+class RSSEntityFeedURL(Component):
     id = 'rss_feed_url'
     __selectors__ = (non_final_entity(), one_line_rset)
     
--- a/web/views/magicsearch.py	Tue Feb 17 14:28:14 2009 +0100
+++ b/web/views/magicsearch.py	Tue Feb 17 14:45:54 2009 +0100
@@ -15,7 +15,7 @@
 from rql.nodes import Relation
 
 from cubicweb import Unauthorized
-from cubicweb.common.appobject import Component, SingletonComponent
+from cubicweb.common.appobject import Component
 
 LOGGER = getLogger('cubicweb.magicsearch')
 
@@ -349,7 +349,7 @@
 
 
 
-class MagicSearchComponent(SingletonComponent):
+class MagicSearchComponent(Component):
     id  = 'magicsearch'
     def __init__(self, req, rset=None):
         super(MagicSearchComponent, self).__init__(req, rset)
--- a/web/views/urlpublishing.py	Tue Feb 17 14:28:14 2009 +0100
+++ b/web/views/urlpublishing.py	Tue Feb 17 14:45:54 2009 +0100
@@ -18,7 +18,7 @@
 because of redirecting instead of direct traversal
 
 :organization: Logilab
-:copyright: 2001-2008 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
+:copyright: 2001-2009 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
 :contact: http://www.logilab.fr/ -- mailto:contact@logilab.fr
 """
 
@@ -28,7 +28,7 @@
 
 from cubicweb import RegistryException, typed_eid
 from cubicweb.web import NotFound, Redirect
-from cubicweb.web.component import SingletonComponent, Component
+from cubicweb.web.component import Component, Component
 
 
 class PathDontMatch(Exception):
@@ -36,7 +36,7 @@
     a path
     """
     
-class URLPublisherComponent(SingletonComponent):
+class URLPublisherComponent(Component):
     """associate url's path to view identifier / rql queries,
     by applying a chain of urlpathevaluator components.