source: main/waeup.sirp/trunk/src/waeup/sirp/interfaces.py @ 6141

Last change on this file since 6141 was 6141, checked in by uli, 13 years ago

Add interface for adapters that can tell about what roles are
assignable for some context object.

  • Property svn:eol-style set to native
File size: 9.5 KB
Line 
1##
2## interfaces.py
3from zc.sourcefactory.basic import BasicSourceFactory
4from zope.component import getUtility
5from zope.component.interfaces import IObjectEvent
6try:
7    from zope.catalog.interfaces import ICatalog
8except ImportError:
9    # BBB
10    from zope.app.catalog.interfaces import ICatalog
11from zope.interface import Interface, Attribute, implements
12from zope import schema
13from zope.schema.vocabulary import SimpleVocabulary, SimpleTerm
14from waeup.sirp.permissions import RoleSource
15
16
17class FatalCSVError(Exception):
18    """Some row could not be processed.
19    """
20    pass
21
22def SimpleWAeUPVocabulary(*terms):
23    """A well-buildt vocabulary provides terms with a value, token and
24       title for each term
25    """
26    return SimpleVocabulary([
27            SimpleTerm(value, value, title) for title, value in terms])
28
29class IWAeUPObject(Interface):
30    """A WAeUP object.
31
32    This is merely a marker interface.
33    """
34
35class IUniversity(IWAeUPObject):
36    """Representation of a university.
37    """
38    name = schema.TextLine(
39        title = u'Name of University',
40        default = u'Unnamed',
41        required = True,
42        )
43
44    title = schema.TextLine(
45        title = u'Title of frontpage',
46        default = u'No Title',
47        required = False,
48        )
49
50    skin = schema.Choice(
51        title = u'Skin',
52        default = u'waeuptheme-gray1.css',
53        vocabulary = 'waeup.sirp.browser.theming.ThemesVocabulary',
54        required = True,
55        )
56
57    frontpage = schema.Text(
58        title = u'Content in reST format',
59        required = False,
60        default = u'This is the SIRP frontpage.'
61        )
62
63    faculties = Attribute("A container for faculties.")
64    students = Attribute("A container for students.")
65    hostels = Attribute("A container for hostels.")
66
67class IWAeUPContainer(IWAeUPObject):
68    """A container for WAeUP objects.
69    """
70
71class IWAeUPContained(IWAeUPObject):
72    """An item contained in an IWAeUPContainer.
73    """
74
75class IStudentContainer(IWAeUPContainer):
76    """A container for StudentObjects.
77    """
78
79
80class IHostelContainer(IWAeUPContainer):
81    """A container for hostels.
82    """
83    def addHostel(hostel):
84        """Add an IHostel object.
85
86        Returns the key, under which the object was stored.
87        """
88
89class IHostel(IWAeUPObject):
90    """Representation of a hostel.
91    """
92    name = schema.TextLine(
93        title = u'Name of Hostel',
94        default = u'Nobody',
95        required = True,
96        )
97
98
99class IWAeUPExporter(Interface):
100    """An exporter for objects.
101    """
102    def export(obj, filepath=None):
103        """Export by pickling.
104
105        Returns a file-like object containing a representation of `obj`.
106
107        This is done using `pickle`. If `filepath` is ``None``, a
108        `cStringIO` object is returned, that contains the saved data.
109        """
110
111class IWAeUPXMLExporter(Interface):
112    """An XML exporter for objects.
113    """
114    def export(obj, filepath=None):
115        """Export as XML.
116
117        Returns an XML representation of `obj`.
118
119        If `filepath` is ``None``, a StringIO` object is returned,
120        that contains the transformed data.
121        """
122
123class IWAeUPXMLImporter(Interface):
124    """An XML import for objects.
125    """
126    def doImport(filepath):
127        """Create Python object from XML.
128
129        Returns a Python object.
130        """
131
132class IBatchProcessor(Interface):
133    """A batch processor that handles mass-operations.
134    """
135    name = schema.TextLine(
136        title = u'Importer name'
137        )
138
139    mode = schema.Choice(
140        title = u'Import mode',
141        values = ['create', 'update', 'remove']
142        )
143
144    def doImport(path, headerfields, mode='create', user='Unknown',
145                 logger=None):
146        """Read data from ``path`` and update connected object.
147
148        `headerfields` is a list of headerfields as read from the file
149        to import.
150
151        `mode` gives the import mode to use (``'create'``,
152        ``'update'``, or ``'remove'``.
153
154        `user` is a string describing the user performing the
155        import. Normally fetched from current principal.
156
157        `logger` is the logger to use during import.
158        """
159
160class ISchemaTypeConverter(Interface):
161    """A converter for zope.schema.types.
162    """
163    def convert(string):
164        """Convert string to certain schema type.
165        """
166
167
168class IUserAccount(IWAeUPObject):
169    """A user account.
170    """
171    name = schema.TextLine(
172        title = u'User ID',
173        description = u'Loginname',
174        required = True,)
175    title = schema.TextLine(
176        title = u'Username',
177        description = u'Real name',
178        required = False,)
179    description = schema.TextLine(
180        title = u'User description',
181        required = False,)
182    password = schema.Password(
183        title = u'Password',
184        required = True,)
185    roles = schema.List(
186        title = u'Roles',
187        value_type = schema.Choice(source=RoleSource()))
188
189
190class IUserContainer(IWAeUPObject):
191    """A container for users (principals).
192
193    These users are used for authentication purposes.
194    """
195
196    def addUser(name, password, title=None, description=None):
197        """Add a user.
198        """
199
200    def delUser(name):
201        """Delete a user if it exists.
202        """
203
204class ILocalRolesAssignable(Interface):
205    """The local roles assignable to an object.
206    """
207    def __call__():
208        """Returns a list of dicts.
209
210        Each dict contains a ``name`` referring to the role assignable
211        for the specified object and a `title` to describe the range
212        of users to which this role can be assigned.
213        """
214
215    def names():
216        """Return a list of role names assignable.
217        """
218
219class IDataCenter(IWAeUPObject):
220    """A data center.
221
222    TODO : declare methods, at least those needed by pages.
223    """
224    pass
225
226class IDataCenterFile(Interface):
227    """A data center file.
228    """
229
230    name = schema.TextLine(
231        title = u'Filename')
232
233    size = schema.TextLine(
234        title = u'Human readable file size')
235
236    uploaddate = schema.TextLine(
237        title = u'Human readable upload datetime')
238
239    lines = schema.Int(
240        title = u'Number of lines in file')
241
242    def getDate():
243        """Get creation timestamp from file in human readable form.
244        """
245
246    def getSize():
247        """Get human readable size of file.
248        """
249
250    def getLinesNumber():
251        """Get number of lines of file.
252        """
253
254class IDataCenterStorageMovedEvent(IObjectEvent):
255    """Emitted, when the storage of a datacenter changes.
256    """
257
258class IObjectUpgradeEvent(IObjectEvent):
259    """Can be fired, when an object shall be upgraded.
260    """
261
262class IQueryResultItem(Interface):
263    """An item in a search result.
264    """
265    url = schema.TextLine(
266        title = u'URL that links to the found item')
267    title = schema.TextLine(
268        title = u'Title displayed in search results.')
269    description = schema.Text(
270        title = u'Longer description of the item found.')
271
272class IWAeUPSIRPPluggable(Interface):
273    """A component that might be plugged into a WAeUP SIRP app.
274
275    Components implementing this interface are referred to as
276    'plugins'. They are normally called when a new
277    :class:`waeup.sirp.app.University` instance is created.
278
279    Plugins can setup and update parts of the central site without the
280    site object (normally a :class:`waeup.sirp.app.University` object)
281    needing to know about that parts. The site simply collects all
282    available plugins, calls them and the plugins care for their
283    respective subarea like the applicants area or the datacenter
284    area.
285
286    Currently we have no mechanism to define an order of plugins. A
287    plugin should therefore make no assumptions about the state of the
288    site or other plugins being run before and instead do appropriate
289    checks if necessary.
290
291    Updates can be triggered for instance by the respective form in
292    the site configuration. You normally do updates when the
293    underlying software changed.
294    """
295    def setup(site, name, logger):
296        """Create an instance of the plugin.
297
298        The method is meant to be called by the central app (site)
299        when it is created.
300
301        `site`:
302           The site that requests a setup.
303
304        `name`:
305           The name under which the plugin was registered (utility name).
306
307        `logger`:
308           A standard Python logger for the plugins use.
309        """
310
311    def update(site, name, logger):
312        """Method to update an already existing plugin.
313
314        This might be called by a site when something serious
315        changes. It is a poor-man replacement for Zope generations
316        (but probably more comprehensive and better understandable).
317
318        `site`:
319           The site that requests an update.
320
321        `name`:
322           The name under which the plugin was registered (utility name).
323
324        `logger`:
325           A standard Python logger for the plugins use.
326        """
327
328class IAuthPluginUtility(Interface):
329    """A component that cares for authentication setup at site creation.
330
331    Utilities providing this interface are looked up when a Pluggable
332    Authentication Utility (PAU) for any
333    :class:`waeup.sirp.app.University` instance is created and put
334    into ZODB.
335
336    The setup-code then calls the `register` method of the utility and
337    expects a modified (or unmodified) version of the PAU back.
338
339    This allows to define any authentication setup modifications by
340    submodules or third-party modules/packages.
341    """
342
343    def register(pau):
344        """Register any plugins wanted to be in the PAU.
345        """
346
347    def unregister(pau):
348        """Unregister any plugins not wanted to be in the PAU.
349        """
Note: See TracBrowser for help on using the repository browser.