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

Last change on this file since 5918 was 5899, checked in by uli, 14 years ago

Fix typo.

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