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