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

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

Move RoleSource? into interfaces -- we need interfaces in
permissions.py.

Rename names() to roles() - this describes much better what the method
provides.

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