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

Last change on this file since 5489 was 5476, checked in by uli, 14 years ago

Update the interface signature for doImport method of batch
processors. In fact we are using this different interface since long
time. We only forgot to test it.

  • Property svn:eol-style set to native
File size: 6.7 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.
242    """
[5069]243    def setup(site, name, logger):
244        """Create an instance of the plugin.
[5013]245
[5069]246        The method is meant to be called by the central app on startup.
247        """
248
249    def update(site, name, logger):
250        """Method to update an already existing plugin.
251
252        This might be called by a site when something serious
253        changes. It is a poor-man replacement for Zope generations.
254        """
Note: See TracBrowser for help on using the repository browser.