source: main/waeup.ikoba/trunk/src/waeup/ikoba/browser/interfaces.py @ 12774

Last change on this file since 12774 was 12630, checked in by Henrik Bettermann, 10 years ago

Fix test.

Email addresses are now TextLines?.

  • Property svn:keywords set to Id
File size: 6.2 KB
Line 
1## $Id: interfaces.py 12630 2015-02-24 06:01:08Z henrik $
2##
3## Copyright (C) 2011 Uli Fouquet & Henrik Bettermann
4## This program is free software; you can redistribute it and/or modify
5## it under the terms of the GNU General Public License as published by
6## the Free Software Foundation; either version 2 of the License, or
7## (at your option) any later version.
8##
9## This program is distributed in the hope that it will be useful,
10## but WITHOUT ANY WARRANTY; without even the implied warranty of
11## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12## GNU General Public License for more details.
13##
14## You should have received a copy of the GNU General Public License
15## along with this program; if not, write to the Free Software
16## Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17##
18"""Interfaces for viewing components.
19"""
20from zope import schema
21from zope.interface import Interface, Attribute
22from waeup.ikoba.interfaces import (
23    IIkobaObject, ICompany, IUsersContainer, IDataCenter, validate_email)
24from waeup.ikoba.interfaces import MessageFactory as _
25
26class IBreadcrumb(Interface):
27    """Provide breadcrumbs.
28    """
29    title = Attribute("Context description")
30    viewname = Attribute("The viewname, for which the breadcrumb is provided.")
31    parent_viewname = Attribute("The viewname of the parent to use.")
32    parent = Attribute("The parent object.")
33    context = Attribute("The context of the breadcrumb.")
34    target = Attribute("The link target.")
35
36class IBreadcrumbIgnorable(Interface):
37    """A marker interface for breadcrumbs that should be skipped in output.
38
39    If a breadcrumb wants to be skipped in real output (for instance,
40    because it is set on a layer in site hierarchy that should not be
41    accessed by users), it can also provide this interface. The
42    getBreadcrumbList() function defined here will exclude IIgnorables
43    by default.
44    """
45    pass
46
47class IBreadcrumbContainer(Interface):
48    """A container of breadcrumbs.
49    """
50    def __iter__():
51        """Allow iteration over the container.
52        """
53
54    def getList():
55        """Get the list of breadcrumbs as real Python list.
56        """
57class ICaptchaRequest(Interface):
58    """A set of data required to verify captcha solutions.
59
60    To solve a captcha we need at least a solution. Many types of
61    captchas might also need a challenge to compare whether the
62    solution is correct.
63    """
64    solution = schema.TextLine(
65        title = u'Solution string a user entered',
66        default = None,
67        )
68    challenge = schema.TextLine(
69        title = u'The challenge the solution might match',
70        default = None,
71        )
72
73class ICaptchaResponse(Interface):
74    """A formalized response for captcha solutions.
75    """
76    is_valid = schema.Bool(
77        title = u'Indicates validity of entered captcha data.',
78        default = False,
79        )
80    error_code = schema.TextLine(
81        title = u'Error when trying to validate entered captcha data.',
82        description = u'Error codes are not expected to be readable strings.',
83        default = None,
84        )
85
86class ICaptcha(Interface):
87
88    def verify(request):
89        """Verify data entered in an HTTP request.
90
91        Expects some IHTTPRequest object and returns an
92        ICaptchaResponse indicating that the solution was correct or
93        not.
94
95        If the solution could not be verified (this might also happen
96        because of technical reasons), the response might contain an
97        error code.
98        """
99
100    def display(error_code=None):
101        """Returns a piece of HTML code that displays the captcha.
102
103        The generated HTML code might depend on any previous error
104        code as returned from :meth:`verify`.
105
106        The code is expected to appear inside a ``<form>``. It
107        therefore should not contain a ``<form>`` nor any submit
108        buttons.
109        """
110
111class ICaptchaConfig(Interface):
112    """Any type of captcha might need some configuration data.
113
114    By default we require no configuration data.
115    """
116
117class ICaptchaManager(Interface):
118    """A chooser that collects available captchas.
119    """
120    def getAvailCaptchas():
121        """Return a dict of available captchas with registered names as keys.
122        """
123
124    def getCaptcha():
125        """Get captcha chosen for a certain site or default.
126        """
127
128class IPDFCreator(Interface):
129    """A component that knows where logo graphics for PDFs are stored
130    and can generate PDF documents.
131
132    It is a utility (and not a simple function or class) to make these
133    data customizable in derived packages.
134    """
135    header_logo_path = schema.TextLine(
136        title = u'Path to header logo JPG')
137    watermark_path = schema.TextLine(
138        title = u'Path to watermark logo JPG')
139    def paint_background(canvas, doc):
140        """A callback function to render background of PDFs.
141        """
142    def create_pdf(data, headerline=None, title=None, author=None,
143                   footer='', note=None, sigs_in_footer=[]):
144        """Create a PDF.
145
146        `data` is expected to be a list of reportlab flowables
147        (paragraphs, images, tables, etc.), that will be rendered into
148        some background.
149
150        `headerline` will be displayed in page head and `title` under
151        the top bar.
152
153        `note` is optional HTML markup added at bottom of created
154        document.
155
156        `footer` is the text rendered in the bottom line next to the
157        page numbers.
158
159        `sigs_in_footer` is a set of translateable strings that will be
160        rendered into signature boxes at bottom of each page.
161
162        If no `headerline` is given, a default will be rendered (name
163        of company).
164
165        If no `title` is given, nothing will be rendered.
166        """
167
168class IChangePassword(IIkobaObject):
169    """Interface needed for change pasword page.
170
171    """
172    email = schema.TextLine(
173        title = _(u'Email Address'),
174        required = True,
175        constraint=validate_email,
176        description = _('Enter your email address stored in Ikoba.')
177        )
178
179class ICustomerNavigationBase(IIkobaObject):
180    """Objects that provide customer navigation should
181       implement this interface.
182    """
183    customer = Attribute('''Some customer object that has a '''
184                        ''' `display_fullname` attribute.''')
Note: See TracBrowser for help on using the repository browser.