source: main/waeup.sirp/branches/workshop2010-playground/src/waeup/sirp/interfaces.py @ 5558

Last change on this file since 5558 was 5558, checked in by gbenga, 14 years ago

Make changes to email text string

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