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

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