|
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 zope.annotation.interfaces import IAttributeAnnotatable |
|
20 from zope.container.interfaces import IContainer |
|
21 |
|
22 # import packages |
|
23 from pyams_i18n.schema import I18nTextLineField, I18nTextField |
|
24 from pyams_sequence.schema import InternalReference |
|
25 from pyams_utils.schema import PersistentList |
|
26 from zope.container.constraints import containers, contains |
|
27 from zope.interface import Interface, Attribute |
|
28 from zope.schema import Choice, TextLine |
|
29 |
|
30 from pyams_content import _ |
|
31 |
|
32 |
|
33 LINK_CONTAINER_KEY = 'pyams_content.link' |
|
34 LINK_LINKS_CONTAINER_KEY = 'pyams_content.link.links' |
|
35 |
|
36 |
|
37 class IBaseLink(IAttributeAnnotatable): |
|
38 """Base link interface""" |
|
39 |
|
40 containers('.ILinkContainer') |
|
41 |
|
42 title = I18nTextLineField(title=_("Title"), |
|
43 description=_("Link title, as shown in front-office"), |
|
44 required=True) |
|
45 |
|
46 description = I18nTextField(title=_("Description"), |
|
47 description=_("Link description displayed by front-office template"), |
|
48 required=False) |
|
49 |
|
50 def get_editor_url(self): |
|
51 """Get URL for use in HTML editor""" |
|
52 |
|
53 def get_url(self, request, view_name=None): |
|
54 """Get link URL""" |
|
55 |
|
56 |
|
57 class IInternalLink(IBaseLink): |
|
58 """Internal link interface""" |
|
59 |
|
60 reference = InternalReference(title=_("Internal reference"), |
|
61 description=_("Internal link target reference. You can search a reference using " |
|
62 "'+' followed by internal number, of by entering text matching " |
|
63 "content title."), |
|
64 required=True) |
|
65 |
|
66 def get_target(self, state=None): |
|
67 """Get reference target""" |
|
68 |
|
69 |
|
70 class IExternalLink(IBaseLink): |
|
71 """External link interface""" |
|
72 |
|
73 url = TextLine(title=_("Target URL"), |
|
74 description=_("URL used to access external resource"), |
|
75 required=True) |
|
76 |
|
77 language = Choice(title=_("Language"), |
|
78 description=_("Language used in this remote resource"), |
|
79 vocabulary='PyAMS base languages', |
|
80 required=False) |
|
81 |
|
82 |
|
83 class ILinkContainer(IContainer): |
|
84 """Links container""" |
|
85 |
|
86 contains(IBaseLink) |
|
87 |
|
88 |
|
89 class ILinkContainerTarget(Interface): |
|
90 """Links container marker interface""" |
|
91 |
|
92 |
|
93 class ILinkLinksContainer(Interface): |
|
94 """Links links container interface""" |
|
95 |
|
96 links = PersistentList(title=_("Contained links"), |
|
97 description=_("List of internal or external links linked to this object"), |
|
98 value_type=Choice(vocabulary="PyAMS content links"), |
|
99 required=False) |
|
100 |
|
101 |
|
102 class ILinkLinksContainerTarget(Interface): |
|
103 """Links links container marker interface""" |