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

Last change on this file since 5661 was 5658, checked in by uli, 14 years ago

Tell more about the plugin mechanism.

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