diff options
| author | Chris McDonough <chrism@agendaless.com> | 2008-07-12 10:46:04 +0000 |
|---|---|---|
| committer | Chris McDonough <chrism@agendaless.com> | 2008-07-12 10:46:04 +0000 |
| commit | 69dfd4ba10c01181ae006266efce5d6057091b72 (patch) | |
| tree | 1066c244dfc531f60e100e0eaa938feec90cd006 /repoze/bfg/metaconfigure.py | |
| parent | 8823e22b7caf3ef72aefaccec9e33f21bb37018c (diff) | |
| download | pyramid-69dfd4ba10c01181ae006266efce5d6057091b72.tar.gz pyramid-69dfd4ba10c01181ae006266efce5d6057091b72.tar.bz2 pyramid-69dfd4ba10c01181ae006266efce5d6057091b72.zip | |
metaconfigure.py -> zcml.py
Diffstat (limited to 'repoze/bfg/metaconfigure.py')
| -rw-r--r-- | repoze/bfg/metaconfigure.py | 116 |
1 files changed, 0 insertions, 116 deletions
diff --git a/repoze/bfg/metaconfigure.py b/repoze/bfg/metaconfigure.py deleted file mode 100644 index bc136055a..000000000 --- a/repoze/bfg/metaconfigure.py +++ /dev/null @@ -1,116 +0,0 @@ -import os - -from zope.schema import TextLine -from zope.configuration.fields import Path -from zope.interface import Interface -from zope.component.zcml import handler -from zope.component.interface import provideInterface -from zope.configuration.exceptions import ConfigurationError -from zope.configuration.fields import GlobalObject -from zope.security.zcml import Permission - -from repoze.bfg.interfaces import IRequest -from repoze.bfg.interfaces import IViewFactory - -from repoze.bfg.template import ViewPageTemplateFile -from repoze.bfg.template import PageTemplateFile - -class ViewBase: - def __init__(self, context, request): - self.context = context - self.request = request - - def __call__(self, *arg, **kw): - return self.index(*arg, **kw) - -def page(_context, - permission, - for_, - name="", - template=None, - class_=None, - ): - - # XXX we do nothing yet with permission - - if not (class_ or template): - raise ConfigurationError("Must specify a class or a template") - - if template: - template = os.path.abspath(str(_context.path(template))) - if not os.path.isfile(template): - raise ConfigurationError("No such file", template) - - template_inst = PageTemplateFile(template) - - def view_factory(context, request): - if template: - if class_ is None: - base = ViewBase - else: - base = class_ - class ViewClass(base): - __name__ = name - index = ViewPageTemplateFile(template_inst) - return ViewClass(context, request) - - else: - return class_(context, request) - - if for_ is not None: - _context.action( - discriminator = None, - callable = provideInterface, - args = ('', for_) - ) - - _context.action( - discriminator = ('view', for_, name, IRequest, IViewFactory), - callable = handler, - args = ('registerAdapter', - view_factory, (for_, IRequest), IViewFactory, name, - _context.info), - ) - -class IPageDirective(Interface): - """ - The page directive is used to create views that provide a single - url or page. - - The page directive creates a new view class from a given template - and/or class and registers it. - """ - - for_ = GlobalObject( - title=u"The interface or class this view is for.", - required=False - ) - - permission = Permission( - title=u"Permission", - description=u"The permission needed to use the view.", - required=True - ) - - class_ = GlobalObject( - title=u"Class", - description=u"A class that provides a __call__ used by the view.", - required=False, - ) - - name = TextLine( - title=u"The name of the page (view)", - description=u""" - The name shows up in URLs/paths. For example 'foo' or - 'foo.html'.""", - required=False, - ) - - template = Path( - title=u"The name of a template that implements the page.", - description=u""" - Refers to a file containing a page template (should end in - extension '.pt' or '.html').""", - required=False - ) - |
