Changeset f9798f in indico


Ignore:
Timestamp:
04/27/12 15:39:28 (13 months ago)
Author:
Jose Benito <jose.benito.gonzalez@…>
Branches:
master, hello-world-walkthrough, ipv6, v0.98-series, v0.98.2, v0.98.3, v0.99, 051b2622c51afb171a1dedb46a0df4fbb0cbd02e, d9941f8582b36b24821a11ea5ba16fda6a457fb1
Children:
c06c72
Parents:
d71fd2
git-author:
Matthew Pugh <matthew.alexander.pugh@…> (04/27/12 14:48:06)
git-committer:
Jose Benito <jose.benito.gonzalez@…> (04/27/12 15:39:28)
Message:

[FIX] Disable Stats when plugin disabled.

  • Stats Register is now aware if any or no plugins are active.
  • Only contributes to SideMenu? when active implementations.
  • No code injection on disactive plugins.
Location:
indico/ext/statistics
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • indico/ext/statistics/chrome.py

    rbe54ff6 rf9798f  
    4646    def fillManagementSideMenu(cls, obj, params={}): 
    4747        if obj._conf.canModify(obj._rh._aw): 
    48             params['Statistics'] = wcomponents.SideMenuItem(_('Statistics'), 
    49                 UHConfModifStatistics.getURL(obj._conf)) 
     48 
     49            if StatisticsRegister().hasActivePlugins(): 
     50                params['Statistics'] = wcomponents.SideMenuItem(_('Statistics'), 
     51                    UHConfModifStatistics.getURL(obj._conf)) 
    5052 
    5153 
     
    6062        """ 
    6163        stats = PluginsHolder().getPluginType('statistics') 
    62  
    63         if not stats.isActive(): 
     64        register = StatisticsRegister() 
     65 
     66        if not stats.isActive() or not register.hasActivePlugins(): 
    6467            return False 
    6568 
    66         register = StatisticsRegister() 
    6769        key = 'extraFooterContent' 
    6870        extension = {} 
     
    174176        self._conf = self._rh._conf 
    175177        self._register = StatisticsRegister() 
    176         self._plugins = self._register.getAllPlugins() 
     178        self._plugins = self._register.getAllPlugins(activeOnly=True) 
    177179        self._templateClass = templateClass 
    178180        self._extraJS = [] 
  • indico/ext/statistics/register.py

    rd22bcc rf9798f  
    6363        self._buildRegister() 
    6464 
    65     def getAllPlugins(self, instantiate=True): 
     65 
     66    def hasActivePlugins(self): 
     67        """ 
     68        Returns True only if any implementations are active in the PluginsHolder 
     69        """ 
     70 
     71        activePlugins = list(p for p in self.getAllPlugins(True) if p.isActive()) 
     72 
     73        # The resultant activePlugins is only True if there are any plugins. 
     74        return bool(activePlugins) 
     75 
     76    def getAllPlugins(self, instantiate=True, activeOnly=False): 
    6677        """ 
    6778        Returns a list of all plugin class registered, if instantiate is 
    68         True, instates all objects before appending to the list. 
     79        True, instates all objects before appending to the list. By default 
     80        this method only returns active implementations, however all implementations 
     81        may be returned by setting activeOnly to True. 
    6982        """ 
    7083        result = [] 
     
    7285        if instantiate: 
    7386            for plugin in self._getRegister().values(): 
     87 
     88                if activeOnly and not plugin().isActive(): 
     89                    continue 
     90 
    7491                result.append(plugin()) 
    7592        else: 
    76             result = self._getRegister().values() 
     93            if activeOnly: 
     94                result = list(p for p in self._getRegister().values() if p().isActive()) 
     95            else: 
     96                result = self._getRegister().values() 
    7797 
    7898        return result 
     
    84104        return self._getRegister().keys() 
    85105 
    86     def getAllPluginJSHooks(self, extra=None): 
     106    def getAllPluginJSHooks(self, extra=None, includeInactive=False): 
    87107        """ 
    88108        Returns a list of JSHook objects which contain the parameters 
     
    94114 
    95115        for plugin in self.getAllPlugins(True): 
     116 
     117            if not includeInactive and not plugin.isActive(): 
     118                continue 
    96119 
    97120            if extra is not None: 
Note: See TracChangeset for help on using the changeset viewer.