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

Last change on this file since 5015 was 5013, checked in by uli, 15 years ago

Define a first version of a plugin interface.

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