~ubuntu-branches/ubuntu/trusty/zope.app.form/trusty

« back to all changes in this revision

Viewing changes to src/zope/app/form/browser/macros.py

  • Committer: Bazaar Package Importer
  • Author(s): Gediminas Paulauskas
  • Date: 2010-12-02 01:37:03 UTC
  • Revision ID: james.westby@ubuntu.com-20101202013703-fvbpiae1ok9v73we
Tags: upstream-4.0.2
ImportĀ upstreamĀ versionĀ 4.0.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
##############################################################################
 
2
#
 
3
# Copyright (c) 2003 Zope Corporation and Contributors.
 
4
# All Rights Reserved.
 
5
#
 
6
# This software is subject to the provisions of the Zope Public License,
 
7
# Version 2.1 (ZPL).  A copy of the ZPL should accompany this distribution.
 
8
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
 
9
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
 
10
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
 
11
# FOR A PARTICULAR PURPOSE.
 
12
#
 
13
##############################################################################
 
14
"""API Documentation macros
 
15
 
 
16
$Id: macros.py 106723 2009-12-17 23:16:34Z hannosch $
 
17
"""
 
18
__docformat__ = 'restructuredtext'
 
19
 
 
20
from zope.component import getMultiAdapter
 
21
from zope.interface import implements
 
22
from zope.interface.common.mapping import IItemMapping
 
23
from zope.publisher.browser import BrowserView
 
24
 
 
25
class FormMacros(BrowserView):
 
26
    implements(IItemMapping)
 
27
 
 
28
    macro_pages = (
 
29
        'view_macros',
 
30
        'widget_macros',
 
31
        'addform_macros',
 
32
        )
 
33
    aliases = {
 
34
        'view': 'page',
 
35
        'dialog': 'page',
 
36
        'addingdialog': 'page',
 
37
        }
 
38
 
 
39
    def __getitem__(self, key):
 
40
        key = self.aliases.get(key, key)
 
41
        context = self.context
 
42
        request = self.request
 
43
        for name in self.macro_pages:
 
44
            page = getMultiAdapter((context, request), name=name)
 
45
            try:
 
46
                v = page[key]
 
47
            except KeyError:
 
48
                pass
 
49
            else:
 
50
                return v
 
51
        raise KeyError(key)