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  # Copyright (C) Zenoss, Inc. 2009, all rights reserved.
     4  #
     5  # This content is made available according to terms specified in
     6  # License.zenoss under the directory where your Zenoss product is installed.
     7  #
     8  ##############################################################################
     9
    10
    11  import zope.component
    12  from zope.interface import Interface
    13  from zope.viewlet.metaconfigure import viewletDirective
    14  from zope.publisher.interfaces.browser import IBrowserView
    15  from zope.publisher.interfaces.browser import IDefaultBrowserLayer
    16  from zope.viewlet.viewlet import ViewletBase
    17  try:
    18      from Products.Five.browser.metaconfigure import page
    19  except ImportError:
    20      from zope.publisher.browser.viewmeta import page
    21
    22  from Products.ZenUtils.extdirect.router import DirectProviderDefinition
    23
    24  from interfaces import IExtDirectJavaScriptManager, IJsonApiJavaScriptManager
    25
    26 -class SourceViewletBase(ViewletBase):
    27      _source = ""
    28      weight=0
    29 -    def render(self):
    30          return self._source
    31
    32 -def JavaScriptSourceViewlet(source):
    33      klass = type('JavaScriptSourceViewlet',
    34                   (SourceViewletBase,),
    35                   {'_source':source,
    36                    'weight':2})
    37      return klass
    38
    39
    40 -def directRouter(_context, name, class_, namespace=None, for_=Interface,
    41                   layer=IDefaultBrowserLayer, timeout="180000",
    42                   permission='zenoss.Common'):
    43
    44      # Register the view at which the class will be available
    45      page(_context, name, permission, for_, layer, class_=class_)
    46
    47      # Make a viewlet class with the appropriate javascript source
    48      definition = DirectProviderDefinition(class_, name, timeout, namespace)
    49
    50      source = definition.render()
    51      viewletclass = JavaScriptSourceViewlet(source)
    52      viewletDirective(_context, name, 'zope2.Public', for_, layer, manager=IExtDirectJavaScriptManager, class_=viewletclass)
    53
    54      jsonapi_source = definition.render_jsonapi()
    55      jsonapi_viewletclass = JavaScriptSourceViewlet(jsonapi_source)
    56      viewletDirective(_context, name, 'zope2.Public', for_, layer, manager=IJsonApiJavaScriptManager, class_=jsonapi_viewletclass)
    57