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

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

Add interface for new event type.

  • Property svn:eol-style set to native
File size: 9.1 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 IDataCenter(IWAeUPObject):
205    """A data center.
206
207    TODO : declare methods, at least those needed by pages.
208    """
209    pass
210
211class IDataCenterFile(Interface):
212    """A data center file.
213    """
214
215    name = schema.TextLine(
216        title = u'Filename')
217
218    size = schema.TextLine(
219        title = u'Human readable file size')
220
221    uploaddate = schema.TextLine(
222        title = u'Human readable upload datetime')
223
224    lines = schema.Int(
225        title = u'Number of lines in file')
226
227    def getDate():
228        """Get creation timestamp from file in human readable form.
229        """
230
231    def getSize():
232        """Get human readable size of file.
233        """
234
235    def getLinesNumber():
236        """Get number of lines of file.
237        """
238
239class IDataCenterStorageMovedEvent(IObjectEvent):
240    """Emitted, when the storage of a datacenter changes.
241    """
242
243class IObjectUpgradeEvent(IObjectEvent):
244    """Can be fired, when an object shall be upgraded.
245    """
246
247class IQueryResultItem(Interface):
248    """An item in a search result.
249    """
250    url = schema.TextLine(
251        title = u'URL that links to the found item')
252    title = schema.TextLine(
253        title = u'Title displayed in search results.')
254    description = schema.Text(
255        title = u'Longer description of the item found.')
256
257class IWAeUPSIRPPluggable(Interface):
258    """A component that might be plugged into a WAeUP SIRP app.
259
260    Components implementing this interface are referred to as
261    'plugins'. They are normally called when a new
262    :class:`waeup.sirp.app.University` instance is created.
263
264    Plugins can setup and update parts of the central site without the
265    site object (normally a :class:`waeup.sirp.app.University` object)
266    needing to know about that parts. The site simply collects all
267    available plugins, calls them and the plugins care for their
268    respective subarea like the applicants area or the datacenter
269    area.
270
271    Currently we have no mechanism to define an order of plugins. A
272    plugin should therefore make no assumptions about the state of the
273    site or other plugins being run before and instead do appropriate
274    checks if necessary.
275
276    Updates can be triggered for instance by the respective form in
277    the site configuration. You normally do updates when the
278    underlying software changed.
279    """
280    def setup(site, name, logger):
281        """Create an instance of the plugin.
282
283        The method is meant to be called by the central app (site)
284        when it is created.
285
286        `site`:
287           The site that requests a setup.
288
289        `name`:
290           The name under which the plugin was registered (utility name).
291
292        `logger`:
293           A standard Python logger for the plugins use.
294        """
295
296    def update(site, name, logger):
297        """Method to update an already existing plugin.
298
299        This might be called by a site when something serious
300        changes. It is a poor-man replacement for Zope generations
301        (but probably more comprehensive and better understandable).
302
303        `site`:
304           The site that requests an update.
305
306        `name`:
307           The name under which the plugin was registered (utility name).
308
309        `logger`:
310           A standard Python logger for the plugins use.
311        """
312
313class IAuthPluginUtility(Interface):
314    """A component that cares for authentication setup at site creation.
315
316    Utilities providing this interface are looked up when a Pluggable
317    Authentication Utility (PAU) for any
318    :class:`waeup.sirp.app.University` instance is created and put
319    into ZODB.
320
321    The setup-code then calls the `register` method of the utility and
322    expects a modified (or unmodified) version of the PAU back.
323
324    This allows to define any authentication setup modifications by
325    submodules or third-party modules/packages.
326    """
327
328    def register(pau):
329        """Register any plugins wanted to be in the PAU.
330        """
331
332    def unregister(pau):
333        """Unregister any plugins not wanted to be in the PAU.
334        """
Note: See TracBrowser for help on using the repository browser.