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

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

Split workflow components (general use stuff goes to w.s.workflow), add some convenience stuff, ...)

  • Property svn:eol-style set to native
File size: 12.8 KB
Line 
1##
2## interfaces.py
3from hurry.workflow.interfaces import IWorkflow, IWorkflowInfo
4from zc.sourcefactory.basic import BasicSourceFactory
5from zope import schema
6from zope.component import getUtility
7from zope.component.interfaces import IObjectEvent
8from zope.interface import Interface, Attribute, implements
9from zope.schema.vocabulary import SimpleVocabulary, SimpleTerm
10
11class FatalCSVError(Exception):
12    """Some row could not be processed.
13    """
14    pass
15
16class DuplicationError(Exception):
17    """An exception that can be raised when duplicates are found.
18
19    When raising :exc:`DuplicationError` you can, beside the usual
20    message, specify a list of objects which are duplicates. These
21    values can be used by catching code to print something helpful or
22    similar.
23    """
24    def __init__(self, msg, entries=[]):
25        self.msg = msg
26        self.entries = entries
27
28    def __str__(self):
29        return '%r' % self.msg
30
31def SimpleWAeUPVocabulary(*terms):
32    """A well-buildt vocabulary provides terms with a value, token and
33       title for each term
34    """
35    return SimpleVocabulary([
36            SimpleTerm(value, value, title) for title, value in terms])
37
38class RoleSource(BasicSourceFactory):
39    def getValues(self):
40        # late import: in interfaces we should not import local modules
41        from waeup.sirp.permissions import getWAeUPRoleNames
42        return getWAeUPRoleNames()
43
44    def getTitle(self, value):
45        # late import: in interfaces we should not import local modules
46        from waeup.sirp.permissions import getRoles
47        roles = dict(getRoles())
48        if value in roles.keys():
49            title = roles[value].title
50        if '.' in title:
51            title = title.split('.', 2)[1]
52        return title
53
54class IWAeUPObject(Interface):
55    """A WAeUP object.
56
57    This is merely a marker interface.
58    """
59
60class IUniversity(IWAeUPObject):
61    """Representation of a university.
62    """
63    name = schema.TextLine(
64        title = u'Name of University',
65        default = u'Unnamed',
66        required = True,
67        )
68
69    title = schema.TextLine(
70        title = u'Title of frontpage',
71        default = u'No Title',
72        required = False,
73        )
74
75    skin = schema.Choice(
76        title = u'Skin',
77        default = u'waeuptheme-gray1.css',
78        vocabulary = 'waeup.sirp.browser.theming.ThemesVocabulary',
79        required = True,
80        )
81
82    frontpage = schema.Text(
83        title = u'Content in reST format',
84        required = False,
85        default = u'This is the SIRP frontpage.'
86        )
87
88    faculties = Attribute("A container for faculties.")
89    students = Attribute("A container for students.")
90    hostels = Attribute("A container for hostels.")
91
92class IWAeUPContainer(IWAeUPObject):
93    """A container for WAeUP objects.
94    """
95
96class IWAeUPContained(IWAeUPObject):
97    """An item contained in an IWAeUPContainer.
98    """
99
100class IStudentContainer(IWAeUPContainer):
101    """A container for StudentObjects.
102    """
103
104
105class IHostelContainer(IWAeUPContainer):
106    """A container for hostels.
107    """
108    def addHostel(hostel):
109        """Add an IHostel object.
110
111        Returns the key, under which the object was stored.
112        """
113
114class IHostel(IWAeUPObject):
115    """Representation of a hostel.
116    """
117    name = schema.TextLine(
118        title = u'Name of Hostel',
119        default = u'Nobody',
120        required = True,
121        )
122
123
124class IWAeUPExporter(Interface):
125    """An exporter for objects.
126    """
127    def export(obj, filepath=None):
128        """Export by pickling.
129
130        Returns a file-like object containing a representation of `obj`.
131
132        This is done using `pickle`. If `filepath` is ``None``, a
133        `cStringIO` object is returned, that contains the saved data.
134        """
135
136class IWAeUPXMLExporter(Interface):
137    """An XML exporter for objects.
138    """
139    def export(obj, filepath=None):
140        """Export as XML.
141
142        Returns an XML representation of `obj`.
143
144        If `filepath` is ``None``, a StringIO` object is returned,
145        that contains the transformed data.
146        """
147
148class IWAeUPXMLImporter(Interface):
149    """An XML import for objects.
150    """
151    def doImport(filepath):
152        """Create Python object from XML.
153
154        Returns a Python object.
155        """
156
157class IBatchProcessor(Interface):
158    """A batch processor that handles mass-operations.
159    """
160    name = schema.TextLine(
161        title = u'Importer name'
162        )
163
164    mode = schema.Choice(
165        title = u'Import mode',
166        values = ['create', 'update', 'remove']
167        )
168
169    def doImport(path, headerfields, mode='create', user='Unknown',
170                 logger=None):
171        """Read data from ``path`` and update connected object.
172
173        `headerfields` is a list of headerfields as read from the file
174        to import.
175
176        `mode` gives the import mode to use (``'create'``,
177        ``'update'``, or ``'remove'``.
178
179        `user` is a string describing the user performing the
180        import. Normally fetched from current principal.
181
182        `logger` is the logger to use during import.
183        """
184
185class IUserAccount(IWAeUPObject):
186    """A user account.
187    """
188    name = schema.TextLine(
189        title = u'User ID',
190        description = u'Loginname',
191        required = True,)
192    title = schema.TextLine(
193        title = u'Username',
194        description = u'Real name',
195        required = False,)
196    description = schema.TextLine(
197        title = u'User description',
198        required = False,)
199    password = schema.Password(
200        title = u'Password',
201        required = True,)
202    roles = schema.List(
203        title = u'Roles',
204        value_type = schema.Choice(source=RoleSource()))
205
206
207class IUserContainer(IWAeUPObject):
208    """A container for users (principals).
209
210    These users are used for authentication purposes.
211    """
212
213    def addUser(name, password, title=None, description=None):
214        """Add a user.
215        """
216
217    def delUser(name):
218        """Delete a user if it exists.
219        """
220
221class ILocalRolesAssignable(Interface):
222    """The local roles assignable to an object.
223    """
224    def __call__():
225        """Returns a list of dicts.
226
227        Each dict contains a ``name`` referring to the role assignable
228        for the specified object and a `title` to describe the range
229        of users to which this role can be assigned.
230        """
231
232class IDataCenter(IWAeUPObject):
233    """A data center.
234
235    TODO : declare methods, at least those needed by pages.
236    """
237    pass
238
239class IDataCenterFile(Interface):
240    """A data center file.
241    """
242
243    name = schema.TextLine(
244        title = u'Filename')
245
246    size = schema.TextLine(
247        title = u'Human readable file size')
248
249    uploaddate = schema.TextLine(
250        title = u'Human readable upload datetime')
251
252    lines = schema.Int(
253        title = u'Number of lines in file')
254
255    def getDate():
256        """Get creation timestamp from file in human readable form.
257        """
258
259    def getSize():
260        """Get human readable size of file.
261        """
262
263    def getLinesNumber():
264        """Get number of lines of file.
265        """
266
267class IDataCenterStorageMovedEvent(IObjectEvent):
268    """Emitted, when the storage of a datacenter changes.
269    """
270
271class IObjectUpgradeEvent(IObjectEvent):
272    """Can be fired, when an object shall be upgraded.
273    """
274
275class ILocalRoleSetEvent(IObjectEvent):
276    """A local role was granted/revoked for a principal on an object.
277    """
278    role_id = Attribute(
279        "The role id that was set.")
280    principal_id = Attribute(
281        "The principal id for which the role was granted/revoked.")
282    granted = Attribute(
283        "Boolean. If false, then the role was revoked.")
284
285class IQueryResultItem(Interface):
286    """An item in a search result.
287    """
288    url = schema.TextLine(
289        title = u'URL that links to the found item')
290    title = schema.TextLine(
291        title = u'Title displayed in search results.')
292    description = schema.Text(
293        title = u'Longer description of the item found.')
294
295class IWAeUPSIRPPluggable(Interface):
296    """A component that might be plugged into a WAeUP SIRP app.
297
298    Components implementing this interface are referred to as
299    'plugins'. They are normally called when a new
300    :class:`waeup.sirp.app.University` instance is created.
301
302    Plugins can setup and update parts of the central site without the
303    site object (normally a :class:`waeup.sirp.app.University` object)
304    needing to know about that parts. The site simply collects all
305    available plugins, calls them and the plugins care for their
306    respective subarea like the applicants area or the datacenter
307    area.
308
309    Currently we have no mechanism to define an order of plugins. A
310    plugin should therefore make no assumptions about the state of the
311    site or other plugins being run before and instead do appropriate
312    checks if necessary.
313
314    Updates can be triggered for instance by the respective form in
315    the site configuration. You normally do updates when the
316    underlying software changed.
317    """
318    def setup(site, name, logger):
319        """Create an instance of the plugin.
320
321        The method is meant to be called by the central app (site)
322        when it is created.
323
324        `site`:
325           The site that requests a setup.
326
327        `name`:
328           The name under which the plugin was registered (utility name).
329
330        `logger`:
331           A standard Python logger for the plugins use.
332        """
333
334    def update(site, name, logger):
335        """Method to update an already existing plugin.
336
337        This might be called by a site when something serious
338        changes. It is a poor-man replacement for Zope generations
339        (but probably more comprehensive and better understandable).
340
341        `site`:
342           The site that requests an update.
343
344        `name`:
345           The name under which the plugin was registered (utility name).
346
347        `logger`:
348           A standard Python logger for the plugins use.
349        """
350
351class IAuthPluginUtility(Interface):
352    """A component that cares for authentication setup at site creation.
353
354    Utilities providing this interface are looked up when a Pluggable
355    Authentication Utility (PAU) for any
356    :class:`waeup.sirp.app.University` instance is created and put
357    into ZODB.
358
359    The setup-code then calls the `register` method of the utility and
360    expects a modified (or unmodified) version of the PAU back.
361
362    This allows to define any authentication setup modifications by
363    submodules or third-party modules/packages.
364    """
365
366    def register(pau):
367        """Register any plugins wanted to be in the PAU.
368        """
369
370    def unregister(pau):
371        """Unregister any plugins not wanted to be in the PAU.
372        """
373
374class IObjectConverter(Interface):
375    """Object converters are available as simple adapters, adapting
376       interfaces (not regular instances).
377
378    """
379
380    def fromStringDict(self, data_dict, context, form_fields=None):
381        """Convert values in `data_dict`.
382
383        Converts data in `data_dict` into real values based on
384        `context` and `form_fields`.
385
386        `data_dict` is a mapping (dict) from field names to values
387        represented as strings.
388
389        The fields (keys) to convert can be given in optional
390        `form_fields`. If given, form_fields should be an instance of
391        :class:`zope.formlib.form.Fields`. Suitable instances are for
392        example created by :class:`grok.AutoFields`.
393
394        If no `form_fields` are given, a default is computed from the
395        associated interface.
396
397        The `context` can be an existing object (implementing the
398        associated interface) or a factory name. If it is a string, we
399        try to create an object using
400        :func:`zope.component.createObject`.
401
402        Returns a tuple ``(<FIELD_ERRORS>, <INVARIANT_ERRORS>,
403        <DATA_DICT>)`` where
404
405        ``<FIELD_ERRORS>``
406           is a list of tuples ``(<FIELD_NAME>, <ERROR>)`` for each
407           error that happened when validating the input data in
408           `data_dict`
409
410        ``<INVARIANT_ERRORS>``
411           is a list of invariant errors concerning several fields
412
413        ``<DATA_DICT>``
414           is a dict with the values from input dict converted.
415
416        If errors happen, i.e. the error lists are not empty, always
417        an empty ``<DATA_DICT>`` is returned.
418
419        If ``<DATA_DICT>` is non-empty, there were no errors.
420        """
421
422class IObjectHistory(Interface):
423
424    messages = schema.List(
425        title = u'List of messages stored',
426        required = True,
427        )
428
429    def addMessage(message):
430        """Add a message.
431        """
432        pass
433
434class IWAeUPWorkflowInfo(IWorkflowInfo):
435    """A :class:`hurry.workflow.workflow.WorkflowInfo` with additional
436       methods for convenience.
437    """
438    def getManualTransitions():
439        """Get allowed manual transitions.
440
441        Get a sorted list of tuples containing the `transition_id` and
442        `title` of each allowed transition.
443        """
444        pass
Note: See TracBrowser for help on using the repository browser.