|
1 # |
|
2 # Copyright (c) 2008-2015 Thierry Florac <tflorac AT ulthar.net> |
|
3 # All Rights Reserved. |
|
4 # |
|
5 # This software is subject to the provisions of the Zope Public License, |
|
6 # Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution. |
|
7 # THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED |
|
8 # WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
|
9 # WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS |
|
10 # FOR A PARTICULAR PURPOSE. |
|
11 # |
|
12 |
|
13 __docformat__ = 'restructuredtext' |
|
14 |
|
15 |
|
16 # import standard library |
|
17 |
|
18 # import interfaces |
|
19 from pyams_viewlet.interfaces import IViewletManager |
|
20 |
|
21 # import packages |
|
22 from zope.configuration.fields import GlobalInterface, GlobalObject |
|
23 from zope.interface import Interface |
|
24 from zope.schema import TextLine |
|
25 |
|
26 |
|
27 class IContentProvider(Interface): |
|
28 """A directive to register a simple content provider. |
|
29 |
|
30 Content providers are registered by their context (`for` attribute), the |
|
31 request (`layer` attribute) and the view (`view` attribute). They also |
|
32 must provide a name, so that they can be found using the TALES |
|
33 ``provider`` namespace. Other than that, content providers are just like |
|
34 any other views. |
|
35 """ |
|
36 |
|
37 view = GlobalObject(title="The view the content provider is registered for", |
|
38 description="The view can either be an interface or a class. By " |
|
39 "default the provider is registered for all views, " |
|
40 "the most common case.", |
|
41 required=False, |
|
42 default=Interface) |
|
43 |
|
44 name = TextLine(title="The name of the content provider", |
|
45 description="The name of the content provider is used in the TALES " |
|
46 "``provider`` namespace to look up the content " |
|
47 "provider.", |
|
48 required=True) |
|
49 |
|
50 for_ = GlobalObject(title="The interface or class this view is for", |
|
51 required=False) |
|
52 |
|
53 permission = TextLine(title="Permission", |
|
54 description="The permission needed to use the view", |
|
55 required=False) |
|
56 |
|
57 class_ = GlobalObject(title="Class", |
|
58 description="A class that provides attributes used by the view", |
|
59 required=False) |
|
60 |
|
61 layer = GlobalInterface(title="The layer the view is in", |
|
62 description="""A skin is composed of layers. It is common to put skin |
|
63 specific views in a layer named after the skin. If the 'layer' |
|
64 attribute is not supplied, it defaults to 'default'.""", |
|
65 required=False) |
|
66 |
|
67 |
|
68 class IViewletManagerDirective(IContentProvider): |
|
69 """A directive to register a new viewlet manager. |
|
70 |
|
71 Viewlet manager registrations are very similar to content provider |
|
72 registrations, since they are just a simple extension of content |
|
73 providers. However, viewlet managers commonly have a specific provided |
|
74 interface, which is used to discriminate the viewlets they are providing. |
|
75 """ |
|
76 |
|
77 provides = GlobalInterface(title="The interface this viewlet manager provides", |
|
78 description="A viewlet manager can provide an interface, which " |
|
79 "is used to lookup its contained viewlets.", |
|
80 required=False, |
|
81 default=IViewletManager) |
|
82 |
|
83 |
|
84 class IViewletDirective(IContentProvider): |
|
85 """A directive to register a new viewlet. |
|
86 |
|
87 Viewlets are content providers that can only be displayed inside a viewlet |
|
88 manager. Thus they are additionally discriminated by the manager. Viewlets |
|
89 can rely on the specified viewlet manager interface to provide their |
|
90 content. |
|
91 |
|
92 The viewlet directive also supports an undefined set of keyword arguments |
|
93 that are set as attributes on the viewlet after creation. Those attributes |
|
94 can then be used to implement sorting and filtering, for example. |
|
95 """ |
|
96 |
|
97 manager = GlobalObject(title="Manager", |
|
98 description="The interface or class of the viewlet manager", |
|
99 required=False, |
|
100 default=IViewletManager) |
|
101 |
|
102 |
|
103 # Arbitrary keys and values are allowed to be passed to the viewlet. |
|
104 IViewletDirective.setTaggedValue('keyword_arguments', True) |