Package Products :: Package ZenUtils :: Package extdirect :: Package zope :: Module metaconfigure |
[hide private]
[frames] | no frames]

# Source Code for Module Products.ZenUtils.extdirect.zope.metaconfigure

     1  ###########################################################################
     2  #
     3  # This program is part of Zenoss Core, an open source monitoring platform.
     4  # Copyright (C) 2009, Zenoss Inc.
     5  #
     6  # This program is free software; you can redistribute it and/or modify it
     7  # under the terms of the GNU General Public License version 2 as published by
     8  # the Free Software Foundation.
     9  #
    10  # For complete information please visit: http://www.zenoss.com/oss/
    11  #
    12  ###########################################################################
    13  import zope.component
    14  from zope.interface import Interface
    15  from zope.viewlet.metaconfigure import viewletDirective
    16  from zope.publisher.interfaces.browser import IBrowserView
    17  from zope.publisher.interfaces.browser import IDefaultBrowserLayer
    18  from zope.viewlet.viewlet import ViewletBase
    19  try:
    20      from Products.Five.browser.metaconfigure import page
    21  except ImportError:
    22      from zope.app.publisher.browser.viewmeta import page
    23
    24  from Products.ZenUtils.extdirect.router import DirectProviderDefinition
    25
    26  from interfaces import IExtDirectJavaScriptManager
    27
    28 -class SourceViewletBase(ViewletBase):
    29      _source = ""
    30      weight=0
    31 -    def render(self):
    32          return self._source
    33
    34 -def JavaScriptSourceViewlet(source):
    35      klass = type('JavaScriptSourceViewlet',
    36                   (SourceViewletBase,),
    37                   {'_source':source,
    38                    'weight':2})
    39      return klass
    40
    41
    42 -def directRouter(_context, name, class_, namespace=None, for_=Interface,
    43                   layer=IDefaultBrowserLayer, timeout="30000",
    44                   permission='zenoss.Common'):
    45
    46      # Register the view at which the class will be available
    47      page(_context, name, permission, for_, layer, class_=class_)
    48
    49      # Make a viewlet class with the appropriate javascript source
    50      source = DirectProviderDefinition(class_, name, timeout, namespace).render()
    51      viewletclass = JavaScriptSourceViewlet(source)
    52
    53      viewletDirective(_context, name, 'zope2.Public', for_, layer,
    54                       manager=IExtDirectJavaScriptManager, class_=viewletclass)
    55