merge
authorAdrien Di Mascio <Adrien.DiMascio@logilab.fr>
Tue, 04 Aug 2009 18:58:54 +0200
changeset 2690 38a4e83c8160
parent 2689 44f041222d0f (diff)
parent 2687 6220500bada7 (current diff)
child 2691 ade319674170
merge
--- a/__init__.py	Tue Aug 04 18:47:11 2009 +0200
+++ b/__init__.py	Tue Aug 04 18:58:54 2009 +0200
@@ -348,3 +348,18 @@
                 callback(context, *args, **kwargs)
 
 CW_EVENT_MANAGER = CubicWebEventManager()
+
+def onevent(event):
+    """decorator to ease event / callback binding
+
+    >>> from cubicweb import onevent
+    >>> @onevent('before-source-reload')
+    ... def mycallback():
+    ...     print 'hello'
+    ...
+    >>>
+    """
+    def _decorator(func):
+        CW_EVENT_MANAGER.bind(event, func)
+        return func
+    return _decorator
--- a/rtags.py	Tue Aug 04 18:47:11 2009 +0200
+++ b/rtags.py	Tue Aug 04 18:58:54 2009 +0200
@@ -41,6 +41,9 @@
         return self.get(*key)
     __contains__ = __getitem__
 
+    def clear(self):
+        self._tagdefs.clear()
+
     def _get_keys(self, stype, rtype, otype, tagged):
         keys = [(rtype, tagged, '*', '*'),
                 (rtype, tagged, '*', otype),
--- a/vregistry.py	Tue Aug 04 18:47:11 2009 +0200
+++ b/vregistry.py	Tue Aug 04 18:58:54 2009 +0200
@@ -35,13 +35,6 @@
                       RegistryOutOfDate)
 from cubicweb.appobject import AppObject
 
-# XXX depending on cubicweb.web is ugly, we should deal with uicfg
-#     reset with a good old event / callback system
-try:
-    from cubicweb.web import uicfg
-except ImportError: # cubicweb.web not installed
-    uicfg = None
-
 def _toload_info(path, extrapath, _toload=None):
     """return a dictionary of <modname>: <modpath> and an ordered list of
     (file, module name) to load
@@ -216,12 +209,6 @@
     def reset(self, force_reload=None):
         self.clear()
         self._lastmodifs = {}
-        # don't reload uicfg when appobjects modules won't be reloaded as well
-        if uicfg is not None:
-            if force_reload is None:
-                force_reload = self.config.mode == 'dev'
-            if force_reload:
-                reload(uicfg)
 
     def __getitem__(self, name):
         """return the registry (dictionary of class objects) associated to
--- a/web/uicfg.py	Tue Aug 04 18:47:11 2009 +0200
+++ b/web/uicfg.py	Tue Aug 04 18:58:54 2009 +0200
@@ -67,7 +67,7 @@
 """
 __docformat__ = "restructuredtext en"
 
-from cubicweb import neg_role
+from cubicweb import neg_role, onevent
 from cubicweb.rtags import (RelationTags, RelationTagsBool,
                             RelationTagsSet, RelationTagsDict)
 from cubicweb.web import formwidgets
@@ -144,7 +144,6 @@
 primaryview_display_ctrl = DisplayCtrlRelationTags('primaryview_display_ctrl',
                                                    init_primaryview_display_ctrl)
 
-
 # index view configuration ####################################################
 # entity type section in the index/manage page. May be one of
 # * 'application'
@@ -205,7 +204,6 @@
 # permissions checking is by-passed and supposed to be ok
 autoform_permissions_overrides = RelationTagsSet('autoform_permissions_overrides')
 
-
 # boxes.EditBox configuration #################################################
 
 # 'link' / 'create' relation tags, used to control the "add entity" submenu
@@ -219,3 +217,14 @@
 actionbox_appearsin_addmenu = RelationTagsBool('actionbox_appearsin_addmenu',
                                                init_actionbox_appearsin_addmenu)
 
+@onevent('before-source-reload')
+def clear_rtag_objects():
+    print 'YAHOO ' * 80
+    primaryview_section.clear()
+    primaryview_display_ctrl.clear()
+    autoform_section.clear()
+    autoform_field.clear()
+    autoform_field_kwargs.clear()
+    autoform_is_inlined.clear()
+    autoform_permissions_overrides.clear()
+    actionbox_appearsin_addmenu.clear()