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

Last change on this file since 5438 was 5407, checked in by Henrik Bettermann, 14 years ago

Implement skin switch.

  • Property svn:eol-style set to native
File size: 6.3 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    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
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   
131    def doImport(path):
132        """Read data from ``path`` and update connected object.
133        """
134
135class ISchemaTypeConverter(Interface):
136    """A converter for zope.schema.types.
137    """
138    def convert(string):
139        """Convert string to certain schema type.
140        """
141
142   
143class IUserAccount(IWAeUPObject):
144    """A user account.
145    """
146    name = schema.TextLine(
147        title = u'User ID',
148        description = u'Loginname',
149        required = True,)
150    title = schema.TextLine(
151        title = u'Username',
152        description = u'Real name',
153        required = False,)
154    description = schema.TextLine(
155        title = u'User description',
156        required = False,)
157    password = schema.Password(
158        title = u'Password',
159        required = True,)
160    roles = schema.List(
161        title = u'Roles',
162        value_type = schema.Choice(source=RoleSource()))
163   
164   
165class IUserContainer(IWAeUPObject):
166    """A container for users (principals).
167
168    These users are used for authentication purposes.
169    """
170
171    def addUser(name, password, title=None, description=None):
172        """Add a user.
173        """
174
175    def delUser(name):
176        """Delete a user if it exists.
177        """
178
179class IDataCenter(IWAeUPObject):
180    """A data center.
181
182    TODO : declare methods, at least those needed by pages.
183    """
184    pass
185
186class IDataCenterFile(Interface):
187    """A data center file.
188    """
189
190    name = schema.TextLine(
191        title = u'Filename')
192
193    size = schema.TextLine(
194        title = u'Human readable file size')
195
196    uploaddate = schema.TextLine(
197        title = u'Human readable upload datetime')
198
199    lines = schema.Int(
200        title = u'Number of lines in file')
201       
202    def getDate():
203        """Get creation timestamp from file in human readable form.
204        """
205
206    def getSize():
207        """Get human readable size of file.
208        """
209
210    def getLinesNumber():
211        """Get number of lines of file.
212        """
213
214class IDataCenterStorageMovedEvent(IObjectEvent):
215    """Emitted, when the storage of a datacenter changes.
216    """
217
218class IQueryResultItem(Interface):
219    """An item in a search result.
220    """
221    url = schema.TextLine(
222        title = u'URL that links to the found item')
223    title = schema.TextLine(
224        title = u'Title displayed in search results.')
225    description = schema.Text(
226        title = u'Longer description of the item found.')
227     
228class IWAeUPSIRPPluggable(Interface):
229    """A component that might be plugged into a WAeUP SIRP app.
230    """
231    def setup(site, name, logger):
232        """Create an instance of the plugin.
233
234        The method is meant to be called by the central app on startup.
235        """
236
237    def update(site, name, logger):
238        """Method to update an already existing plugin.
239
240        This might be called by a site when something serious
241        changes. It is a poor-man replacement for Zope generations.
242        """
Note: See TracBrowser for help on using the repository browser.