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

Last change on this file since 6227 was 6226, checked in by uli, 14 years ago

Once, there was a DuplicationError? defined in zope.exceptions. This is
not used any more in recent Zope packages and so we are free to define
our own one. This one accepts an additional paramter specifying the
objects which are duplicates.

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