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 | try: |
---|
7 | from zope.catalog.interfaces import ICatalog |
---|
8 | except ImportError: |
---|
9 | # BBB |
---|
10 | from zope.app.catalog.interfaces import ICatalog |
---|
11 | from zope.interface import Interface, Attribute |
---|
12 | from zope import schema |
---|
13 | from zope.schema.vocabulary import SimpleVocabulary, SimpleTerm |
---|
14 | from waeup.sirp.permissions import RoleSource |
---|
15 | |
---|
16 | class FatalCSVError(Exception): |
---|
17 | """Some row could not be processed. |
---|
18 | """ |
---|
19 | pass |
---|
20 | |
---|
21 | def 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 | |
---|
28 | class IWAeUPObject(Interface): |
---|
29 | """A WAeUP object. |
---|
30 | """ |
---|
31 | |
---|
32 | class 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 | |
---|
45 | class IWAeUPContainer(IWAeUPObject): |
---|
46 | """A container for WAeUP objects. |
---|
47 | """ |
---|
48 | |
---|
49 | class IWAeUPContained(IWAeUPObject): |
---|
50 | """An item contained in an IWAeUPContainer. |
---|
51 | """ |
---|
52 | |
---|
53 | class IStudentContainer(IWAeUPContainer): |
---|
54 | """A container for StudentObjects. |
---|
55 | """ |
---|
56 | |
---|
57 | |
---|
58 | class 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 | |
---|
67 | class 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 | |
---|
77 | class 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 | |
---|
89 | class 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 | |
---|
101 | class 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 | |
---|
110 | class 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 | |
---|
126 | class ISchemaTypeConverter(Interface): |
---|
127 | """A converter for zope.schema.types. |
---|
128 | """ |
---|
129 | def convert(string): |
---|
130 | """Convert string to certain schema type. |
---|
131 | """ |
---|
132 | |
---|
133 | |
---|
134 | class 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 | |
---|
156 | class 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 | |
---|
170 | class IDataCenter(IWAeUPObject): |
---|
171 | """A data center. |
---|
172 | |
---|
173 | TODO : declare methods, at least those needed by pages. |
---|
174 | """ |
---|
175 | pass |
---|
176 | |
---|
177 | class 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 | |
---|
205 | class IDataCenterStorageMovedEvent(IObjectEvent): |
---|
206 | """Emitted, when the storage of a datacenter changes. |
---|
207 | """ |
---|
208 | |
---|
209 | class 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 | |
---|
219 | class IWAeUPSIRPPluggable(Interface): |
---|
220 | """A component that might be plugged into a WAeUP SIRP app. |
---|
221 | """ |
---|
222 | factory_name = schema.TextLine( |
---|
223 | title = u'Name of the factory to create an instance of the pluggble.', |
---|
224 | description = u'The given name should be usable for ' |
---|
225 | u'calls like createObject(factory_name).' ) |
---|
226 | |
---|
227 | name = schema.TextLine( |
---|
228 | title = u'Name under which the pluggable should be created.') |
---|