1 | ## |
---|
2 | ## interfaces.py |
---|
3 | from zc.sourcefactory.basic import BasicSourceFactory |
---|
4 | from zope.component import getUtility |
---|
5 | from zope.component.interfaces import IObjectEvent |
---|
6 | from zope.app.catalog.interfaces import ICatalog |
---|
7 | from zope.interface import Interface, Attribute |
---|
8 | from zope import schema |
---|
9 | from zope.schema.vocabulary import SimpleVocabulary, SimpleTerm |
---|
10 | from waeup.sirp.permissions import RoleSource |
---|
11 | |
---|
12 | class FatalCSVError(Exception): |
---|
13 | """Some row could not be processed. |
---|
14 | """ |
---|
15 | pass |
---|
16 | |
---|
17 | def 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 | |
---|
24 | class IWAeUPObject(Interface): |
---|
25 | """A WAeUP object. |
---|
26 | """ |
---|
27 | |
---|
28 | class IUniversity(IWAeUPObject): |
---|
29 | """Representation of a university. |
---|
30 | """ |
---|
31 | name = schema.TextLine( |
---|
32 | title = u'Name of University', |
---|
33 | default = u'Unnamed', |
---|
34 | required = True, |
---|
35 | ) |
---|
36 | |
---|
37 | faculties = Attribute("A container for faculties.") |
---|
38 | students = Attribute("A container for students.") |
---|
39 | hostels = Attribute("A container for hostels.") |
---|
40 | |
---|
41 | class IWAeUPContainer(IWAeUPObject): |
---|
42 | """A container for WAeUP objects. |
---|
43 | """ |
---|
44 | |
---|
45 | class IWAeUPContained(IWAeUPObject): |
---|
46 | """An item contained in an IWAeUPContainer. |
---|
47 | """ |
---|
48 | |
---|
49 | class IStudentContainer(IWAeUPContainer): |
---|
50 | """A container for StudentObjects. |
---|
51 | """ |
---|
52 | |
---|
53 | |
---|
54 | class 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 | |
---|
63 | class 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 | |
---|
73 | class 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 | |
---|
85 | class 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 | |
---|
97 | class 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 | |
---|
106 | class 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 | |
---|
122 | class ISchemaTypeConverter(Interface): |
---|
123 | """A converter for zope.schema.types. |
---|
124 | """ |
---|
125 | def convert(string): |
---|
126 | """Convert string to certain schema type. |
---|
127 | """ |
---|
128 | |
---|
129 | |
---|
130 | class 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 | |
---|
152 | class 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 | |
---|
166 | class IDataCenter(IWAeUPObject): |
---|
167 | """A data center. |
---|
168 | |
---|
169 | TODO : declare methods, at least those needed by pages. |
---|
170 | """ |
---|
171 | pass |
---|
172 | |
---|
173 | class IDataCenterFile(Interface): |
---|
174 | """A data center file. |
---|
175 | """ |
---|
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 | |
---|
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 | """ |
---|
196 | |
---|
197 | def getLinesNumber(): |
---|
198 | """Get number of lines of file. |
---|
199 | """ |
---|
200 | |
---|
201 | class IDataCenterStorageMovedEvent(IObjectEvent): |
---|
202 | """Emitted, when the storage of a datacenter changes. |
---|
203 | """ |
---|
204 | |
---|
205 | class 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 | |
---|
215 | class 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.') |
---|