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

Last change on this file since 6209 was 6209, checked in by Henrik Bettermann, 13 years ago

Remove import. ICatalog not needed.

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