1 | ## $Id: interfaces.py 15287 2019-01-09 21:17:08Z 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 zc.async.interfaces |
---|
22 | import zope.i18nmessageid |
---|
23 | from datetime import datetime |
---|
24 | from hurry.file.interfaces import IFileRetrieval |
---|
25 | from hurry.workflow.interfaces import IWorkflowInfo |
---|
26 | from zc.sourcefactory.basic import BasicSourceFactory |
---|
27 | from zope import schema |
---|
28 | from zope.pluggableauth.interfaces import IPrincipalInfo |
---|
29 | from zope.security.interfaces import IGroupClosureAwarePrincipal as IPrincipal |
---|
30 | from zope.component import getUtility |
---|
31 | from zope.component.interfaces import IObjectEvent |
---|
32 | from zope.configuration.fields import Path |
---|
33 | from zope.container.interfaces import INameChooser, IContainer |
---|
34 | from zope.interface import Interface, Attribute |
---|
35 | from zope.schema.interfaces import IObject |
---|
36 | from zope.schema.vocabulary import SimpleVocabulary, SimpleTerm |
---|
37 | from waeup.kofa.schema import PhoneNumber |
---|
38 | from waeup.kofa.sourcefactory import SmartBasicContextualSourceFactory |
---|
39 | |
---|
40 | _ = MessageFactory = zope.i18nmessageid.MessageFactory('waeup.kofa') |
---|
41 | |
---|
42 | DELETION_MARKER = 'XXX' |
---|
43 | IGNORE_MARKER = '<IGNORE>' |
---|
44 | WAEUP_KEY = 'waeup.kofa' |
---|
45 | VIRT_JOBS_CONTAINER_NAME = 'jobs' |
---|
46 | DOCLINK = 'http://kofa-doc.waeup.org/userdocs' |
---|
47 | |
---|
48 | CREATED = 'created' |
---|
49 | ADMITTED = 'admitted' |
---|
50 | CLEARANCE = 'clearance started' |
---|
51 | REQUESTED = 'clearance requested' |
---|
52 | CLEARED = 'cleared' |
---|
53 | PAID = 'school fee paid' |
---|
54 | RETURNING = 'returning' |
---|
55 | REGISTERED = 'courses registered' |
---|
56 | VALIDATED = 'courses validated' |
---|
57 | GRADUATED = 'graduated' |
---|
58 | TRANSREQ = 'transcript requested' |
---|
59 | TRANSVAL = 'transcript validated' |
---|
60 | TRANSREL = 'transcript released' |
---|
61 | |
---|
62 | |
---|
63 | #: A dict giving job status as tuple (<STRING>, <TRANSLATED_STRING>), |
---|
64 | #: the latter for UI purposes. |
---|
65 | JOB_STATUS_MAP = { |
---|
66 | zc.async.interfaces.NEW: ('new', _('new')), |
---|
67 | zc.async.interfaces.COMPLETED: ('completed', _('completed')), |
---|
68 | zc.async.interfaces.PENDING: ('pending', _('pending')), |
---|
69 | zc.async.interfaces.ACTIVE: ('active', _('active')), |
---|
70 | zc.async.interfaces.ASSIGNED: ('assigned', _('assigned')), |
---|
71 | zc.async.interfaces.CALLBACKS: ('callbacks', _('callbacks')), |
---|
72 | } |
---|
73 | |
---|
74 | #default_rest_frontpage = u'' + codecs.open(os.path.join( |
---|
75 | # os.path.dirname(__file__), 'frontpage.rst'), |
---|
76 | # encoding='utf-8', mode='rb').read() |
---|
77 | |
---|
78 | default_html_frontpage = u'' + codecs.open(os.path.join( |
---|
79 | os.path.dirname(__file__), 'frontpage.html'), |
---|
80 | encoding='utf-8', mode='rb').read() |
---|
81 | |
---|
82 | def SimpleKofaVocabulary(*terms): |
---|
83 | """A well-buildt vocabulary provides terms with a value, token and |
---|
84 | title for each term |
---|
85 | """ |
---|
86 | return SimpleVocabulary([ |
---|
87 | SimpleTerm(value, value, title) for title, value in terms]) |
---|
88 | |
---|
89 | def academic_sessions(): |
---|
90 | curr_year = datetime.now().year |
---|
91 | year_range = range(1980, curr_year + 2) |
---|
92 | return [('%s/%s' % (year,year+1), year) for year in year_range] |
---|
93 | |
---|
94 | academic_sessions_vocab = SimpleKofaVocabulary(*academic_sessions()) |
---|
95 | |
---|
96 | registration_states_vocab = SimpleKofaVocabulary( |
---|
97 | (_('created'), CREATED), |
---|
98 | (_('admitted'), ADMITTED), |
---|
99 | (_('clearance started'), CLEARANCE), |
---|
100 | (_('clearance requested'), REQUESTED), |
---|
101 | (_('cleared'), CLEARED), |
---|
102 | (_('school fee paid'), PAID), |
---|
103 | (_('courses registered'), REGISTERED), |
---|
104 | (_('courses validated'), VALIDATED), |
---|
105 | (_('returning'), RETURNING), |
---|
106 | (_('graduated'), GRADUATED), |
---|
107 | (_('transcript requested'), TRANSREQ), |
---|
108 | (_('transcript validated'), TRANSVAL), |
---|
109 | (_('transcript released'), TRANSREL), |
---|
110 | ) |
---|
111 | |
---|
112 | class ContextualDictSourceFactoryBase(SmartBasicContextualSourceFactory): |
---|
113 | """A base for contextual sources based on KofaUtils dicts. |
---|
114 | |
---|
115 | To create a real source, you have to set the `DICT_NAME` attribute |
---|
116 | which should be the name of a dictionary in KofaUtils. |
---|
117 | """ |
---|
118 | def getValues(self, context): |
---|
119 | utils = getUtility(IKofaUtils) |
---|
120 | sorted_items = sorted(getattr(utils, self.DICT_NAME).items(), |
---|
121 | key=lambda item: item[1]) |
---|
122 | return [item[0] for item in sorted_items] |
---|
123 | |
---|
124 | def getToken(self, context, value): |
---|
125 | return str(value) |
---|
126 | |
---|
127 | def getTitle(self, context, value): |
---|
128 | utils = getUtility(IKofaUtils) |
---|
129 | return getattr(utils, self.DICT_NAME)[value] |
---|
130 | |
---|
131 | class SubjectSource(BasicSourceFactory): |
---|
132 | """A source for school subjects used in exam documentation. |
---|
133 | """ |
---|
134 | def getValues(self): |
---|
135 | subjects_dict = getUtility(IKofaUtils).EXAM_SUBJECTS_DICT |
---|
136 | return sorted(subjects_dict.keys()) |
---|
137 | |
---|
138 | def getTitle(self, value): |
---|
139 | subjects_dict = getUtility(IKofaUtils).EXAM_SUBJECTS_DICT |
---|
140 | return "%s:" % subjects_dict[value] |
---|
141 | |
---|
142 | class GradeSource(BasicSourceFactory): |
---|
143 | """A source for exam grades. |
---|
144 | """ |
---|
145 | def getValues(self): |
---|
146 | for entry in getUtility(IKofaUtils).EXAM_GRADES: |
---|
147 | yield entry[0] |
---|
148 | |
---|
149 | def getTitle(self, value): |
---|
150 | return dict(getUtility(IKofaUtils).EXAM_GRADES)[value] |
---|
151 | |
---|
152 | class DisablePaymentGroupSource(ContextualDictSourceFactoryBase): |
---|
153 | """A source for filtering groups of students |
---|
154 | """ |
---|
155 | #: name of dict to deliver from kofa utils. |
---|
156 | DICT_NAME = 'DISABLE_PAYMENT_GROUP_DICT' |
---|
157 | |
---|
158 | # Define a validation method for email addresses |
---|
159 | class NotAnEmailAddress(schema.ValidationError): |
---|
160 | __doc__ = u"Invalid email address" |
---|
161 | |
---|
162 | #: Regular expression to check email-address formats. As these can |
---|
163 | #: become rather complex (nearly everything is allowed by RFCs), we only |
---|
164 | #: forbid whitespaces, commas and dots following onto each other. |
---|
165 | check_email = re.compile( |
---|
166 | r"^[^@\s,]+@[^@\.\s,]+(\.[^@\.\s,]+)*$").match |
---|
167 | |
---|
168 | def validate_email(value): |
---|
169 | if not check_email(value): |
---|
170 | raise NotAnEmailAddress(value) |
---|
171 | return True |
---|
172 | |
---|
173 | # Define a validation method for ids |
---|
174 | class NotIdValue(schema.ValidationError): |
---|
175 | __doc__ = u"Invalid id" |
---|
176 | |
---|
177 | #: Regular expressions to check id formats. |
---|
178 | check_id = re.compile(r"^[a-zA-Z0-9_-]{2,11}$").match |
---|
179 | |
---|
180 | def validate_id(value): |
---|
181 | if not check_id(value): |
---|
182 | raise NotIdValue(value) |
---|
183 | return True |
---|
184 | |
---|
185 | # Define a validation method for HTML fields |
---|
186 | class NotHTMLValue(schema.ValidationError): |
---|
187 | __doc__ = u"Style or script elements not allowed" |
---|
188 | |
---|
189 | def validate_html(value): |
---|
190 | if '<style' in value or '<script' in value: |
---|
191 | raise NotHTMLValue(value) |
---|
192 | return True |
---|
193 | |
---|
194 | # Define a validation method for international phone numbers |
---|
195 | class InvalidPhoneNumber(schema.ValidationError): |
---|
196 | __doc__ = u"Invalid phone number" |
---|
197 | |
---|
198 | # represent format +NNN-NNNN-NNNN |
---|
199 | RE_INT_PHONE = re.compile(r"^\+?\d+\-\d+\-[\d\-]+$") |
---|
200 | |
---|
201 | def validate_phone(value): |
---|
202 | if not RE_INT_PHONE.match(value): |
---|
203 | raise InvalidPhoneNumber(value) |
---|
204 | return True |
---|
205 | |
---|
206 | class FatalCSVError(Exception): |
---|
207 | """Some row could not be processed. |
---|
208 | """ |
---|
209 | pass |
---|
210 | |
---|
211 | class DuplicationError(Exception): |
---|
212 | """An exception that can be raised when duplicates are found. |
---|
213 | |
---|
214 | When raising :exc:`DuplicationError` you can, beside the usual |
---|
215 | message, specify a list of objects which are duplicates. These |
---|
216 | values can be used by catching code to print something helpful or |
---|
217 | similar. |
---|
218 | """ |
---|
219 | def __init__(self, msg, entries=[]): |
---|
220 | self.msg = msg |
---|
221 | self.entries = entries |
---|
222 | |
---|
223 | def __str__(self): |
---|
224 | return '%r' % self.msg |
---|
225 | |
---|
226 | class RoleSource(BasicSourceFactory): |
---|
227 | """A source for site roles. |
---|
228 | """ |
---|
229 | def getValues(self): |
---|
230 | # late import: in interfaces we should not import local modules |
---|
231 | from waeup.kofa.permissions import get_waeup_role_names |
---|
232 | return get_waeup_role_names() |
---|
233 | |
---|
234 | def getTitle(self, value): |
---|
235 | # late import: in interfaces we should not import local modules |
---|
236 | from waeup.kofa.permissions import get_all_roles |
---|
237 | roles = dict(get_all_roles()) |
---|
238 | if value in roles.keys(): |
---|
239 | title = roles[value].title |
---|
240 | if '.' in title: |
---|
241 | title = title.split('.', 2)[1] |
---|
242 | return title |
---|
243 | |
---|
244 | class CaptchaSource(BasicSourceFactory): |
---|
245 | """A source for captchas. |
---|
246 | """ |
---|
247 | def getValues(self): |
---|
248 | captchas = ['No captcha', 'Testing captcha', 'ReCaptcha'] |
---|
249 | try: |
---|
250 | # we have to 'try' because IConfiguration can only handle |
---|
251 | # interfaces from w.k.interface. |
---|
252 | from waeup.kofa.browser.interfaces import ICaptchaManager |
---|
253 | except: |
---|
254 | return captchas |
---|
255 | return sorted(getUtility(ICaptchaManager).getAvailCaptchas().keys()) |
---|
256 | |
---|
257 | def getTitle(self, value): |
---|
258 | return value |
---|
259 | |
---|
260 | class IResultEntry(Interface): |
---|
261 | """A school grade entry. |
---|
262 | """ |
---|
263 | |
---|
264 | subject = schema.Choice( |
---|
265 | title = _(u'Subject'), |
---|
266 | source = SubjectSource(), |
---|
267 | ) |
---|
268 | |
---|
269 | grade = schema.Choice( |
---|
270 | title = _(u'Grade'), |
---|
271 | source = GradeSource(), |
---|
272 | ) |
---|
273 | |
---|
274 | class IResultEntryField(IObject): |
---|
275 | """A zope.schema-like field for usage in interfaces. |
---|
276 | |
---|
277 | Marker interface to distuingish result entries from ordinary |
---|
278 | object fields. Needed for registration of widgets. |
---|
279 | """ |
---|
280 | |
---|
281 | class IRefereeEntry(Interface): |
---|
282 | """A referee entry. |
---|
283 | """ |
---|
284 | email_sent = Attribute('True if email has been sent') |
---|
285 | |
---|
286 | name = schema.TextLine( |
---|
287 | title = _(u'Name'), |
---|
288 | required = True, |
---|
289 | description = _(u'Name'), |
---|
290 | ) |
---|
291 | |
---|
292 | email = schema.ASCIILine( |
---|
293 | title = _(u'Email Address'), |
---|
294 | default = None, |
---|
295 | required = True, |
---|
296 | constraint=validate_email, |
---|
297 | description = _( |
---|
298 | u'Email Address (referees will be automatically invited by email ' |
---|
299 | 'after final submission of this form)'), |
---|
300 | ) |
---|
301 | |
---|
302 | class IRefereeEntryField(IObject): |
---|
303 | """A zope.schema-like field for usage in interfaces. |
---|
304 | |
---|
305 | Marker interface to distuingish result entries from ordinary |
---|
306 | object fields. Needed for registration of widgets. |
---|
307 | """ |
---|
308 | |
---|
309 | class IKofaUtils(Interface): |
---|
310 | """A collection of methods which are subject to customization. |
---|
311 | """ |
---|
312 | |
---|
313 | PORTAL_LANGUAGE = Attribute("Dict of global language setting") |
---|
314 | PREFERRED_LANGUAGES_DICT = Attribute("Dict of preferred languages") |
---|
315 | EXAM_SUBJECTS_DICT = Attribute("Dict of examination subjects") |
---|
316 | EXAM_GRADES = Attribute("Dict of examination grades") |
---|
317 | INST_TYPES_DICT = Attribute("Dict if institution types") |
---|
318 | STUDY_MODES_DICT = Attribute("Dict of study modes") |
---|
319 | APP_CATS_DICT = Attribute("Dict of application categories") |
---|
320 | SEMESTER_DICT = Attribute("Dict of semesters or trimesters") |
---|
321 | SYSTEM_MAX_LOAD = Attribute("Dict of maximum system loads.") |
---|
322 | |
---|
323 | def sendContactForm( |
---|
324 | from_name,from_addr,rcpt_name,rcpt_addr, |
---|
325 | from_username,usertype,portal,body,subject): |
---|
326 | """Send an email with data provided by forms. |
---|
327 | """ |
---|
328 | |
---|
329 | def fullname(firstname,lastname,middlename): |
---|
330 | """Full name constructor. |
---|
331 | """ |
---|
332 | |
---|
333 | def sendCredentials(user, password, url_info, msg): |
---|
334 | """Send credentials as email. |
---|
335 | |
---|
336 | Input is the applicant for which credentials are sent and the |
---|
337 | password. |
---|
338 | |
---|
339 | Returns True or False to indicate successful operation. |
---|
340 | """ |
---|
341 | |
---|
342 | def genPassword(length, chars): |
---|
343 | """Generate a random password. |
---|
344 | """ |
---|
345 | |
---|
346 | class IKofaObject(Interface): |
---|
347 | """A Kofa object. |
---|
348 | |
---|
349 | This is merely a marker interface. |
---|
350 | """ |
---|
351 | |
---|
352 | class IUniversity(IKofaObject): |
---|
353 | """Representation of a university. |
---|
354 | """ |
---|
355 | |
---|
356 | |
---|
357 | class IKofaContainer(IKofaObject): |
---|
358 | """A container for Kofa objects. |
---|
359 | """ |
---|
360 | |
---|
361 | class IKofaContained(IKofaObject): |
---|
362 | """An item contained in an IKofaContainer. |
---|
363 | """ |
---|
364 | |
---|
365 | class ICSVExporter(Interface): |
---|
366 | """A CSV file exporter for objects. |
---|
367 | """ |
---|
368 | fields = Attribute("""List of fieldnames in resulting CSV""") |
---|
369 | |
---|
370 | title = schema.TextLine( |
---|
371 | title = u'Title', |
---|
372 | description = u'Description to be displayed in selections.', |
---|
373 | ) |
---|
374 | def mangle_value(value, name, obj): |
---|
375 | """Mangle `value` extracted from `obj` or suobjects thereof. |
---|
376 | |
---|
377 | This is called by export before actually writing to the result |
---|
378 | file. |
---|
379 | """ |
---|
380 | |
---|
381 | def get_filtered(site, **kw): |
---|
382 | """Get datasets in `site` to be exported. |
---|
383 | |
---|
384 | The set of data is specified by keywords, which might be |
---|
385 | different for any implementaion of exporter. |
---|
386 | |
---|
387 | Returns an iterable. |
---|
388 | """ |
---|
389 | |
---|
390 | def get_selected(site, selected): |
---|
391 | """Get datasets in `site` to be exported. |
---|
392 | |
---|
393 | The set of data is specified by a list of identifiers. |
---|
394 | |
---|
395 | Returns an iterable. |
---|
396 | """ |
---|
397 | |
---|
398 | def export(iterable, filepath=None): |
---|
399 | """Export iterables as rows in a CSV file. |
---|
400 | |
---|
401 | If `filepath` is not given, a string with the data should be |
---|
402 | returned. |
---|
403 | |
---|
404 | What kind of iterables are acceptable depends on the specific |
---|
405 | exporter implementation. |
---|
406 | """ |
---|
407 | |
---|
408 | def export_all(site, filepath=None): |
---|
409 | """Export all items in `site` as CSV file. |
---|
410 | |
---|
411 | if `filepath` is not given, a string with the data should be |
---|
412 | returned. |
---|
413 | """ |
---|
414 | |
---|
415 | def export_filtered(site, filepath=None, **kw): |
---|
416 | """Export those items in `site` specified by `args` and `kw`. |
---|
417 | |
---|
418 | If `filepath` is not given, a string with the data should be |
---|
419 | returned. |
---|
420 | |
---|
421 | Which special keywords are supported is up to the respective |
---|
422 | exporter. |
---|
423 | """ |
---|
424 | |
---|
425 | def export_selected(site, filepath=None, **kw): |
---|
426 | """Export items in `site` specified by a list of identifiers |
---|
427 | called `selected`. |
---|
428 | |
---|
429 | If `filepath` is not given, a string with the data should be |
---|
430 | returned. |
---|
431 | """ |
---|
432 | |
---|
433 | class IKofaExporter(Interface): |
---|
434 | """An exporter for objects. |
---|
435 | """ |
---|
436 | def export(obj, filepath=None): |
---|
437 | """Export by pickling. |
---|
438 | |
---|
439 | Returns a file-like object containing a representation of `obj`. |
---|
440 | |
---|
441 | This is done using `pickle`. If `filepath` is ``None``, a |
---|
442 | `cStringIO` object is returned, that contains the saved data. |
---|
443 | """ |
---|
444 | |
---|
445 | class IKofaXMLExporter(Interface): |
---|
446 | """An XML exporter for objects. |
---|
447 | """ |
---|
448 | def export(obj, filepath=None): |
---|
449 | """Export as XML. |
---|
450 | |
---|
451 | Returns an XML representation of `obj`. |
---|
452 | |
---|
453 | If `filepath` is ``None``, a StringIO` object is returned, |
---|
454 | that contains the transformed data. |
---|
455 | """ |
---|
456 | |
---|
457 | class IKofaXMLImporter(Interface): |
---|
458 | """An XML import for objects. |
---|
459 | """ |
---|
460 | def doImport(filepath): |
---|
461 | """Create Python object from XML. |
---|
462 | |
---|
463 | Returns a Python object. |
---|
464 | """ |
---|
465 | |
---|
466 | class IBatchProcessor(Interface): |
---|
467 | """A batch processor that handles mass-operations. |
---|
468 | """ |
---|
469 | name = schema.TextLine( |
---|
470 | title = _(u'Processor name') |
---|
471 | ) |
---|
472 | |
---|
473 | def doImport(path, headerfields, mode='create', user='Unknown', |
---|
474 | logger=None, ignore_empty=True): |
---|
475 | """Read data from ``path`` and update connected object. |
---|
476 | |
---|
477 | `headerfields` is a list of headerfields as read from the file |
---|
478 | to import. |
---|
479 | |
---|
480 | `mode` gives the import mode to use (``'create'``, |
---|
481 | ``'update'``, or ``'remove'``. |
---|
482 | |
---|
483 | `user` is a string describing the user performing the |
---|
484 | import. Normally fetched from current principal. |
---|
485 | |
---|
486 | `logger` is the logger to use during import. |
---|
487 | |
---|
488 | `ignore_emtpy` in update mode ignores empty fields if true. |
---|
489 | """ |
---|
490 | |
---|
491 | class IContactForm(IKofaObject): |
---|
492 | """A contact form. |
---|
493 | """ |
---|
494 | |
---|
495 | email_from = schema.ASCIILine( |
---|
496 | title = _(u'Email Address:'), |
---|
497 | default = None, |
---|
498 | required = True, |
---|
499 | constraint=validate_email, |
---|
500 | ) |
---|
501 | |
---|
502 | email_to = schema.ASCIILine( |
---|
503 | title = _(u'Email to:'), |
---|
504 | default = None, |
---|
505 | required = True, |
---|
506 | constraint=validate_email, |
---|
507 | ) |
---|
508 | |
---|
509 | subject = schema.TextLine( |
---|
510 | title = _(u'Subject:'), |
---|
511 | required = True,) |
---|
512 | |
---|
513 | fullname = schema.TextLine( |
---|
514 | title = _(u'Full Name:'), |
---|
515 | required = True,) |
---|
516 | |
---|
517 | body = schema.Text( |
---|
518 | title = _(u'Text:'), |
---|
519 | required = True,) |
---|
520 | |
---|
521 | class IKofaPrincipalInfo(IPrincipalInfo): |
---|
522 | """Infos about principals that are users of Kofa Kofa. |
---|
523 | """ |
---|
524 | email = Attribute("The email address of a user") |
---|
525 | phone = Attribute("The phone number of a user") |
---|
526 | public_name = Attribute("The public name of a user") |
---|
527 | user_type = Attribute("The type of a user") |
---|
528 | |
---|
529 | |
---|
530 | class IKofaPrincipal(IPrincipal): |
---|
531 | """A principle for Kofa Kofa. |
---|
532 | |
---|
533 | This interface extends zope.security.interfaces.IPrincipal and |
---|
534 | requires also an `id` and other attributes defined there. |
---|
535 | """ |
---|
536 | |
---|
537 | email = schema.TextLine( |
---|
538 | title = _(u'Email Address'), |
---|
539 | description = u'', |
---|
540 | required=False,) |
---|
541 | |
---|
542 | phone = PhoneNumber( |
---|
543 | title = _(u'Phone'), |
---|
544 | description = u'', |
---|
545 | required=False,) |
---|
546 | |
---|
547 | public_name = schema.TextLine( |
---|
548 | title = _(u'Public Name'), |
---|
549 | required = False,) |
---|
550 | |
---|
551 | user_type = Attribute('The user type of the principal') |
---|
552 | |
---|
553 | class IFailedLoginInfo(IKofaObject): |
---|
554 | """Info about failed logins. |
---|
555 | |
---|
556 | Timestamps are supposed to be stored as floats using time.time() |
---|
557 | or similar. |
---|
558 | """ |
---|
559 | num = schema.Int( |
---|
560 | title = _(u'Number of failed logins'), |
---|
561 | description = _(u'Number of failed logins'), |
---|
562 | required = True, |
---|
563 | default = 0, |
---|
564 | ) |
---|
565 | |
---|
566 | last = schema.Float( |
---|
567 | title = _(u'Timestamp'), |
---|
568 | description = _(u'Timestamp of last failed login or `None`'), |
---|
569 | required = False, |
---|
570 | default = None, |
---|
571 | ) |
---|
572 | |
---|
573 | def as_tuple(): |
---|
574 | """Get login info as tuple ``<NUM>, <TIMESTAMP>``. |
---|
575 | """ |
---|
576 | |
---|
577 | def set_values(num=0, last=None): |
---|
578 | """Set number of failed logins and timestamp of last one. |
---|
579 | """ |
---|
580 | |
---|
581 | def increase(): |
---|
582 | """Increase the current number of failed logins and set timestamp. |
---|
583 | """ |
---|
584 | |
---|
585 | def reset(): |
---|
586 | """Set failed login counters back to zero. |
---|
587 | """ |
---|
588 | |
---|
589 | |
---|
590 | class IUserAccount(IKofaObject): |
---|
591 | """A user account. |
---|
592 | """ |
---|
593 | |
---|
594 | failed_logins = Attribute('FailedLoginInfo for this account') |
---|
595 | |
---|
596 | name = schema.TextLine( |
---|
597 | title = _(u'User Id'), |
---|
598 | description = _(u'Login name of user'), |
---|
599 | required = True,) |
---|
600 | |
---|
601 | title = schema.TextLine( |
---|
602 | title = _(u'Full Name'), |
---|
603 | required = True,) |
---|
604 | |
---|
605 | public_name = schema.TextLine( |
---|
606 | title = _(u'Public Name'), |
---|
607 | description = _(u"Substitute for officer's real name " |
---|
608 | "in student object histories."), |
---|
609 | required = False,) |
---|
610 | |
---|
611 | description = schema.Text( |
---|
612 | title = _(u'Description/Notice'), |
---|
613 | required = False,) |
---|
614 | |
---|
615 | email = schema.ASCIILine( |
---|
616 | title = _(u'Email Address'), |
---|
617 | default = None, |
---|
618 | required = True, |
---|
619 | constraint=validate_email, |
---|
620 | ) |
---|
621 | |
---|
622 | phone = PhoneNumber( |
---|
623 | title = _(u'Phone'), |
---|
624 | default = None, |
---|
625 | required = False, |
---|
626 | ) |
---|
627 | |
---|
628 | roles = schema.List( |
---|
629 | title = _(u'Portal Roles'), |
---|
630 | value_type = schema.Choice(source=RoleSource()), |
---|
631 | required = False, |
---|
632 | ) |
---|
633 | |
---|
634 | suspended = schema.Bool( |
---|
635 | title = _(u'Account suspended'), |
---|
636 | description = _(u'If set, the account is immediately blocked.'), |
---|
637 | default = False, |
---|
638 | required = False, |
---|
639 | ) |
---|
640 | |
---|
641 | |
---|
642 | class IPasswordValidator(Interface): |
---|
643 | """A password validator utility. |
---|
644 | """ |
---|
645 | |
---|
646 | def validate_password(password, password_repeat): |
---|
647 | """Validates a password by comparing it with |
---|
648 | control password and checking some other requirements. |
---|
649 | """ |
---|
650 | |
---|
651 | def validate_secure_password(self, pw, pw_repeat): |
---|
652 | """ Validates a password by comparing it with |
---|
653 | control password and checks password strength by |
---|
654 | matching with the regular expression: |
---|
655 | |
---|
656 | ^(?=.*[A-Z])(?=.*[a-z])(?=.*[0-9]).{8,}$ |
---|
657 | |
---|
658 | ^ Start anchor |
---|
659 | (?=.*[A-Z]) Ensure password has one uppercase letters. |
---|
660 | (?=.*[0-9]) Ensure password has one digit. |
---|
661 | (?=.*[a-z]) Ensure password has one lowercase letter. |
---|
662 | .{8,} Ensure password is of length 8. |
---|
663 | $ End anchor. |
---|
664 | """ |
---|
665 | |
---|
666 | |
---|
667 | class IUsersContainer(IKofaObject): |
---|
668 | """A container for officers. |
---|
669 | """ |
---|
670 | |
---|
671 | def addUser(name, password, title=None, description=None): |
---|
672 | """Add a user. |
---|
673 | """ |
---|
674 | |
---|
675 | def delUser(name): |
---|
676 | """Delete a user if it exists. |
---|
677 | """ |
---|
678 | |
---|
679 | class ILocalRolesAssignable(Interface): |
---|
680 | """The local roles assignable to an object. |
---|
681 | """ |
---|
682 | def __call__(): |
---|
683 | """Returns a list of dicts. |
---|
684 | |
---|
685 | Each dict contains a ``name`` referring to the role assignable |
---|
686 | for the specified object and a `title` to describe the range |
---|
687 | of users to which this role can be assigned. |
---|
688 | """ |
---|
689 | |
---|
690 | class IConfigurationContainer(IKofaObject): |
---|
691 | """A container for session configuration objects. |
---|
692 | """ |
---|
693 | |
---|
694 | name = schema.TextLine( |
---|
695 | title = _(u'Name of University'), |
---|
696 | default = _(u'Sample University'), |
---|
697 | required = True, |
---|
698 | ) |
---|
699 | |
---|
700 | acronym = schema.TextLine( |
---|
701 | title = _(u'Abbreviated Title of University'), |
---|
702 | default = u'WAeUP.Kofa', |
---|
703 | required = True, |
---|
704 | ) |
---|
705 | |
---|
706 | frontpage = schema.Text( |
---|
707 | title = _(u'Content in HTML format'), |
---|
708 | required = False, |
---|
709 | default = default_html_frontpage, |
---|
710 | constraint=validate_html, |
---|
711 | ) |
---|
712 | |
---|
713 | frontpage_dict = schema.Dict( |
---|
714 | title = u'Content as language dictionary with values in html format', |
---|
715 | required = False, |
---|
716 | default = {}, |
---|
717 | ) |
---|
718 | |
---|
719 | name_admin = schema.TextLine( |
---|
720 | title = _(u'Name of Administrator'), |
---|
721 | default = u'Administrator', |
---|
722 | required = True, |
---|
723 | ) |
---|
724 | |
---|
725 | email_admin = schema.ASCIILine( |
---|
726 | title = _(u'Email Address of Administrator'), |
---|
727 | default = 'contact@waeup.org', |
---|
728 | required = True, |
---|
729 | #constraint=validate_email, |
---|
730 | ) |
---|
731 | |
---|
732 | email_subject = schema.TextLine( |
---|
733 | title = _(u'Subject of Email to Administrator'), |
---|
734 | default = _(u'Kofa Contact'), |
---|
735 | required = True, |
---|
736 | ) |
---|
737 | |
---|
738 | smtp_mailer = schema.Choice( |
---|
739 | title = _(u'SMTP mailer to use when sending mail'), |
---|
740 | vocabulary = 'Mail Delivery Names', |
---|
741 | default = 'No email service', |
---|
742 | required = True, |
---|
743 | ) |
---|
744 | |
---|
745 | captcha = schema.Choice( |
---|
746 | title = _(u'Captcha used for public registration pages'), |
---|
747 | source = CaptchaSource(), |
---|
748 | default = u'No captcha', |
---|
749 | required = True, |
---|
750 | ) |
---|
751 | |
---|
752 | carry_over = schema.Bool( |
---|
753 | title = _(u'Carry-over Course Registration'), |
---|
754 | default = False, |
---|
755 | ) |
---|
756 | |
---|
757 | current_academic_session = schema.Choice( |
---|
758 | title = _(u'Current Academic Session'), |
---|
759 | description = _(u'Session for which score editing is allowed'), |
---|
760 | source = academic_sessions_vocab, |
---|
761 | default = None, |
---|
762 | required = False, |
---|
763 | readonly = False, |
---|
764 | ) |
---|
765 | |
---|
766 | next_matric_integer = schema.Int( |
---|
767 | title = _(u'Next Matriculation Number Integer'), |
---|
768 | description = _(u'Integer used for constructing the next ' |
---|
769 | 'matriculation number'), |
---|
770 | default = 0, |
---|
771 | readonly = False, |
---|
772 | required = False, |
---|
773 | ) |
---|
774 | |
---|
775 | next_matric_integer_2 = schema.Int( |
---|
776 | title = _(u'Next Matriculation Number Integer 2'), |
---|
777 | description = _(u'2nd integer used for constructing the next ' |
---|
778 | 'matriculation number'), |
---|
779 | default = 0, |
---|
780 | readonly = False, |
---|
781 | required = False, |
---|
782 | ) |
---|
783 | |
---|
784 | next_matric_integer_3 = schema.Int( |
---|
785 | title = _(u'Next Matriculation Number Integer 3'), |
---|
786 | description = _(u'3rd integer used for constructing the next ' |
---|
787 | 'matriculation number'), |
---|
788 | default = 0, |
---|
789 | readonly = False, |
---|
790 | required = False, |
---|
791 | ) |
---|
792 | |
---|
793 | next_matric_integer_4 = schema.Int( |
---|
794 | title = _(u'Next Matriculation Number Integer 4'), |
---|
795 | description = _(u'4th integer used for constructing the next ' |
---|
796 | 'matriculation number'), |
---|
797 | default = 0, |
---|
798 | readonly = False, |
---|
799 | required = False, |
---|
800 | ) |
---|
801 | |
---|
802 | export_disabled_message = schema.Text( |
---|
803 | title = _(u'Export-disabled message'), |
---|
804 | description = _(u'Message which will show up if an officer tries ' |
---|
805 | 'to export data. All exporters are automatcally ' |
---|
806 | 'disabled if this field is set.'), |
---|
807 | required = False, |
---|
808 | ) |
---|
809 | |
---|
810 | maintmode_enabled_by = schema.TextLine( |
---|
811 | title = _(u'Maintenance Mode enabled by'), |
---|
812 | default = None, |
---|
813 | required = False, |
---|
814 | ) |
---|
815 | |
---|
816 | def addSessionConfiguration(sessionconfiguration): |
---|
817 | """Add a session configuration object. |
---|
818 | """ |
---|
819 | |
---|
820 | class ISessionConfiguration(IKofaObject): |
---|
821 | """A session configuration object. |
---|
822 | """ |
---|
823 | |
---|
824 | academic_session = schema.Choice( |
---|
825 | title = _(u'Academic Session'), |
---|
826 | source = academic_sessions_vocab, |
---|
827 | default = None, |
---|
828 | required = True, |
---|
829 | readonly = True, |
---|
830 | ) |
---|
831 | |
---|
832 | clearance_enabled = schema.Bool( |
---|
833 | title = _(u'Clearance enabled'), |
---|
834 | default = False, |
---|
835 | ) |
---|
836 | |
---|
837 | payment_disabled = schema.List( |
---|
838 | title = _(u'Payment disabled'), |
---|
839 | value_type = schema.Choice( |
---|
840 | source = DisablePaymentGroupSource(), |
---|
841 | ), |
---|
842 | required = False, |
---|
843 | defaultFactory=list, |
---|
844 | ) |
---|
845 | |
---|
846 | coursereg_deadline = schema.Datetime( |
---|
847 | title = _(u'Course Reg. Deadline'), |
---|
848 | required = False, |
---|
849 | description = _('Example: ') + u'2011-12-31 23:59:59+01:00', |
---|
850 | ) |
---|
851 | |
---|
852 | clearance_fee = schema.Float( |
---|
853 | title = _(u'Acceptance Fee'), |
---|
854 | default = 0.0, |
---|
855 | required = False, |
---|
856 | ) |
---|
857 | |
---|
858 | booking_fee = schema.Float( |
---|
859 | title = _(u'Bed Booking Fee'), |
---|
860 | default = 0.0, |
---|
861 | required = False, |
---|
862 | ) |
---|
863 | |
---|
864 | maint_fee = schema.Float( |
---|
865 | title = _(u'Rent (fallback)'), |
---|
866 | default = 0.0, |
---|
867 | required = False, |
---|
868 | ) |
---|
869 | |
---|
870 | late_registration_fee = schema.Float( |
---|
871 | title = _(u'Late Course Reg. Fee'), |
---|
872 | default = 0.0, |
---|
873 | required = False, |
---|
874 | ) |
---|
875 | |
---|
876 | transcript_fee = schema.Float( |
---|
877 | title = _(u'Transcript Fee'), |
---|
878 | default = 0.0, |
---|
879 | required = False, |
---|
880 | ) |
---|
881 | |
---|
882 | transfer_fee = schema.Float( |
---|
883 | title = _(u'Transfer Fee'), |
---|
884 | default = 0.0, |
---|
885 | required = False, |
---|
886 | ) |
---|
887 | |
---|
888 | def getSessionString(): |
---|
889 | """Return the session string from the vocabulary. |
---|
890 | """ |
---|
891 | |
---|
892 | |
---|
893 | class ISessionConfigurationAdd(ISessionConfiguration): |
---|
894 | """A session configuration object in add mode. |
---|
895 | """ |
---|
896 | |
---|
897 | academic_session = schema.Choice( |
---|
898 | title = _(u'Academic Session'), |
---|
899 | source = academic_sessions_vocab, |
---|
900 | default = None, |
---|
901 | required = True, |
---|
902 | readonly = False, |
---|
903 | ) |
---|
904 | |
---|
905 | ISessionConfigurationAdd['academic_session'].order = ISessionConfiguration[ |
---|
906 | 'academic_session'].order |
---|
907 | |
---|
908 | class IDataCenter(IKofaObject): |
---|
909 | """A data center. |
---|
910 | |
---|
911 | A data center manages files (uploads, downloads, etc.). |
---|
912 | |
---|
913 | Beside providing the bare paths needed to keep files, it also |
---|
914 | provides some helpers to put results of batch processing into |
---|
915 | well-defined final locations (with well-defined filenames). |
---|
916 | |
---|
917 | The main use-case is managing of site-related files, i.e. files |
---|
918 | for import, export etc. |
---|
919 | |
---|
920 | DataCenters are _not_ meant as storages for object-specific files |
---|
921 | like passport photographs and similar. |
---|
922 | |
---|
923 | It is up to the datacenter implementation how to organize data |
---|
924 | (paths) inside its storage path. |
---|
925 | """ |
---|
926 | storage = schema.Bytes( |
---|
927 | title = u'Path to directory where everything is kept.' |
---|
928 | ) |
---|
929 | |
---|
930 | deleted_path = schema.Bytes( |
---|
931 | title = u'Path were data about deleted objects should be stored.' |
---|
932 | ) |
---|
933 | |
---|
934 | def getPendingFiles(sort='name'): |
---|
935 | """Get a list of files stored in `storage` sorted by basename. |
---|
936 | """ |
---|
937 | |
---|
938 | def getFinishedFiles(): |
---|
939 | """Get a list of files stored in `finished` subfolder of `storage`. |
---|
940 | """ |
---|
941 | |
---|
942 | def setStoragePath(path, move=False, overwrite=False): |
---|
943 | """Set the path where to store files. |
---|
944 | |
---|
945 | If `move` is True, move over files from the current location |
---|
946 | to the new one. |
---|
947 | |
---|
948 | If `overwrite` is also True, overwrite any already existing |
---|
949 | files of same name in target location. |
---|
950 | |
---|
951 | Triggers a DataCenterStorageMovedEvent. |
---|
952 | """ |
---|
953 | |
---|
954 | def distProcessedFiles(successful, source_path, finished_file, |
---|
955 | pending_file, mode='create', move_orig=True): |
---|
956 | """Distribute processed files over final locations. |
---|
957 | """ |
---|
958 | |
---|
959 | |
---|
960 | class IDataCenterFile(Interface): |
---|
961 | """A data center file. |
---|
962 | """ |
---|
963 | |
---|
964 | name = schema.TextLine( |
---|
965 | title = u'Filename') |
---|
966 | |
---|
967 | size = schema.TextLine( |
---|
968 | title = u'Human readable file size') |
---|
969 | |
---|
970 | uploaddate = schema.TextLine( |
---|
971 | title = u'Human readable upload datetime') |
---|
972 | |
---|
973 | lines = schema.Int( |
---|
974 | title = u'Number of lines in file') |
---|
975 | |
---|
976 | def getDate(): |
---|
977 | """Get creation timestamp from file in human readable form. |
---|
978 | """ |
---|
979 | |
---|
980 | def getSize(): |
---|
981 | """Get human readable size of file. |
---|
982 | """ |
---|
983 | |
---|
984 | def getLinesNumber(): |
---|
985 | """Get number of lines of file. |
---|
986 | """ |
---|
987 | |
---|
988 | class IDataCenterStorageMovedEvent(IObjectEvent): |
---|
989 | """Emitted, when the storage of a datacenter changes. |
---|
990 | """ |
---|
991 | |
---|
992 | class IObjectUpgradeEvent(IObjectEvent): |
---|
993 | """Can be fired, when an object shall be upgraded. |
---|
994 | """ |
---|
995 | |
---|
996 | class ILocalRoleSetEvent(IObjectEvent): |
---|
997 | """A local role was granted/revoked for a principal on an object. |
---|
998 | """ |
---|
999 | role_id = Attribute( |
---|
1000 | "The role id that was set.") |
---|
1001 | principal_id = Attribute( |
---|
1002 | "The principal id for which the role was granted/revoked.") |
---|
1003 | granted = Attribute( |
---|
1004 | "Boolean. If false, then the role was revoked.") |
---|
1005 | |
---|
1006 | class IQueryResultItem(Interface): |
---|
1007 | """An item in a search result. |
---|
1008 | """ |
---|
1009 | url = schema.TextLine( |
---|
1010 | title = u'URL that links to the found item') |
---|
1011 | title = schema.TextLine( |
---|
1012 | title = u'Title displayed in search results.') |
---|
1013 | description = schema.Text( |
---|
1014 | title = u'Longer description of the item found.') |
---|
1015 | |
---|
1016 | class IKofaPluggable(Interface): |
---|
1017 | """A component that might be plugged into a Kofa Kofa app. |
---|
1018 | |
---|
1019 | Components implementing this interface are referred to as |
---|
1020 | 'plugins'. They are normally called when a new |
---|
1021 | :class:`waeup.kofa.app.University` instance is created. |
---|
1022 | |
---|
1023 | Plugins can setup and update parts of the central site without the |
---|
1024 | site object (normally a :class:`waeup.kofa.app.University` object) |
---|
1025 | needing to know about that parts. The site simply collects all |
---|
1026 | available plugins, calls them and the plugins care for their |
---|
1027 | respective subarea like the applicants area or the datacenter |
---|
1028 | area. |
---|
1029 | |
---|
1030 | Currently we have no mechanism to define an order of plugins. A |
---|
1031 | plugin should therefore make no assumptions about the state of the |
---|
1032 | site or other plugins being run before and instead do appropriate |
---|
1033 | checks if necessary. |
---|
1034 | |
---|
1035 | Updates can be triggered for instance by the respective form in |
---|
1036 | the site configuration. You normally do updates when the |
---|
1037 | underlying software changed. |
---|
1038 | """ |
---|
1039 | def setup(site, name, logger): |
---|
1040 | """Create an instance of the plugin. |
---|
1041 | |
---|
1042 | The method is meant to be called by the central app (site) |
---|
1043 | when it is created. |
---|
1044 | |
---|
1045 | `site`: |
---|
1046 | The site that requests a setup. |
---|
1047 | |
---|
1048 | `name`: |
---|
1049 | The name under which the plugin was registered (utility name). |
---|
1050 | |
---|
1051 | `logger`: |
---|
1052 | A standard Python logger for the plugins use. |
---|
1053 | """ |
---|
1054 | |
---|
1055 | def update(site, name, logger): |
---|
1056 | """Method to update an already existing plugin. |
---|
1057 | |
---|
1058 | This might be called by a site when something serious |
---|
1059 | changes. It is a poor-man replacement for Zope generations |
---|
1060 | (but probably more comprehensive and better understandable). |
---|
1061 | |
---|
1062 | `site`: |
---|
1063 | The site that requests an update. |
---|
1064 | |
---|
1065 | `name`: |
---|
1066 | The name under which the plugin was registered (utility name). |
---|
1067 | |
---|
1068 | `logger`: |
---|
1069 | A standard Python logger for the plugins use. |
---|
1070 | """ |
---|
1071 | |
---|
1072 | class IAuthPluginUtility(Interface): |
---|
1073 | """A component that cares for authentication setup at site creation. |
---|
1074 | |
---|
1075 | Utilities providing this interface are looked up when a Pluggable |
---|
1076 | Authentication Utility (PAU) for any |
---|
1077 | :class:`waeup.kofa.app.University` instance is created and put |
---|
1078 | into ZODB. |
---|
1079 | |
---|
1080 | The setup-code then calls the `register` method of the utility and |
---|
1081 | expects a modified (or unmodified) version of the PAU back. |
---|
1082 | |
---|
1083 | This allows to define any authentication setup modifications by |
---|
1084 | submodules or third-party modules/packages. |
---|
1085 | """ |
---|
1086 | |
---|
1087 | def register(pau): |
---|
1088 | """Register any plugins wanted to be in the PAU. |
---|
1089 | """ |
---|
1090 | |
---|
1091 | def unregister(pau): |
---|
1092 | """Unregister any plugins not wanted to be in the PAU. |
---|
1093 | """ |
---|
1094 | |
---|
1095 | class IObjectConverter(Interface): |
---|
1096 | """Object converters are available as simple adapters, adapting |
---|
1097 | interfaces (not regular instances). |
---|
1098 | |
---|
1099 | """ |
---|
1100 | |
---|
1101 | def fromStringDict(self, data_dict, context, form_fields=None): |
---|
1102 | """Convert values in `data_dict`. |
---|
1103 | |
---|
1104 | Converts data in `data_dict` into real values based on |
---|
1105 | `context` and `form_fields`. |
---|
1106 | |
---|
1107 | `data_dict` is a mapping (dict) from field names to values |
---|
1108 | represented as strings. |
---|
1109 | |
---|
1110 | The fields (keys) to convert can be given in optional |
---|
1111 | `form_fields`. If given, form_fields should be an instance of |
---|
1112 | :class:`zope.formlib.form.Fields`. Suitable instances are for |
---|
1113 | example created by :class:`grok.AutoFields`. |
---|
1114 | |
---|
1115 | If no `form_fields` are given, a default is computed from the |
---|
1116 | associated interface. |
---|
1117 | |
---|
1118 | The `context` can be an existing object (implementing the |
---|
1119 | associated interface) or a factory name. If it is a string, we |
---|
1120 | try to create an object using |
---|
1121 | :func:`zope.component.createObject`. |
---|
1122 | |
---|
1123 | Returns a tuple ``(<FIELD_ERRORS>, <INVARIANT_ERRORS>, |
---|
1124 | <DATA_DICT>)`` where |
---|
1125 | |
---|
1126 | ``<FIELD_ERRORS>`` |
---|
1127 | is a list of tuples ``(<FIELD_NAME>, <ERROR>)`` for each |
---|
1128 | error that happened when validating the input data in |
---|
1129 | `data_dict` |
---|
1130 | |
---|
1131 | ``<INVARIANT_ERRORS>`` |
---|
1132 | is a list of invariant errors concerning several fields |
---|
1133 | |
---|
1134 | ``<DATA_DICT>`` |
---|
1135 | is a dict with the values from input dict converted. |
---|
1136 | |
---|
1137 | If errors happen, i.e. the error lists are not empty, always |
---|
1138 | an empty ``<DATA_DICT>`` is returned. |
---|
1139 | |
---|
1140 | If ``<DATA_DICT>`` is non-empty, there were no errors. |
---|
1141 | """ |
---|
1142 | |
---|
1143 | class IFieldConverter(Interface): |
---|
1144 | def request_data(name, value, schema_field, prefix='', mode='create'): |
---|
1145 | """Create a dict with key-value mapping as created by a request. |
---|
1146 | |
---|
1147 | `name` and `value` are expected to be parsed from CSV or a |
---|
1148 | similar input and represent an attribute to be set to a |
---|
1149 | representation of value. |
---|
1150 | |
---|
1151 | `mode` gives the mode of import. |
---|
1152 | |
---|
1153 | :meth:`update_request_data` is then requested to turn this |
---|
1154 | name and value into vars as they would be sent by a regular |
---|
1155 | form submit. This means we do not create the real values to be |
---|
1156 | set but we only define the values that would be sent in a |
---|
1157 | browser request to request the creation of those values. |
---|
1158 | |
---|
1159 | The returned dict should contain names and values of a faked |
---|
1160 | browser request for the given `schema_field`. |
---|
1161 | |
---|
1162 | Field converters are normally registered as adapters to some |
---|
1163 | specific zope.schema field. |
---|
1164 | """ |
---|
1165 | |
---|
1166 | class IObjectHistory(Interface): |
---|
1167 | |
---|
1168 | messages = schema.List( |
---|
1169 | title = u'List of messages stored', |
---|
1170 | required = True, |
---|
1171 | ) |
---|
1172 | |
---|
1173 | def addMessage(message): |
---|
1174 | """Add a message. |
---|
1175 | """ |
---|
1176 | |
---|
1177 | class IKofaWorkflowInfo(IWorkflowInfo): |
---|
1178 | """A :class:`hurry.workflow.workflow.WorkflowInfo` with additional |
---|
1179 | methods for convenience. |
---|
1180 | """ |
---|
1181 | def getManualTransitions(): |
---|
1182 | """Get allowed manual transitions. |
---|
1183 | |
---|
1184 | Get a sorted list of tuples containing the `transition_id` and |
---|
1185 | `title` of each allowed transition. |
---|
1186 | """ |
---|
1187 | |
---|
1188 | class ISiteLoggers(Interface): |
---|
1189 | |
---|
1190 | loggers = Attribute("A list or generator of registered KofaLoggers") |
---|
1191 | |
---|
1192 | def register(name, filename=None, site=None, **options): |
---|
1193 | """Register a logger `name` which logs to `filename`. |
---|
1194 | |
---|
1195 | If `filename` is not given, logfile will be `name` with |
---|
1196 | ``.log`` as filename extension. |
---|
1197 | """ |
---|
1198 | |
---|
1199 | def unregister(name): |
---|
1200 | """Unregister a once registered logger. |
---|
1201 | """ |
---|
1202 | |
---|
1203 | class ILogger(Interface): |
---|
1204 | """A logger cares for setup, update and restarting of a Python logger. |
---|
1205 | """ |
---|
1206 | |
---|
1207 | logger = Attribute("""A :class:`logging.Logger` instance""") |
---|
1208 | |
---|
1209 | |
---|
1210 | def __init__(name, filename=None, site=None, **options): |
---|
1211 | """Create a Kofa logger instance. |
---|
1212 | """ |
---|
1213 | |
---|
1214 | def setup(): |
---|
1215 | """Create a Python :class:`logging.Logger` instance. |
---|
1216 | |
---|
1217 | The created logger is based on the params given by constructor. |
---|
1218 | """ |
---|
1219 | |
---|
1220 | def update(**options): |
---|
1221 | """Update the logger. |
---|
1222 | |
---|
1223 | Updates the logger respecting modified `options` and changed |
---|
1224 | paths. |
---|
1225 | """ |
---|
1226 | |
---|
1227 | class ILoggerCollector(Interface): |
---|
1228 | |
---|
1229 | def getLoggers(site): |
---|
1230 | """Return all loggers registered for `site`. |
---|
1231 | """ |
---|
1232 | |
---|
1233 | def registerLogger(site, logging_component): |
---|
1234 | """Register a logging component residing in `site`. |
---|
1235 | """ |
---|
1236 | |
---|
1237 | def unregisterLogger(site, logging_component): |
---|
1238 | """Unregister a logger. |
---|
1239 | """ |
---|
1240 | |
---|
1241 | # |
---|
1242 | # External File Storage and relatives |
---|
1243 | # |
---|
1244 | class IFileStoreNameChooser(INameChooser): |
---|
1245 | """See zope.container.interfaces.INameChooser for base methods. |
---|
1246 | """ |
---|
1247 | def checkName(name, attr=None): |
---|
1248 | """Check whether an object name is valid. |
---|
1249 | |
---|
1250 | Raises a user error if the name is not valid. |
---|
1251 | """ |
---|
1252 | |
---|
1253 | def chooseName(name, attr=None): |
---|
1254 | """Choose a unique valid file id for the object. |
---|
1255 | |
---|
1256 | The given name may be taken into account when choosing the |
---|
1257 | name (file id). |
---|
1258 | |
---|
1259 | chooseName is expected to always choose a valid file id (that |
---|
1260 | would pass the checkName test) and never raise an error. |
---|
1261 | |
---|
1262 | If `attr` is not ``None`` it might been taken into account as |
---|
1263 | well when generating the file id. Usual behaviour is to |
---|
1264 | interpret `attr` as a hint for what type of file for a given |
---|
1265 | context should be stored if there are several types |
---|
1266 | possible. For instance for a certain student some file could |
---|
1267 | be the connected passport photograph or some certificate scan |
---|
1268 | or whatever. Each of them has to be stored in a different |
---|
1269 | location so setting `attr` to a sensible value should give |
---|
1270 | different file ids returned. |
---|
1271 | """ |
---|
1272 | |
---|
1273 | class IExtFileStore(IFileRetrieval): |
---|
1274 | """A file storage that stores files in filesystem (not as blobs). |
---|
1275 | """ |
---|
1276 | root = schema.TextLine( |
---|
1277 | title = u'Root path of file store.', |
---|
1278 | ) |
---|
1279 | |
---|
1280 | def getFile(file_id): |
---|
1281 | """Get raw file data stored under file with `file_id`. |
---|
1282 | |
---|
1283 | Returns a file descriptor open for reading or ``None`` if the |
---|
1284 | file cannot be found. |
---|
1285 | """ |
---|
1286 | |
---|
1287 | def getFileByContext(context, attr=None): |
---|
1288 | """Get raw file data stored for the given context. |
---|
1289 | |
---|
1290 | Returns a file descriptor open for reading or ``None`` if no |
---|
1291 | such file can be found. |
---|
1292 | |
---|
1293 | Both, `context` and `attr` might be used to find (`context`) |
---|
1294 | and feed (`attr`) an appropriate file name chooser. |
---|
1295 | |
---|
1296 | This is a convenience method. |
---|
1297 | """ |
---|
1298 | |
---|
1299 | def deleteFile(file_id): |
---|
1300 | """Delete file stored under `file_id`. |
---|
1301 | |
---|
1302 | Remove file from filestore so, that it is not available |
---|
1303 | anymore on next call to getFile for the same file_id. |
---|
1304 | |
---|
1305 | Should not complain if no such file exists. |
---|
1306 | """ |
---|
1307 | |
---|
1308 | def deleteFileByContext(context, attr=None): |
---|
1309 | """Delete file for given `context` and `attr`. |
---|
1310 | |
---|
1311 | Both, `context` and `attr` might be used to find (`context`) |
---|
1312 | and feed (`attr`) an appropriate file name chooser. |
---|
1313 | |
---|
1314 | This is a convenience method. |
---|
1315 | """ |
---|
1316 | |
---|
1317 | def createFile(filename, f): |
---|
1318 | """Create file given by f with filename `filename` |
---|
1319 | |
---|
1320 | Returns a hurry.file.File-based object. |
---|
1321 | """ |
---|
1322 | |
---|
1323 | class IFileStoreHandler(Interface): |
---|
1324 | """Filestore handlers handle specific files for file stores. |
---|
1325 | |
---|
1326 | If a file to store/get provides a specific filename, a file store |
---|
1327 | looks up special handlers for that type of file. |
---|
1328 | |
---|
1329 | """ |
---|
1330 | def pathFromFileID(store, root, filename): |
---|
1331 | """Turn file id into path to store. |
---|
1332 | |
---|
1333 | Returned path should be absolute. |
---|
1334 | """ |
---|
1335 | |
---|
1336 | def createFile(store, root, filename, file_id, file): |
---|
1337 | """Return some hurry.file based on `store` and `file_id`. |
---|
1338 | |
---|
1339 | Some kind of callback method called by file stores to create |
---|
1340 | file objects from file_id. |
---|
1341 | |
---|
1342 | Returns a tuple ``(raw_file, path, file_like_obj)`` where the |
---|
1343 | ``file_like_obj`` should be a HurryFile, a KofaImageFile or |
---|
1344 | similar. ``raw_file`` is the (maybe changed) input file and |
---|
1345 | ``path`` the relative internal path to store the file at. |
---|
1346 | |
---|
1347 | Please make sure the ``raw_file`` is opened for reading and |
---|
1348 | the file descriptor set at position 0 when returned. |
---|
1349 | |
---|
1350 | This method also gets the raw input file object that is about |
---|
1351 | to be stored and is expected to raise any exceptions if some |
---|
1352 | kind of validation or similar fails. |
---|
1353 | """ |
---|
1354 | |
---|
1355 | class IPDF(Interface): |
---|
1356 | """A PDF representation of some context. |
---|
1357 | """ |
---|
1358 | |
---|
1359 | def __call__(view=None, note=None): |
---|
1360 | """Create a bytestream representing a PDF from context. |
---|
1361 | |
---|
1362 | If `view` is passed in additional infos might be rendered into |
---|
1363 | the document. |
---|
1364 | |
---|
1365 | `note` is optional HTML rendered at bottom of the created |
---|
1366 | PDF. Please consider the limited reportlab support for HTML, |
---|
1367 | but using font-tags and friends you certainly can get the |
---|
1368 | desired look. |
---|
1369 | """ |
---|
1370 | |
---|
1371 | class IMailService(Interface): |
---|
1372 | """A mail service. |
---|
1373 | """ |
---|
1374 | |
---|
1375 | def __call__(): |
---|
1376 | """Get the default mail delivery. |
---|
1377 | """ |
---|
1378 | |
---|
1379 | |
---|
1380 | class IDataCenterConfig(Interface): |
---|
1381 | path = Path( |
---|
1382 | title = u'Path', |
---|
1383 | description = u"Directory where the datacenter should store " |
---|
1384 | u"files by default (adjustable in web UI).", |
---|
1385 | required = True, |
---|
1386 | ) |
---|
1387 | |
---|
1388 | # |
---|
1389 | # Asynchronous job handling and related |
---|
1390 | # |
---|
1391 | class IJobManager(IKofaObject): |
---|
1392 | """A manager for asynchronous running jobs (tasks). |
---|
1393 | """ |
---|
1394 | def put(job, site=None): |
---|
1395 | """Put a job into task queue. |
---|
1396 | |
---|
1397 | If no `site` is given, queue job in context of current local |
---|
1398 | site. |
---|
1399 | |
---|
1400 | Returns a job_id to identify the put job. This job_id is |
---|
1401 | needed for further references to the job. |
---|
1402 | """ |
---|
1403 | |
---|
1404 | def jobs(site=None): |
---|
1405 | """Get an iterable of jobs stored. |
---|
1406 | """ |
---|
1407 | |
---|
1408 | def get(job_id, site=None): |
---|
1409 | """Get the job with id `job_id`. |
---|
1410 | |
---|
1411 | For the `site` parameter see :meth:`put`. |
---|
1412 | """ |
---|
1413 | |
---|
1414 | def remove(job_id, site=None): |
---|
1415 | """Remove job with `job_id` from stored jobs. |
---|
1416 | """ |
---|
1417 | |
---|
1418 | def start_test_job(site=None): |
---|
1419 | """Start a test job. |
---|
1420 | """ |
---|
1421 | |
---|
1422 | class IProgressable(Interface): |
---|
1423 | """A component that can indicate its progress status. |
---|
1424 | """ |
---|
1425 | percent = schema.Float( |
---|
1426 | title = u'Percent of job done already.', |
---|
1427 | ) |
---|
1428 | |
---|
1429 | class IJobContainer(IContainer): |
---|
1430 | """A job container contains IJob objects. |
---|
1431 | """ |
---|
1432 | |
---|
1433 | class IExportJob(zc.async.interfaces.IJob): |
---|
1434 | def __init__(site, exporter_name): |
---|
1435 | pass |
---|
1436 | |
---|
1437 | finished = schema.Bool( |
---|
1438 | title = u'`True` if the job finished.`', |
---|
1439 | default = False, |
---|
1440 | ) |
---|
1441 | |
---|
1442 | failed = schema.Bool( |
---|
1443 | title = u"`True` iff the job finished and didn't provide a file.", |
---|
1444 | default = None, |
---|
1445 | ) |
---|
1446 | |
---|
1447 | class IExportJobContainer(IKofaObject): |
---|
1448 | """A component that contains (maybe virtually) export jobs. |
---|
1449 | """ |
---|
1450 | def start_export_job(exporter_name, user_id, *args, **kwargs): |
---|
1451 | """Start asynchronous export job. |
---|
1452 | |
---|
1453 | `exporter_name` is the name of an exporter utility to be used. |
---|
1454 | |
---|
1455 | `user_id` is the ID of the user that triggers the export. |
---|
1456 | |
---|
1457 | `args` positional arguments passed to the export job created. |
---|
1458 | |
---|
1459 | `kwargs` keyword arguments passed to the export job. |
---|
1460 | |
---|
1461 | The job_id is stored along with exporter name and user id in a |
---|
1462 | persistent list. |
---|
1463 | |
---|
1464 | Returns the job ID of the job started. |
---|
1465 | """ |
---|
1466 | |
---|
1467 | def get_running_export_jobs(user_id=None): |
---|
1468 | """Get export jobs for user with `user_id` as list of tuples. |
---|
1469 | |
---|
1470 | Each tuples holds ``<job_id>, <exporter_name>, <user_id>`` in |
---|
1471 | that order. The ``<exporter_name>`` is the utility name of the |
---|
1472 | used exporter. |
---|
1473 | |
---|
1474 | If `user_id` is ``None``, all running jobs are returned. |
---|
1475 | """ |
---|
1476 | |
---|
1477 | def get_export_jobs_status(user_id=None): |
---|
1478 | """Get running/completed export jobs for `user_id` as list of tuples. |
---|
1479 | |
---|
1480 | Each tuple holds ``<raw status>, <status translated>, |
---|
1481 | <exporter title>`` in that order, where ``<status |
---|
1482 | translated>`` and ``<exporter title>`` are translated strings |
---|
1483 | representing the status of the job and the human readable |
---|
1484 | title of the exporter used. |
---|
1485 | """ |
---|
1486 | |
---|
1487 | def delete_export_entry(entry): |
---|
1488 | """Delete the export denoted by `entry`. |
---|
1489 | |
---|
1490 | Removes `entry` from the local `running_exports` list and also |
---|
1491 | removes the regarding job via the local job manager. |
---|
1492 | |
---|
1493 | `entry` is a tuple ``(<job id>, <exporter name>, <user id>)`` |
---|
1494 | as created by :meth:`start_export_job` or returned by |
---|
1495 | :meth:`get_running_export_jobs`. |
---|
1496 | """ |
---|
1497 | |
---|
1498 | def entry_from_job_id(job_id): |
---|
1499 | """Get entry tuple for `job_id`. |
---|
1500 | |
---|
1501 | Returns ``None`` if no such entry can be found. |
---|
1502 | """ |
---|
1503 | |
---|
1504 | class IExportContainerFinder(Interface): |
---|
1505 | """A finder for the central export container. |
---|
1506 | """ |
---|
1507 | def __call__(): |
---|
1508 | """Return the currently used global or site-wide IExportContainer. |
---|
1509 | """ |
---|
1510 | |
---|
1511 | class IFilteredQuery(IKofaObject): |
---|
1512 | """A query for objects. |
---|
1513 | """ |
---|
1514 | |
---|
1515 | defaults = schema.Dict( |
---|
1516 | title = u'Default Parameters', |
---|
1517 | required = True, |
---|
1518 | ) |
---|
1519 | |
---|
1520 | def __init__(**parameters): |
---|
1521 | """Instantiate a filtered query by passing in parameters. |
---|
1522 | """ |
---|
1523 | |
---|
1524 | def query(): |
---|
1525 | """Get an iterable of objects denoted by the set parameters. |
---|
1526 | |
---|
1527 | The search should be applied to objects inside current |
---|
1528 | site. It's the caller's duty to set the correct site before. |
---|
1529 | |
---|
1530 | Result can be any iterable like a catalog result set, a list, |
---|
1531 | or similar. |
---|
1532 | """ |
---|
1533 | |
---|
1534 | class IFilteredCatalogQuery(IFilteredQuery): |
---|
1535 | """A catalog-based query for objects. |
---|
1536 | """ |
---|
1537 | |
---|
1538 | cat_name = schema.TextLine( |
---|
1539 | title = u'Registered name of the catalog to search.', |
---|
1540 | required = True, |
---|
1541 | ) |
---|
1542 | |
---|
1543 | def query_catalog(catalog): |
---|
1544 | """Query catalog with the parameters passed to constructor. |
---|
1545 | """ |
---|