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

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

Remove unused method from interface too.

  • Property svn:eol-style set to native
File size: 9.9 KB
RevLine 
[3521]1##
2## interfaces.py
[4789]3from zc.sourcefactory.basic import BasicSourceFactory
[6147]4from zope import schema
5from zope.catalog.interfaces import ICatalog
[4789]6from zope.component import getUtility
[4882]7from zope.component.interfaces import IObjectEvent
[5955]8from zope.interface import Interface, Attribute, implements
[4789]9from zope.schema.vocabulary import SimpleVocabulary, SimpleTerm
[3521]10
[4858]11class FatalCSVError(Exception):
12    """Some row could not be processed.
13    """
14    pass
15
[4789]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
[6143]23class RoleSource(BasicSourceFactory):
24    def getValues(self):
[6157]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
[6143]31        from waeup.sirp.permissions import getRoles
[6157]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
[6143]38
[4789]39class IWAeUPObject(Interface):
40    """A WAeUP object.
[5663]41
42    This is merely a marker interface.
[4789]43    """
44
45class IUniversity(IWAeUPObject):
[3521]46    """Representation of a university.
47    """
48    name = schema.TextLine(
49        title = u'Name of University',
50        default = u'Unnamed',
51        required = True,
52        )
[5955]53
[6065]54    title = schema.TextLine(
55        title = u'Title of frontpage',
56        default = u'No Title',
57        required = False,
58        )
59
[5407]60    skin = schema.Choice(
61        title = u'Skin',
62        default = u'waeuptheme-gray1.css',
[5968]63        vocabulary = 'waeup.sirp.browser.theming.ThemesVocabulary',
[5407]64        required = True,
65        )
[6136]66
[6065]67    frontpage = schema.Text(
[6132]68        title = u'Content in reST format',
[6065]69        required = False,
70        default = u'This is the SIRP frontpage.'
[6136]71        )
[4789]72
73    faculties = Attribute("A container for faculties.")
74    students = Attribute("A container for students.")
75    hostels = Attribute("A container for hostels.")
[6136]76
[4789]77class IWAeUPContainer(IWAeUPObject):
78    """A container for WAeUP objects.
79    """
80
81class IWAeUPContained(IWAeUPObject):
82    """An item contained in an IWAeUPContainer.
83    """
[6136]84
[4789]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
[6136]108
[4789]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
[4858]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        )
[6136]153
[5476]154    def doImport(path, headerfields, mode='create', user='Unknown',
155                 logger=None):
[4858]156        """Read data from ``path`` and update connected object.
[5476]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.
[4858]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
[6136]177
[4789]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()))
[6136]198
199
[4789]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
[6141]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
[4789]225class IDataCenter(IWAeUPObject):
226    """A data center.
227
228    TODO : declare methods, at least those needed by pages.
229    """
230    pass
231
232class IDataCenterFile(Interface):
233    """A data center file.
234    """
[4858]235
236    name = schema.TextLine(
237        title = u'Filename')
238
239    size = schema.TextLine(
240        title = u'Human readable file size')
241
242    uploaddate = schema.TextLine(
243        title = u'Human readable upload datetime')
244
245    lines = schema.Int(
246        title = u'Number of lines in file')
[6136]247
[4789]248    def getDate():
249        """Get creation timestamp from file in human readable form.
250        """
251
252    def getSize():
253        """Get human readable size of file.
254        """
[4858]255
256    def getLinesNumber():
257        """Get number of lines of file.
258        """
[4882]259
260class IDataCenterStorageMovedEvent(IObjectEvent):
261    """Emitted, when the storage of a datacenter changes.
262    """
[5007]263
[6136]264class IObjectUpgradeEvent(IObjectEvent):
265    """Can be fired, when an object shall be upgraded.
266    """
267
[5007]268class IQueryResultItem(Interface):
269    """An item in a search result.
270    """
271    url = schema.TextLine(
272        title = u'URL that links to the found item')
273    title = schema.TextLine(
274        title = u'Title displayed in search results.')
275    description = schema.Text(
276        title = u'Longer description of the item found.')
[6136]277
[5013]278class IWAeUPSIRPPluggable(Interface):
279    """A component that might be plugged into a WAeUP SIRP app.
[5658]280
281    Components implementing this interface are referred to as
282    'plugins'. They are normally called when a new
283    :class:`waeup.sirp.app.University` instance is created.
284
285    Plugins can setup and update parts of the central site without the
286    site object (normally a :class:`waeup.sirp.app.University` object)
287    needing to know about that parts. The site simply collects all
288    available plugins, calls them and the plugins care for their
[5676]289    respective subarea like the applicants area or the datacenter
[5658]290    area.
291
292    Currently we have no mechanism to define an order of plugins. A
293    plugin should therefore make no assumptions about the state of the
294    site or other plugins being run before and instead do appropriate
295    checks if necessary.
296
297    Updates can be triggered for instance by the respective form in
298    the site configuration. You normally do updates when the
299    underlying software changed.
[5013]300    """
[5069]301    def setup(site, name, logger):
302        """Create an instance of the plugin.
[5013]303
[5658]304        The method is meant to be called by the central app (site)
305        when it is created.
306
307        `site`:
308           The site that requests a setup.
309
310        `name`:
311           The name under which the plugin was registered (utility name).
312
313        `logger`:
314           A standard Python logger for the plugins use.
[5069]315        """
316
317    def update(site, name, logger):
318        """Method to update an already existing plugin.
319
320        This might be called by a site when something serious
[5658]321        changes. It is a poor-man replacement for Zope generations
322        (but probably more comprehensive and better understandable).
323
324        `site`:
325           The site that requests an update.
326
327        `name`:
328           The name under which the plugin was registered (utility name).
329
330        `logger`:
331           A standard Python logger for the plugins use.
[5069]332        """
[5898]333
[5899]334class IAuthPluginUtility(Interface):
[5898]335    """A component that cares for authentication setup at site creation.
336
337    Utilities providing this interface are looked up when a Pluggable
338    Authentication Utility (PAU) for any
339    :class:`waeup.sirp.app.University` instance is created and put
340    into ZODB.
341
342    The setup-code then calls the `register` method of the utility and
343    expects a modified (or unmodified) version of the PAU back.
344
345    This allows to define any authentication setup modifications by
346    submodules or third-party modules/packages.
347    """
348
349    def register(pau):
350        """Register any plugins wanted to be in the PAU.
351        """
352
353    def unregister(pau):
354        """Unregister any plugins not wanted to be in the PAU.
355        """
Note: See TracBrowser for help on using the repository browser.