1 | ## $Id: interfaces.py 9115 2012-08-28 08:13:21Z henrik $ |
---|
2 | ## |
---|
3 | ## Copyright (C) 2011 Uli Fouquet & Henrik Bettermann |
---|
4 | ## This program is free software; you can redistribute it and/or modify |
---|
5 | ## it under the terms of the GNU General Public License as published by |
---|
6 | ## the Free Software Foundation; either version 2 of the License, or |
---|
7 | ## (at your option) any later version. |
---|
8 | ## |
---|
9 | ## This program is distributed in the hope that it will be useful, |
---|
10 | ## but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
11 | ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
12 | ## GNU General Public License for more details. |
---|
13 | ## |
---|
14 | ## You should have received a copy of the GNU General Public License |
---|
15 | ## along with this program; if not, write to the Free Software |
---|
16 | ## Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
---|
17 | ## |
---|
18 | import os |
---|
19 | import re |
---|
20 | import codecs |
---|
21 | import zope.i18nmessageid |
---|
22 | from datetime import datetime |
---|
23 | from hurry.file.interfaces import IFileRetrieval |
---|
24 | from hurry.workflow.interfaces import IWorkflowInfo |
---|
25 | from zc.sourcefactory.basic import BasicSourceFactory |
---|
26 | from zope import schema |
---|
27 | from zope.pluggableauth.interfaces import IPrincipalInfo |
---|
28 | from zope.security.interfaces import IGroupClosureAwarePrincipal as IPrincipal |
---|
29 | from zope.component import getUtility |
---|
30 | from zope.component.interfaces import IObjectEvent |
---|
31 | from zope.container.interfaces import INameChooser |
---|
32 | from zope.interface import Interface, Attribute |
---|
33 | from zope.schema.interfaces import IObject |
---|
34 | from zope.schema.vocabulary import SimpleVocabulary, SimpleTerm |
---|
35 | from waeup.kofa.schema import PhoneNumber |
---|
36 | |
---|
37 | _ = MessageFactory = zope.i18nmessageid.MessageFactory('waeup.kofa') |
---|
38 | |
---|
39 | DELETION_MARKER = 'XXX' |
---|
40 | IGNORE_MARKER = '<IGNORE>' |
---|
41 | |
---|
42 | CREATED = 'created' |
---|
43 | ADMITTED = 'admitted' |
---|
44 | CLEARANCE = 'clearance started' |
---|
45 | REQUESTED = 'clearance requested' |
---|
46 | CLEARED = 'cleared' |
---|
47 | PAID = 'school fee paid' |
---|
48 | RETURNING = 'returning' |
---|
49 | REGISTERED = 'courses registered' |
---|
50 | VALIDATED = 'courses validated' |
---|
51 | |
---|
52 | #default_rest_frontpage = u'' + codecs.open(os.path.join( |
---|
53 | # os.path.dirname(__file__), 'frontpage.rst'), |
---|
54 | # encoding='utf-8', mode='rb').read() |
---|
55 | |
---|
56 | default_html_frontpage = u'' + codecs.open(os.path.join( |
---|
57 | os.path.dirname(__file__), 'frontpage.html'), |
---|
58 | encoding='utf-8', mode='rb').read() |
---|
59 | |
---|
60 | def SimpleKofaVocabulary(*terms): |
---|
61 | """A well-buildt vocabulary provides terms with a value, token and |
---|
62 | title for each term |
---|
63 | """ |
---|
64 | return SimpleVocabulary([ |
---|
65 | SimpleTerm(value, value, title) for title, value in terms]) |
---|
66 | |
---|
67 | def academic_sessions(): |
---|
68 | curr_year = datetime.now().year |
---|
69 | year_range = range(1995, curr_year + 2) |
---|
70 | return [('%s/%s' % (year,year+1), year) for year in year_range] |
---|
71 | |
---|
72 | academic_sessions_vocab = SimpleKofaVocabulary(*academic_sessions()) |
---|
73 | |
---|
74 | registration_states_vocab = SimpleKofaVocabulary( |
---|
75 | (_('created'), CREATED), |
---|
76 | (_('admitted'), ADMITTED), |
---|
77 | (_('clearance started'), CLEARANCE), |
---|
78 | (_('clearance requested'), REQUESTED), |
---|
79 | (_('cleared'), CLEARED), |
---|
80 | (_('school fee paid'), PAID), |
---|
81 | (_('returning'), RETURNING), |
---|
82 | (_('courses registered'), REGISTERED), |
---|
83 | (_('courses validated'), VALIDATED), |
---|
84 | ) |
---|
85 | |
---|
86 | class SubjectSource(BasicSourceFactory): |
---|
87 | """A source for school subjects used in exam documentation. |
---|
88 | """ |
---|
89 | def getValues(self): |
---|
90 | subjects_dict = getUtility(IKofaUtils).EXAM_SUBJECTS_DICT |
---|
91 | return sorted(subjects_dict.keys()) |
---|
92 | |
---|
93 | def getTitle(self, value): |
---|
94 | subjects_dict = getUtility(IKofaUtils).EXAM_SUBJECTS_DICT |
---|
95 | return "%s:" % subjects_dict[value] |
---|
96 | |
---|
97 | class GradeSource(BasicSourceFactory): |
---|
98 | """A source for exam grades. |
---|
99 | """ |
---|
100 | def getValues(self): |
---|
101 | for entry in getUtility(IKofaUtils).EXAM_GRADES: |
---|
102 | yield entry[0] |
---|
103 | |
---|
104 | def getTitle(self, value): |
---|
105 | return dict(getUtility(IKofaUtils).EXAM_GRADES)[value] |
---|
106 | |
---|
107 | # Define a validation method for email addresses |
---|
108 | class NotAnEmailAddress(schema.ValidationError): |
---|
109 | __doc__ = u"Invalid email address" |
---|
110 | |
---|
111 | #: Regular expression to check email-address formats. As these can |
---|
112 | #: become rather complex (nearly everything is allowed by RFCs), we only |
---|
113 | #: forbid whitespaces, commas and dots following onto each other. |
---|
114 | check_email = re.compile( |
---|
115 | r"^[^@\s,]+@[^@\.\s,]+(\.[^@\.\s,]+)*$").match |
---|
116 | |
---|
117 | def validate_email(value): |
---|
118 | if not check_email(value): |
---|
119 | raise NotAnEmailAddress(value) |
---|
120 | return True |
---|
121 | |
---|
122 | # Define a validation method for international phone numbers |
---|
123 | class InvalidPhoneNumber(schema.ValidationError): |
---|
124 | __doc__ = u"Invalid phone number" |
---|
125 | |
---|
126 | # represent format +NNN-NNNN-NNNN |
---|
127 | RE_INT_PHONE = re.compile(r"^\+?\d+\-\d+\-[\d\-]+$") |
---|
128 | |
---|
129 | def validate_phone(value): |
---|
130 | if not RE_INT_PHONE.match(value): |
---|
131 | raise InvalidPhoneNumber(value) |
---|
132 | return True |
---|
133 | |
---|
134 | class FatalCSVError(Exception): |
---|
135 | """Some row could not be processed. |
---|
136 | """ |
---|
137 | pass |
---|
138 | |
---|
139 | class DuplicationError(Exception): |
---|
140 | """An exception that can be raised when duplicates are found. |
---|
141 | |
---|
142 | When raising :exc:`DuplicationError` you can, beside the usual |
---|
143 | message, specify a list of objects which are duplicates. These |
---|
144 | values can be used by catching code to print something helpful or |
---|
145 | similar. |
---|
146 | """ |
---|
147 | def __init__(self, msg, entries=[]): |
---|
148 | self.msg = msg |
---|
149 | self.entries = entries |
---|
150 | |
---|
151 | def __str__(self): |
---|
152 | return '%r' % self.msg |
---|
153 | |
---|
154 | class RoleSource(BasicSourceFactory): |
---|
155 | """A source for site roles. |
---|
156 | """ |
---|
157 | def getValues(self): |
---|
158 | # late import: in interfaces we should not import local modules |
---|
159 | from waeup.kofa.permissions import get_waeup_role_names |
---|
160 | return get_waeup_role_names() |
---|
161 | |
---|
162 | def getTitle(self, value): |
---|
163 | # late import: in interfaces we should not import local modules |
---|
164 | from waeup.kofa.permissions import get_all_roles |
---|
165 | roles = dict(get_all_roles()) |
---|
166 | if value in roles.keys(): |
---|
167 | title = roles[value].title |
---|
168 | if '.' in title: |
---|
169 | title = title.split('.', 2)[1] |
---|
170 | return title |
---|
171 | |
---|
172 | class CaptchaSource(BasicSourceFactory): |
---|
173 | """A source for captchas. |
---|
174 | """ |
---|
175 | def getValues(self): |
---|
176 | captchas = ['No captcha', 'Testing captcha', 'ReCaptcha'] |
---|
177 | try: |
---|
178 | # we have to 'try' because IConfiguration can only handle |
---|
179 | # interfaces from w.k.interface. |
---|
180 | from waeup.kofa.browser.interfaces import ICaptchaManager |
---|
181 | except: |
---|
182 | return captchas |
---|
183 | return sorted(getUtility(ICaptchaManager).getAvailCaptchas().keys()) |
---|
184 | |
---|
185 | def getTitle(self, value): |
---|
186 | return value |
---|
187 | |
---|
188 | class IResultEntry(Interface): |
---|
189 | """A school grade entry. |
---|
190 | """ |
---|
191 | subject = schema.Choice( |
---|
192 | title = _(u'Subject'), |
---|
193 | source = SubjectSource(), |
---|
194 | ) |
---|
195 | grade = schema.Choice( |
---|
196 | title = _(u'Grade'), |
---|
197 | source = GradeSource(), |
---|
198 | ) |
---|
199 | |
---|
200 | class IResultEntryField(IObject): |
---|
201 | """A zope.schema-like field for usage in interfaces. |
---|
202 | |
---|
203 | Marker interface to distuingish result entries from ordinary |
---|
204 | object fields. Needed for registration of widgets. |
---|
205 | """ |
---|
206 | |
---|
207 | class IKofaUtils(Interface): |
---|
208 | """A collection of methods which are subject to customization. |
---|
209 | """ |
---|
210 | |
---|
211 | PORTAL_LANGUAGE = Attribute("Dict of global language setting") |
---|
212 | PREFERRED_LANGUAGES_DICT = Attribute("Dict of preferred languages") |
---|
213 | EXAM_SUBJECTS_DICT = Attribute("Dict of examination subjects") |
---|
214 | EXAM_GRADES_DICT = Attribute("Dict of examination grades") |
---|
215 | INST_TYPES_DICT = Attribute("Dict if institution types") |
---|
216 | STUDY_MODES_DICT = Attribute("Dict of study modes") |
---|
217 | APP_CATS_DICT = Attribute("Dict of application categories") |
---|
218 | SEMESTER_DICT = Attribute("Dict of semesters or trimesters") |
---|
219 | INT_PHONE_PREFIXES = Attribute( |
---|
220 | "Dict of international phone number prefixes") |
---|
221 | |
---|
222 | def sendContactForm( |
---|
223 | from_name,from_addr,rcpt_name,rcpt_addr, |
---|
224 | from_username,usertype,portal,body,subject): |
---|
225 | """Send an email with data provided by forms. |
---|
226 | """ |
---|
227 | |
---|
228 | def fullname(firstname,lastname,middlename): |
---|
229 | """Full name constructor. |
---|
230 | """ |
---|
231 | |
---|
232 | def sendCredentials(user, password, url_info, msg): |
---|
233 | """Send credentials as email. |
---|
234 | |
---|
235 | Input is the applicant for which credentials are sent and the |
---|
236 | password. |
---|
237 | |
---|
238 | Returns True or False to indicate successful operation. |
---|
239 | """ |
---|
240 | |
---|
241 | def genPassword(length, chars): |
---|
242 | """Generate a random password. |
---|
243 | """ |
---|
244 | |
---|
245 | class IKofaObject(Interface): |
---|
246 | """A Kofa object. |
---|
247 | |
---|
248 | This is merely a marker interface. |
---|
249 | """ |
---|
250 | |
---|
251 | class IUniversity(IKofaObject): |
---|
252 | """Representation of a university. |
---|
253 | """ |
---|
254 | |
---|
255 | |
---|
256 | class IKofaContainer(IKofaObject): |
---|
257 | """A container for Kofa objects. |
---|
258 | """ |
---|
259 | |
---|
260 | class IKofaContained(IKofaObject): |
---|
261 | """An item contained in an IKofaContainer. |
---|
262 | """ |
---|
263 | |
---|
264 | class ICSVExporter(Interface): |
---|
265 | """A CSV file exporter for objects. |
---|
266 | """ |
---|
267 | fields = Attribute("""List of fieldnames in resulting CSV""") |
---|
268 | |
---|
269 | title = schema.TextLine( |
---|
270 | title = u'Title', |
---|
271 | description = u'Description to be displayed in selections.', |
---|
272 | ) |
---|
273 | def mangle_value(value, name, obj): |
---|
274 | """Mangle `value` extracted from `obj` or suobjects thereof. |
---|
275 | |
---|
276 | This is called by export before actually writing to the result |
---|
277 | file. |
---|
278 | """ |
---|
279 | |
---|
280 | def export(iterable, filepath=None): |
---|
281 | """Export iterables as rows in a CSV file. |
---|
282 | |
---|
283 | If `filepath` is not given, a string with the data should be |
---|
284 | returned. |
---|
285 | |
---|
286 | What kind of iterables are acceptable depends on the specific |
---|
287 | exporter implementation. |
---|
288 | """ |
---|
289 | |
---|
290 | def export_all(site, filapath=None): |
---|
291 | """Export all items in `site` as CSV file. |
---|
292 | |
---|
293 | if `filepath` is not given, a string with the data should be |
---|
294 | returned. |
---|
295 | """ |
---|
296 | |
---|
297 | class IKofaExporter(Interface): |
---|
298 | """An exporter for objects. |
---|
299 | """ |
---|
300 | def export(obj, filepath=None): |
---|
301 | """Export by pickling. |
---|
302 | |
---|
303 | Returns a file-like object containing a representation of `obj`. |
---|
304 | |
---|
305 | This is done using `pickle`. If `filepath` is ``None``, a |
---|
306 | `cStringIO` object is returned, that contains the saved data. |
---|
307 | """ |
---|
308 | |
---|
309 | class IKofaXMLExporter(Interface): |
---|
310 | """An XML exporter for objects. |
---|
311 | """ |
---|
312 | def export(obj, filepath=None): |
---|
313 | """Export as XML. |
---|
314 | |
---|
315 | Returns an XML representation of `obj`. |
---|
316 | |
---|
317 | If `filepath` is ``None``, a StringIO` object is returned, |
---|
318 | that contains the transformed data. |
---|
319 | """ |
---|
320 | |
---|
321 | class IKofaXMLImporter(Interface): |
---|
322 | """An XML import for objects. |
---|
323 | """ |
---|
324 | def doImport(filepath): |
---|
325 | """Create Python object from XML. |
---|
326 | |
---|
327 | Returns a Python object. |
---|
328 | """ |
---|
329 | |
---|
330 | class IBatchProcessor(Interface): |
---|
331 | """A batch processor that handles mass-operations. |
---|
332 | """ |
---|
333 | name = schema.TextLine( |
---|
334 | title = _(u'Processor name') |
---|
335 | ) |
---|
336 | |
---|
337 | def doImport(path, headerfields, mode='create', user='Unknown', |
---|
338 | logger=None, ignore_empty=True): |
---|
339 | """Read data from ``path`` and update connected object. |
---|
340 | |
---|
341 | `headerfields` is a list of headerfields as read from the file |
---|
342 | to import. |
---|
343 | |
---|
344 | `mode` gives the import mode to use (``'create'``, |
---|
345 | ``'update'``, or ``'remove'``. |
---|
346 | |
---|
347 | `user` is a string describing the user performing the |
---|
348 | import. Normally fetched from current principal. |
---|
349 | |
---|
350 | `logger` is the logger to use during import. |
---|
351 | |
---|
352 | `ignore_emtpy` in update mode ignores empty fields if true. |
---|
353 | """ |
---|
354 | |
---|
355 | class IContactForm(IKofaObject): |
---|
356 | """A contact form. |
---|
357 | """ |
---|
358 | |
---|
359 | email_from = schema.ASCIILine( |
---|
360 | title = _(u'Email Address:'), |
---|
361 | default = None, |
---|
362 | required = True, |
---|
363 | constraint=validate_email, |
---|
364 | ) |
---|
365 | |
---|
366 | email_to = schema.ASCIILine( |
---|
367 | title = _(u'Email to:'), |
---|
368 | default = None, |
---|
369 | required = True, |
---|
370 | constraint=validate_email, |
---|
371 | ) |
---|
372 | |
---|
373 | subject = schema.TextLine( |
---|
374 | title = _(u'Subject:'), |
---|
375 | required = True,) |
---|
376 | |
---|
377 | fullname = schema.TextLine( |
---|
378 | title = _(u'Full Name:'), |
---|
379 | required = True,) |
---|
380 | |
---|
381 | body = schema.Text( |
---|
382 | title = _(u'Text:'), |
---|
383 | required = True,) |
---|
384 | |
---|
385 | class IKofaPrincipalInfo(IPrincipalInfo): |
---|
386 | """Infos about principals that are users of Kofa Kofa. |
---|
387 | """ |
---|
388 | email = Attribute("The email address of a user") |
---|
389 | phone = Attribute("The phone number of a user") |
---|
390 | public_name = Attribute("The public name of a user") |
---|
391 | |
---|
392 | |
---|
393 | class IKofaPrincipal(IPrincipal): |
---|
394 | """A principle for Kofa Kofa. |
---|
395 | |
---|
396 | This interface extends zope.security.interfaces.IPrincipal and |
---|
397 | requires also an `id` and other attributes defined there. |
---|
398 | """ |
---|
399 | |
---|
400 | email = schema.TextLine( |
---|
401 | title = _(u'Email Address'), |
---|
402 | description = u'', |
---|
403 | required=False,) |
---|
404 | |
---|
405 | phone = PhoneNumber( |
---|
406 | title = _(u'Phone'), |
---|
407 | description = u'', |
---|
408 | required=False,) |
---|
409 | |
---|
410 | public_name = schema.TextLine( |
---|
411 | title = _(u'Public Name'), |
---|
412 | required = False,) |
---|
413 | |
---|
414 | class IUserAccount(IKofaObject): |
---|
415 | """A user account. |
---|
416 | """ |
---|
417 | name = schema.TextLine( |
---|
418 | title = _(u'User Id'), |
---|
419 | description = u'Login name of user', |
---|
420 | required = True,) |
---|
421 | |
---|
422 | title = schema.TextLine( |
---|
423 | title = _(u'Full Name'), |
---|
424 | required = True,) |
---|
425 | |
---|
426 | public_name = schema.TextLine( |
---|
427 | title = _(u'Public Name'), |
---|
428 | description = u"Substitute for officer's real name " |
---|
429 | "in student object histories.", |
---|
430 | required = False,) |
---|
431 | |
---|
432 | description = schema.Text( |
---|
433 | title = _(u'Description/Notice'), |
---|
434 | required = False,) |
---|
435 | |
---|
436 | email = schema.ASCIILine( |
---|
437 | title = _(u'Email Address'), |
---|
438 | default = None, |
---|
439 | required = True, |
---|
440 | constraint=validate_email, |
---|
441 | ) |
---|
442 | |
---|
443 | phone = PhoneNumber( |
---|
444 | title = _(u'Phone'), |
---|
445 | default = None, |
---|
446 | required = False, |
---|
447 | ) |
---|
448 | |
---|
449 | roles = schema.List( |
---|
450 | title = _(u'Portal Roles'), |
---|
451 | value_type = schema.Choice(source=RoleSource()), |
---|
452 | required = False, |
---|
453 | ) |
---|
454 | |
---|
455 | class IPasswordValidator(Interface): |
---|
456 | """A password validator utility. |
---|
457 | """ |
---|
458 | |
---|
459 | def validate_password(password, password_repeat): |
---|
460 | """Validates a password by comparing it with |
---|
461 | control password and checking some other requirements. |
---|
462 | """ |
---|
463 | |
---|
464 | |
---|
465 | class IUsersContainer(IKofaObject): |
---|
466 | """A container for users (principals). |
---|
467 | |
---|
468 | These users are used for authentication purposes. |
---|
469 | """ |
---|
470 | |
---|
471 | def addUser(name, password, title=None, description=None): |
---|
472 | """Add a user. |
---|
473 | """ |
---|
474 | |
---|
475 | def delUser(name): |
---|
476 | """Delete a user if it exists. |
---|
477 | """ |
---|
478 | |
---|
479 | class ILocalRolesAssignable(Interface): |
---|
480 | """The local roles assignable to an object. |
---|
481 | """ |
---|
482 | def __call__(): |
---|
483 | """Returns a list of dicts. |
---|
484 | |
---|
485 | Each dict contains a ``name`` referring to the role assignable |
---|
486 | for the specified object and a `title` to describe the range |
---|
487 | of users to which this role can be assigned. |
---|
488 | """ |
---|
489 | |
---|
490 | class IConfigurationContainer(IKofaObject): |
---|
491 | """A container for session configuration objects. |
---|
492 | """ |
---|
493 | |
---|
494 | name = schema.TextLine( |
---|
495 | title = _(u'Name of University'), |
---|
496 | default = _(u'Sample University'), |
---|
497 | required = True, |
---|
498 | ) |
---|
499 | |
---|
500 | acronym = schema.TextLine( |
---|
501 | title = _(u'Abbreviated Title of University'), |
---|
502 | default = u'WAeUP.Kofa', |
---|
503 | required = True, |
---|
504 | ) |
---|
505 | |
---|
506 | skin = schema.Choice( |
---|
507 | title = _(u'Skin'), |
---|
508 | default = u'gray waeup theme', |
---|
509 | vocabulary = 'waeup.kofa.browser.theming.ThemesVocabulary', |
---|
510 | required = True, |
---|
511 | ) |
---|
512 | |
---|
513 | frontpage = schema.Text( |
---|
514 | title = _(u'Content in HTML format'), |
---|
515 | required = False, |
---|
516 | default = default_html_frontpage, |
---|
517 | ) |
---|
518 | |
---|
519 | frontpage_dict = schema.Dict( |
---|
520 | title = u'Content as language dictionary with values in html format', |
---|
521 | required = False, |
---|
522 | default = {}, |
---|
523 | ) |
---|
524 | |
---|
525 | name_admin = schema.TextLine( |
---|
526 | title = _(u'Name of Administrator'), |
---|
527 | default = u'Administrator', |
---|
528 | required = True, |
---|
529 | ) |
---|
530 | |
---|
531 | email_admin = schema.ASCIILine( |
---|
532 | title = _(u'Email Address of Administrator'), |
---|
533 | default = 'contact@waeup.org', |
---|
534 | required = True, |
---|
535 | constraint=validate_email, |
---|
536 | ) |
---|
537 | |
---|
538 | email_subject = schema.TextLine( |
---|
539 | title = _(u'Subject of Email to Administrator'), |
---|
540 | default = _(u'Kofa Contact'), |
---|
541 | required = True, |
---|
542 | ) |
---|
543 | |
---|
544 | smtp_mailer = schema.Choice( |
---|
545 | title = _(u'SMTP mailer to use when sending mail'), |
---|
546 | vocabulary = 'Mail Delivery Names', |
---|
547 | default = 'No email service', |
---|
548 | required = True, |
---|
549 | ) |
---|
550 | |
---|
551 | captcha = schema.Choice( |
---|
552 | title = _(u'Captcha used for public registration pages'), |
---|
553 | source = CaptchaSource(), |
---|
554 | default = u'No captcha', |
---|
555 | required = True, |
---|
556 | ) |
---|
557 | |
---|
558 | carry_over = schema.Bool( |
---|
559 | title = _(u'Carry-over Course Registration'), |
---|
560 | default = False, |
---|
561 | ) |
---|
562 | |
---|
563 | class ISessionConfiguration(IKofaObject): |
---|
564 | """A session configuration object. |
---|
565 | """ |
---|
566 | |
---|
567 | academic_session = schema.Choice( |
---|
568 | title = _(u'Academic Session'), |
---|
569 | source = academic_sessions_vocab, |
---|
570 | default = None, |
---|
571 | required = True, |
---|
572 | readonly = True, |
---|
573 | ) |
---|
574 | |
---|
575 | application_fee = schema.Float( |
---|
576 | title = _(u'Application Fee'), |
---|
577 | default = 0.0, |
---|
578 | required = False, |
---|
579 | ) |
---|
580 | |
---|
581 | clearance_fee = schema.Float( |
---|
582 | title = _(u'Clearance Fee'), |
---|
583 | default = 0.0, |
---|
584 | required = False, |
---|
585 | ) |
---|
586 | |
---|
587 | booking_fee = schema.Float( |
---|
588 | title = _(u'Bed Booking Fee'), |
---|
589 | default = 0.0, |
---|
590 | required = False, |
---|
591 | ) |
---|
592 | |
---|
593 | def getSessionString(): |
---|
594 | """Returns the session string from the vocabulary. |
---|
595 | """ |
---|
596 | |
---|
597 | |
---|
598 | class ISessionConfigurationAdd(ISessionConfiguration): |
---|
599 | """A session configuration object in add mode. |
---|
600 | """ |
---|
601 | |
---|
602 | academic_session = schema.Choice( |
---|
603 | title = _(u'Academic Session'), |
---|
604 | source = academic_sessions_vocab, |
---|
605 | default = None, |
---|
606 | required = True, |
---|
607 | readonly = False, |
---|
608 | ) |
---|
609 | |
---|
610 | ISessionConfigurationAdd['academic_session'].order = ISessionConfiguration[ |
---|
611 | 'academic_session'].order |
---|
612 | |
---|
613 | class IDataCenter(IKofaObject): |
---|
614 | """A data center. |
---|
615 | |
---|
616 | A data center manages files (uploads, downloads, etc.). |
---|
617 | |
---|
618 | Beside providing the bare paths needed to keep files, it also |
---|
619 | provides some helpers to put results of batch processing into |
---|
620 | well-defined final locations (with well-defined filenames). |
---|
621 | |
---|
622 | The main use-case is managing of site-related files, i.e. files |
---|
623 | for import, export etc. |
---|
624 | |
---|
625 | DataCenters are _not_ meant as storages for object-specific files |
---|
626 | like passport photographs and similar. |
---|
627 | |
---|
628 | It is up to the datacenter implementation how to organize data |
---|
629 | (paths) inside its storage path. |
---|
630 | """ |
---|
631 | storage = schema.Bytes( |
---|
632 | title = u'Path to directory where everything is kept.' |
---|
633 | ) |
---|
634 | |
---|
635 | deleted_path = schema.Bytes( |
---|
636 | title = u'Path were data about deleted objects should be stored.' |
---|
637 | ) |
---|
638 | |
---|
639 | def getPendingFiles(sort='name'): |
---|
640 | """Get a list of files stored in `storage` sorted by basename. |
---|
641 | """ |
---|
642 | |
---|
643 | def getFinishedFiles(): |
---|
644 | """Get a list of files stored in `finished` subfolder of `storage`. |
---|
645 | """ |
---|
646 | |
---|
647 | def setStoragePath(path, move=False, overwrite=False): |
---|
648 | """Set the path where to store files. |
---|
649 | |
---|
650 | If `move` is True, move over files from the current location |
---|
651 | to the new one. |
---|
652 | |
---|
653 | If `overwrite` is also True, overwrite any already existing |
---|
654 | files of same name in target location. |
---|
655 | |
---|
656 | Triggers a DataCenterStorageMovedEvent. |
---|
657 | """ |
---|
658 | |
---|
659 | def distProcessedFiles(successful, source_path, finished_file, |
---|
660 | pending_file, mode='create', move_orig=True): |
---|
661 | """Distribute processed files over final locations. |
---|
662 | """ |
---|
663 | |
---|
664 | |
---|
665 | class IDataCenterFile(Interface): |
---|
666 | """A data center file. |
---|
667 | """ |
---|
668 | |
---|
669 | name = schema.TextLine( |
---|
670 | title = u'Filename') |
---|
671 | |
---|
672 | size = schema.TextLine( |
---|
673 | title = u'Human readable file size') |
---|
674 | |
---|
675 | uploaddate = schema.TextLine( |
---|
676 | title = u'Human readable upload datetime') |
---|
677 | |
---|
678 | lines = schema.Int( |
---|
679 | title = u'Number of lines in file') |
---|
680 | |
---|
681 | def getDate(): |
---|
682 | """Get creation timestamp from file in human readable form. |
---|
683 | """ |
---|
684 | |
---|
685 | def getSize(): |
---|
686 | """Get human readable size of file. |
---|
687 | """ |
---|
688 | |
---|
689 | def getLinesNumber(): |
---|
690 | """Get number of lines of file. |
---|
691 | """ |
---|
692 | |
---|
693 | class IDataCenterStorageMovedEvent(IObjectEvent): |
---|
694 | """Emitted, when the storage of a datacenter changes. |
---|
695 | """ |
---|
696 | |
---|
697 | class IObjectUpgradeEvent(IObjectEvent): |
---|
698 | """Can be fired, when an object shall be upgraded. |
---|
699 | """ |
---|
700 | |
---|
701 | class ILocalRoleSetEvent(IObjectEvent): |
---|
702 | """A local role was granted/revoked for a principal on an object. |
---|
703 | """ |
---|
704 | role_id = Attribute( |
---|
705 | "The role id that was set.") |
---|
706 | principal_id = Attribute( |
---|
707 | "The principal id for which the role was granted/revoked.") |
---|
708 | granted = Attribute( |
---|
709 | "Boolean. If false, then the role was revoked.") |
---|
710 | |
---|
711 | class IQueryResultItem(Interface): |
---|
712 | """An item in a search result. |
---|
713 | """ |
---|
714 | url = schema.TextLine( |
---|
715 | title = u'URL that links to the found item') |
---|
716 | title = schema.TextLine( |
---|
717 | title = u'Title displayed in search results.') |
---|
718 | description = schema.Text( |
---|
719 | title = u'Longer description of the item found.') |
---|
720 | |
---|
721 | class IKofaPluggable(Interface): |
---|
722 | """A component that might be plugged into a Kofa Kofa app. |
---|
723 | |
---|
724 | Components implementing this interface are referred to as |
---|
725 | 'plugins'. They are normally called when a new |
---|
726 | :class:`waeup.kofa.app.University` instance is created. |
---|
727 | |
---|
728 | Plugins can setup and update parts of the central site without the |
---|
729 | site object (normally a :class:`waeup.kofa.app.University` object) |
---|
730 | needing to know about that parts. The site simply collects all |
---|
731 | available plugins, calls them and the plugins care for their |
---|
732 | respective subarea like the applicants area or the datacenter |
---|
733 | area. |
---|
734 | |
---|
735 | Currently we have no mechanism to define an order of plugins. A |
---|
736 | plugin should therefore make no assumptions about the state of the |
---|
737 | site or other plugins being run before and instead do appropriate |
---|
738 | checks if necessary. |
---|
739 | |
---|
740 | Updates can be triggered for instance by the respective form in |
---|
741 | the site configuration. You normally do updates when the |
---|
742 | underlying software changed. |
---|
743 | """ |
---|
744 | def setup(site, name, logger): |
---|
745 | """Create an instance of the plugin. |
---|
746 | |
---|
747 | The method is meant to be called by the central app (site) |
---|
748 | when it is created. |
---|
749 | |
---|
750 | `site`: |
---|
751 | The site that requests a setup. |
---|
752 | |
---|
753 | `name`: |
---|
754 | The name under which the plugin was registered (utility name). |
---|
755 | |
---|
756 | `logger`: |
---|
757 | A standard Python logger for the plugins use. |
---|
758 | """ |
---|
759 | |
---|
760 | def update(site, name, logger): |
---|
761 | """Method to update an already existing plugin. |
---|
762 | |
---|
763 | This might be called by a site when something serious |
---|
764 | changes. It is a poor-man replacement for Zope generations |
---|
765 | (but probably more comprehensive and better understandable). |
---|
766 | |
---|
767 | `site`: |
---|
768 | The site that requests an update. |
---|
769 | |
---|
770 | `name`: |
---|
771 | The name under which the plugin was registered (utility name). |
---|
772 | |
---|
773 | `logger`: |
---|
774 | A standard Python logger for the plugins use. |
---|
775 | """ |
---|
776 | |
---|
777 | class IAuthPluginUtility(Interface): |
---|
778 | """A component that cares for authentication setup at site creation. |
---|
779 | |
---|
780 | Utilities providing this interface are looked up when a Pluggable |
---|
781 | Authentication Utility (PAU) for any |
---|
782 | :class:`waeup.kofa.app.University` instance is created and put |
---|
783 | into ZODB. |
---|
784 | |
---|
785 | The setup-code then calls the `register` method of the utility and |
---|
786 | expects a modified (or unmodified) version of the PAU back. |
---|
787 | |
---|
788 | This allows to define any authentication setup modifications by |
---|
789 | submodules or third-party modules/packages. |
---|
790 | """ |
---|
791 | |
---|
792 | def register(pau): |
---|
793 | """Register any plugins wanted to be in the PAU. |
---|
794 | """ |
---|
795 | |
---|
796 | def unregister(pau): |
---|
797 | """Unregister any plugins not wanted to be in the PAU. |
---|
798 | """ |
---|
799 | |
---|
800 | class IObjectConverter(Interface): |
---|
801 | """Object converters are available as simple adapters, adapting |
---|
802 | interfaces (not regular instances). |
---|
803 | |
---|
804 | """ |
---|
805 | |
---|
806 | def fromStringDict(self, data_dict, context, form_fields=None): |
---|
807 | """Convert values in `data_dict`. |
---|
808 | |
---|
809 | Converts data in `data_dict` into real values based on |
---|
810 | `context` and `form_fields`. |
---|
811 | |
---|
812 | `data_dict` is a mapping (dict) from field names to values |
---|
813 | represented as strings. |
---|
814 | |
---|
815 | The fields (keys) to convert can be given in optional |
---|
816 | `form_fields`. If given, form_fields should be an instance of |
---|
817 | :class:`zope.formlib.form.Fields`. Suitable instances are for |
---|
818 | example created by :class:`grok.AutoFields`. |
---|
819 | |
---|
820 | If no `form_fields` are given, a default is computed from the |
---|
821 | associated interface. |
---|
822 | |
---|
823 | The `context` can be an existing object (implementing the |
---|
824 | associated interface) or a factory name. If it is a string, we |
---|
825 | try to create an object using |
---|
826 | :func:`zope.component.createObject`. |
---|
827 | |
---|
828 | Returns a tuple ``(<FIELD_ERRORS>, <INVARIANT_ERRORS>, |
---|
829 | <DATA_DICT>)`` where |
---|
830 | |
---|
831 | ``<FIELD_ERRORS>`` |
---|
832 | is a list of tuples ``(<FIELD_NAME>, <ERROR>)`` for each |
---|
833 | error that happened when validating the input data in |
---|
834 | `data_dict` |
---|
835 | |
---|
836 | ``<INVARIANT_ERRORS>`` |
---|
837 | is a list of invariant errors concerning several fields |
---|
838 | |
---|
839 | ``<DATA_DICT>`` |
---|
840 | is a dict with the values from input dict converted. |
---|
841 | |
---|
842 | If errors happen, i.e. the error lists are not empty, always |
---|
843 | an empty ``<DATA_DICT>`` is returned. |
---|
844 | |
---|
845 | If ``<DATA_DICT>` is non-empty, there were no errors. |
---|
846 | """ |
---|
847 | |
---|
848 | class IFieldConverter(Interface): |
---|
849 | def request_data(name, value, schema_field, prefix='', mode='create'): |
---|
850 | """Create a dict with key-value mapping as created by a request. |
---|
851 | |
---|
852 | `name` and `value` are expected to be parsed from CSV or a |
---|
853 | similar input and represent an attribute to be set to a |
---|
854 | representation of value. |
---|
855 | |
---|
856 | `mode` gives the mode of import. |
---|
857 | |
---|
858 | :meth:`update_request_data` is then requested to turn this |
---|
859 | name and value into vars as they would be sent by a regular |
---|
860 | form submit. This means we do not create the real values to be |
---|
861 | set but we only define the values that would be sent in a |
---|
862 | browser request to request the creation of those values. |
---|
863 | |
---|
864 | The returned dict should contain names and values of a faked |
---|
865 | browser request for the given `schema_field`. |
---|
866 | |
---|
867 | Field converters are normally registered as adapters to some |
---|
868 | specific zope.schema field. |
---|
869 | """ |
---|
870 | |
---|
871 | class IObjectHistory(Interface): |
---|
872 | |
---|
873 | messages = schema.List( |
---|
874 | title = u'List of messages stored', |
---|
875 | required = True, |
---|
876 | ) |
---|
877 | |
---|
878 | def addMessage(message): |
---|
879 | """Add a message. |
---|
880 | """ |
---|
881 | |
---|
882 | class IKofaWorkflowInfo(IWorkflowInfo): |
---|
883 | """A :class:`hurry.workflow.workflow.WorkflowInfo` with additional |
---|
884 | methods for convenience. |
---|
885 | """ |
---|
886 | def getManualTransitions(): |
---|
887 | """Get allowed manual transitions. |
---|
888 | |
---|
889 | Get a sorted list of tuples containing the `transition_id` and |
---|
890 | `title` of each allowed transition. |
---|
891 | """ |
---|
892 | |
---|
893 | class ISiteLoggers(Interface): |
---|
894 | |
---|
895 | loggers = Attribute("A list or generator of registered KofaLoggers") |
---|
896 | |
---|
897 | def register(name, filename=None, site=None, **options): |
---|
898 | """Register a logger `name` which logs to `filename`. |
---|
899 | |
---|
900 | If `filename` is not given, logfile will be `name` with |
---|
901 | ``.log`` as filename extension. |
---|
902 | """ |
---|
903 | |
---|
904 | def unregister(name): |
---|
905 | """Unregister a once registered logger. |
---|
906 | """ |
---|
907 | |
---|
908 | class ILogger(Interface): |
---|
909 | """A logger cares for setup, update and restarting of a Python logger. |
---|
910 | """ |
---|
911 | |
---|
912 | logger = Attribute("""A :class:`logging.Logger` instance""") |
---|
913 | |
---|
914 | |
---|
915 | def __init__(name, filename=None, site=None, **options): |
---|
916 | """Create a Kofa logger instance. |
---|
917 | """ |
---|
918 | |
---|
919 | def setup(): |
---|
920 | """Create a Python :class:`logging.Logger` instance. |
---|
921 | |
---|
922 | The created logger is based on the params given by constructor. |
---|
923 | """ |
---|
924 | |
---|
925 | def update(**options): |
---|
926 | """Update the logger. |
---|
927 | |
---|
928 | Updates the logger respecting modified `options` and changed |
---|
929 | paths. |
---|
930 | """ |
---|
931 | |
---|
932 | class ILoggerCollector(Interface): |
---|
933 | |
---|
934 | def getLoggers(site): |
---|
935 | """Return all loggers registered for `site`. |
---|
936 | """ |
---|
937 | |
---|
938 | def registerLogger(site, logging_component): |
---|
939 | """Register a logging component residing in `site`. |
---|
940 | """ |
---|
941 | |
---|
942 | def unregisterLogger(site, logging_component): |
---|
943 | """Unregister a logger. |
---|
944 | """ |
---|
945 | |
---|
946 | # |
---|
947 | # External File Storage and relatives |
---|
948 | # |
---|
949 | class IFileStoreNameChooser(INameChooser): |
---|
950 | """See zope.container.interfaces.INameChooser for base methods. |
---|
951 | """ |
---|
952 | def checkName(name, attr=None): |
---|
953 | """Check whether an object name is valid. |
---|
954 | |
---|
955 | Raises a user error if the name is not valid. |
---|
956 | """ |
---|
957 | |
---|
958 | def chooseName(name, attr=None): |
---|
959 | """Choose a unique valid file id for the object. |
---|
960 | |
---|
961 | The given name may be taken into account when choosing the |
---|
962 | name (file id). |
---|
963 | |
---|
964 | chooseName is expected to always choose a valid file id (that |
---|
965 | would pass the checkName test) and never raise an error. |
---|
966 | |
---|
967 | If `attr` is not ``None`` it might been taken into account as |
---|
968 | well when generating the file id. Usual behaviour is to |
---|
969 | interpret `attr` as a hint for what type of file for a given |
---|
970 | context should be stored if there are several types |
---|
971 | possible. For instance for a certain student some file could |
---|
972 | be the connected passport photograph or some certificate scan |
---|
973 | or whatever. Each of them has to be stored in a different |
---|
974 | location so setting `attr` to a sensible value should give |
---|
975 | different file ids returned. |
---|
976 | """ |
---|
977 | |
---|
978 | class IExtFileStore(IFileRetrieval): |
---|
979 | """A file storage that stores files in filesystem (not as blobs). |
---|
980 | """ |
---|
981 | root = schema.TextLine( |
---|
982 | title = u'Root path of file store.', |
---|
983 | ) |
---|
984 | |
---|
985 | def getFile(file_id): |
---|
986 | """Get raw file data stored under file with `file_id`. |
---|
987 | |
---|
988 | Returns a file descriptor open for reading or ``None`` if the |
---|
989 | file cannot be found. |
---|
990 | """ |
---|
991 | |
---|
992 | def getFileByContext(context, attr=None): |
---|
993 | """Get raw file data stored for the given context. |
---|
994 | |
---|
995 | Returns a file descriptor open for reading or ``None`` if no |
---|
996 | such file can be found. |
---|
997 | |
---|
998 | Both, `context` and `attr` might be used to find (`context`) |
---|
999 | and feed (`attr`) an appropriate file name chooser. |
---|
1000 | |
---|
1001 | This is a convenience method. |
---|
1002 | """ |
---|
1003 | |
---|
1004 | def deleteFile(file_id): |
---|
1005 | """Delete file stored under `file_id`. |
---|
1006 | |
---|
1007 | Remove file from filestore so, that it is not available |
---|
1008 | anymore on next call to getFile for the same file_id. |
---|
1009 | |
---|
1010 | Should not complain if no such file exists. |
---|
1011 | """ |
---|
1012 | |
---|
1013 | def deleteFileByContext(context, attr=None): |
---|
1014 | """Delete file for given `context` and `attr`. |
---|
1015 | |
---|
1016 | Both, `context` and `attr` might be used to find (`context`) |
---|
1017 | and feed (`attr`) an appropriate file name chooser. |
---|
1018 | |
---|
1019 | This is a convenience method. |
---|
1020 | """ |
---|
1021 | |
---|
1022 | def createFile(filename, f): |
---|
1023 | """Create file given by f with filename `filename` |
---|
1024 | |
---|
1025 | Returns a hurry.file.File-based object. |
---|
1026 | """ |
---|
1027 | |
---|
1028 | class IFileStoreHandler(Interface): |
---|
1029 | """Filestore handlers handle specific files for file stores. |
---|
1030 | |
---|
1031 | If a file to store/get provides a specific filename, a file store |
---|
1032 | looks up special handlers for that type of file. |
---|
1033 | |
---|
1034 | """ |
---|
1035 | def pathFromFileID(store, root, filename): |
---|
1036 | """Turn file id into path to store. |
---|
1037 | |
---|
1038 | Returned path should be absolute. |
---|
1039 | """ |
---|
1040 | |
---|
1041 | def createFile(store, root, filename, file_id, file): |
---|
1042 | """Return some hurry.file based on `store` and `file_id`. |
---|
1043 | |
---|
1044 | Some kind of callback method called by file stores to create |
---|
1045 | file objects from file_id. |
---|
1046 | |
---|
1047 | Returns a tuple ``(raw_file, path, file_like_obj)`` where the |
---|
1048 | ``file_like_obj`` should be a HurryFile, a KofaImageFile or |
---|
1049 | similar. ``raw_file`` is the (maybe changed) input file and |
---|
1050 | ``path`` the relative internal path to store the file at. |
---|
1051 | |
---|
1052 | Please make sure the ``raw_file`` is opened for reading and |
---|
1053 | the file descriptor set at position 0 when returned. |
---|
1054 | |
---|
1055 | This method also gets the raw input file object that is about |
---|
1056 | to be stored and is expected to raise any exceptions if some |
---|
1057 | kind of validation or similar fails. |
---|
1058 | """ |
---|
1059 | |
---|
1060 | class IPDF(Interface): |
---|
1061 | """A PDF representation of some context. |
---|
1062 | """ |
---|
1063 | |
---|
1064 | def __call__(view=None, note=None): |
---|
1065 | """Create a bytestream representing a PDF from context. |
---|
1066 | |
---|
1067 | If `view` is passed in additional infos might be rendered into |
---|
1068 | the document. |
---|
1069 | |
---|
1070 | `note` is optional HTML rendered at bottom of the created |
---|
1071 | PDF. Please consider the limited reportlab support for HTML, |
---|
1072 | but using font-tags and friends you certainly can get the |
---|
1073 | desired look. |
---|
1074 | """ |
---|
1075 | |
---|
1076 | class IMailService(Interface): |
---|
1077 | """A mail service. |
---|
1078 | """ |
---|
1079 | |
---|
1080 | def __call__(): |
---|
1081 | """Get the default mail delivery. |
---|
1082 | """ |
---|
1083 | |
---|
1084 | from zope.configuration.fields import Path |
---|
1085 | class IDataCenterConfig(Interface): |
---|
1086 | path = Path( |
---|
1087 | title = u'Path', |
---|
1088 | description = u"Directory where the datacenter should store " |
---|
1089 | u"files by default (adjustable in web UI).", |
---|
1090 | required = True, |
---|
1091 | ) |
---|
1092 | |
---|
1093 | class IChangePassword(IKofaObject): |
---|
1094 | """Interface needed for change pasword page. |
---|
1095 | |
---|
1096 | """ |
---|
1097 | identifier = schema.TextLine( |
---|
1098 | title = _(u'Unique Identifier'), |
---|
1099 | description = _( |
---|
1100 | u'User Name, Student or Applicant Id, Matriculation or ' |
---|
1101 | u'Registration Number'), |
---|
1102 | required = True, |
---|
1103 | readonly = False, |
---|
1104 | ) |
---|
1105 | |
---|
1106 | email = schema.ASCIILine( |
---|
1107 | title = _(u'Email Address'), |
---|
1108 | required = True, |
---|
1109 | constraint=validate_email, |
---|
1110 | ) |
---|