source: main/waeup.sirp/branches/ulif-fasttables/src/waeup/sirp/interfaces.py @ 10009

Last change on this file since 10009 was 5069, checked in by uli, 15 years ago

Change the plugin interface.

  • Property svn:eol-style set to native
File size: 5.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
32class IUniversity(IWAeUPObject):
33    """Representation of a university.
34    """
35    name = schema.TextLine(
36        title = u'Name of University',
37        default = u'Unnamed',
38        required = True,
39        )
40
41    faculties = Attribute("A container for faculties.")
42    students = Attribute("A container for students.")
43    hostels = Attribute("A container for hostels.")
44   
45class IWAeUPContainer(IWAeUPObject):
46    """A container for WAeUP objects.
47    """
48
49class IWAeUPContained(IWAeUPObject):
50    """An item contained in an IWAeUPContainer.
51    """
52   
53class IStudentContainer(IWAeUPContainer):
54    """A container for StudentObjects.
55    """
56
57
58class IHostelContainer(IWAeUPContainer):
59    """A container for hostels.
60    """
61    def addHostel(hostel):
62        """Add an IHostel object.
63
64        Returns the key, under which the object was stored.
65        """
66
67class IHostel(IWAeUPObject):
68    """Representation of a hostel.
69    """
70    name = schema.TextLine(
71        title = u'Name of Hostel',
72        default = u'Nobody',
73        required = True,
74        )
75
76       
77class IWAeUPExporter(Interface):
78    """An exporter for objects.
79    """
80    def export(obj, filepath=None):
81        """Export by pickling.
82
83        Returns a file-like object containing a representation of `obj`.
84
85        This is done using `pickle`. If `filepath` is ``None``, a
86        `cStringIO` object is returned, that contains the saved data.
87        """
88
89class IWAeUPXMLExporter(Interface):
90    """An XML exporter for objects.
91    """
92    def export(obj, filepath=None):
93        """Export as XML.
94
95        Returns an XML representation of `obj`.
96
97        If `filepath` is ``None``, a StringIO` object is returned,
98        that contains the transformed data.
99        """
100
101class IWAeUPXMLImporter(Interface):
102    """An XML import for objects.
103    """
104    def doImport(filepath):
105        """Create Python object from XML.
106
107        Returns a Python object.
108        """
109
110class IBatchProcessor(Interface):
111    """A batch processor that handles mass-operations.
112    """
113    name = schema.TextLine(
114        title = u'Importer name'
115        )
116
117    mode = schema.Choice(
118        title = u'Import mode',
119        values = ['create', 'update', 'remove']
120        )
121   
122    def doImport(path):
123        """Read data from ``path`` and update connected object.
124        """
125
126class ISchemaTypeConverter(Interface):
127    """A converter for zope.schema.types.
128    """
129    def convert(string):
130        """Convert string to certain schema type.
131        """
132
133   
134class IUserAccount(IWAeUPObject):
135    """A user account.
136    """
137    name = schema.TextLine(
138        title = u'User ID',
139        description = u'Loginname',
140        required = True,)
141    title = schema.TextLine(
142        title = u'Username',
143        description = u'Real name',
144        required = False,)
145    description = schema.TextLine(
146        title = u'User description',
147        required = False,)
148    password = schema.Password(
149        title = u'Password',
150        required = True,)
151    roles = schema.List(
152        title = u'Roles',
153        value_type = schema.Choice(source=RoleSource()))
154   
155   
156class IUserContainer(IWAeUPObject):
157    """A container for users (principals).
158
159    These users are used for authentication purposes.
160    """
161
162    def addUser(name, password, title=None, description=None):
163        """Add a user.
164        """
165
166    def delUser(name):
167        """Delete a user if it exists.
168        """
169
170class IDataCenter(IWAeUPObject):
171    """A data center.
172
173    TODO : declare methods, at least those needed by pages.
174    """
175    pass
176
177class IDataCenterFile(Interface):
178    """A data center file.
179    """
180
181    name = schema.TextLine(
182        title = u'Filename')
183
184    size = schema.TextLine(
185        title = u'Human readable file size')
186
187    uploaddate = schema.TextLine(
188        title = u'Human readable upload datetime')
189
190    lines = schema.Int(
191        title = u'Number of lines in file')
192       
193    def getDate():
194        """Get creation timestamp from file in human readable form.
195        """
196
197    def getSize():
198        """Get human readable size of file.
199        """
200
201    def getLinesNumber():
202        """Get number of lines of file.
203        """
204
205class IDataCenterStorageMovedEvent(IObjectEvent):
206    """Emitted, when the storage of a datacenter changes.
207    """
208
209class IQueryResultItem(Interface):
210    """An item in a search result.
211    """
212    url = schema.TextLine(
213        title = u'URL that links to the found item')
214    title = schema.TextLine(
215        title = u'Title displayed in search results.')
216    description = schema.Text(
217        title = u'Longer description of the item found.')
218     
219class IWAeUPSIRPPluggable(Interface):
220    """A component that might be plugged into a WAeUP SIRP app.
221    """
222    def setup(site, name, logger):
223        """Create an instance of the plugin.
224
225        The method is meant to be called by the central app on startup.
226        """
227
228    def update(site, name, logger):
229        """Method to update an already existing plugin.
230
231        This might be called by a site when something serious
232        changes. It is a poor-man replacement for Zope generations.
233        """
Note: See TracBrowser for help on using the repository browser.