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

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

Zope roles come with a title attribute. Start making use of it and simplify role lookup in w.s.permissions

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