[7193] | 1 | ## $Id: interfaces.py 13034 2015-06-05 06:02:20Z henrik $ |
---|
[3521] | 2 | ## |
---|
[7193] | 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 | ## |
---|
[6361] | 18 | import os |
---|
[7221] | 19 | import re |
---|
[7702] | 20 | import codecs |
---|
[9217] | 21 | import zc.async.interfaces |
---|
[7670] | 22 | import zope.i18nmessageid |
---|
[6915] | 23 | from datetime import datetime |
---|
[7063] | 24 | from hurry.file.interfaces import IFileRetrieval |
---|
[8394] | 25 | from hurry.workflow.interfaces import IWorkflowInfo |
---|
[4789] | 26 | from zc.sourcefactory.basic import BasicSourceFactory |
---|
[6147] | 27 | from zope import schema |
---|
[7233] | 28 | from zope.pluggableauth.interfaces import IPrincipalInfo |
---|
| 29 | from zope.security.interfaces import IGroupClosureAwarePrincipal as IPrincipal |
---|
[4789] | 30 | from zope.component import getUtility |
---|
[4882] | 31 | from zope.component.interfaces import IObjectEvent |
---|
[9217] | 32 | from zope.configuration.fields import Path |
---|
| 33 | from zope.container.interfaces import INameChooser, IContainer |
---|
[8394] | 34 | from zope.interface import Interface, Attribute |
---|
[7795] | 35 | from zope.schema.interfaces import IObject |
---|
[4789] | 36 | from zope.schema.vocabulary import SimpleVocabulary, SimpleTerm |
---|
[8176] | 37 | from waeup.kofa.schema import PhoneNumber |
---|
[11450] | 38 | from waeup.kofa.sourcefactory import SmartBasicContextualSourceFactory |
---|
[3521] | 39 | |
---|
[7811] | 40 | _ = MessageFactory = zope.i18nmessageid.MessageFactory('waeup.kofa') |
---|
[6990] | 41 | |
---|
[8214] | 42 | DELETION_MARKER = 'XXX' |
---|
| 43 | IGNORE_MARKER = '<IGNORE>' |
---|
[9217] | 44 | WAEUP_KEY = 'waeup.kofa' |
---|
| 45 | VIRT_JOBS_CONTAINER_NAME = 'jobs' |
---|
[12901] | 46 | DOCLINK = 'http://kofa-doc.waeup.org/userdocs' |
---|
[8202] | 47 | |
---|
[7673] | 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' |
---|
[10446] | 57 | GRADUATED = 'graduated' |
---|
| 58 | TRANSCRIPT = 'transcript requested' |
---|
[7670] | 59 | |
---|
[10446] | 60 | |
---|
[9217] | 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 | |
---|
[8361] | 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'), |
---|
[7702] | 78 | encoding='utf-8', mode='rb').read() |
---|
[6361] | 79 | |
---|
[7819] | 80 | def SimpleKofaVocabulary(*terms): |
---|
[6915] | 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 |
---|
[12751] | 89 | year_range = range(1989, curr_year + 2) |
---|
[6915] | 90 | return [('%s/%s' % (year,year+1), year) for year in year_range] |
---|
| 91 | |
---|
[7819] | 92 | academic_sessions_vocab = SimpleKofaVocabulary(*academic_sessions()) |
---|
[6915] | 93 | |
---|
[7819] | 94 | registration_states_vocab = SimpleKofaVocabulary( |
---|
[7677] | 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), |
---|
[9671] | 103 | (_('returning'), RETURNING), |
---|
[10451] | 104 | (_('graduated'), GRADUATED), |
---|
| 105 | (_('transcript requested'), TRANSCRIPT), |
---|
[6990] | 106 | ) |
---|
| 107 | |
---|
[11450] | 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) |
---|
[11664] | 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] |
---|
[11450] | 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 | |
---|
[7795] | 127 | class SubjectSource(BasicSourceFactory): |
---|
[7918] | 128 | """A source for school subjects used in exam documentation. |
---|
| 129 | """ |
---|
[7795] | 130 | def getValues(self): |
---|
[7841] | 131 | subjects_dict = getUtility(IKofaUtils).EXAM_SUBJECTS_DICT |
---|
[7837] | 132 | return sorted(subjects_dict.keys()) |
---|
| 133 | |
---|
[7795] | 134 | def getTitle(self, value): |
---|
[7841] | 135 | subjects_dict = getUtility(IKofaUtils).EXAM_SUBJECTS_DICT |
---|
[7837] | 136 | return "%s:" % subjects_dict[value] |
---|
[7795] | 137 | |
---|
| 138 | class GradeSource(BasicSourceFactory): |
---|
[7918] | 139 | """A source for exam grades. |
---|
| 140 | """ |
---|
[7795] | 141 | def getValues(self): |
---|
[7918] | 142 | for entry in getUtility(IKofaUtils).EXAM_GRADES: |
---|
| 143 | yield entry[0] |
---|
[7837] | 144 | |
---|
[7795] | 145 | def getTitle(self, value): |
---|
[7918] | 146 | return dict(getUtility(IKofaUtils).EXAM_GRADES)[value] |
---|
[7795] | 147 | |
---|
[11451] | 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 | |
---|
[7850] | 154 | # Define a validation method for email addresses |
---|
[7221] | 155 | class NotAnEmailAddress(schema.ValidationError): |
---|
| 156 | __doc__ = u"Invalid email address" |
---|
| 157 | |
---|
[8638] | 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. |
---|
[7221] | 161 | check_email = re.compile( |
---|
[8638] | 162 | r"^[^@\s,]+@[^@\.\s,]+(\.[^@\.\s,]+)*$").match |
---|
[7221] | 163 | |
---|
| 164 | def validate_email(value): |
---|
| 165 | if not check_email(value): |
---|
| 166 | raise NotAnEmailAddress(value) |
---|
| 167 | return True |
---|
| 168 | |
---|
[12414] | 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. |
---|
[13029] | 174 | check_id = re.compile(r"^[a-zA-Z0-9_-]{2,10}$").match |
---|
[12414] | 175 | |
---|
| 176 | def validate_id(value): |
---|
| 177 | if not check_id(value): |
---|
| 178 | raise NotIdValue(value) |
---|
| 179 | return True |
---|
| 180 | |
---|
[7850] | 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): |
---|
[7851] | 189 | if not RE_INT_PHONE.match(value): |
---|
[7850] | 190 | raise InvalidPhoneNumber(value) |
---|
| 191 | return True |
---|
| 192 | |
---|
[4858] | 193 | class FatalCSVError(Exception): |
---|
| 194 | """Some row could not be processed. |
---|
| 195 | """ |
---|
| 196 | pass |
---|
| 197 | |
---|
[6226] | 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 | |
---|
[6143] | 213 | class RoleSource(BasicSourceFactory): |
---|
[7178] | 214 | """A source for site roles. |
---|
[6508] | 215 | """ |
---|
[6143] | 216 | def getValues(self): |
---|
[6157] | 217 | # late import: in interfaces we should not import local modules |
---|
[7811] | 218 | from waeup.kofa.permissions import get_waeup_role_names |
---|
[7186] | 219 | return get_waeup_role_names() |
---|
[6157] | 220 | |
---|
| 221 | def getTitle(self, value): |
---|
| 222 | # late import: in interfaces we should not import local modules |
---|
[7811] | 223 | from waeup.kofa.permissions import get_all_roles |
---|
[7186] | 224 | roles = dict(get_all_roles()) |
---|
[6157] | 225 | if value in roles.keys(): |
---|
| 226 | title = roles[value].title |
---|
[6569] | 227 | if '.' in title: |
---|
| 228 | title = title.split('.', 2)[1] |
---|
[6157] | 229 | return title |
---|
[6143] | 230 | |
---|
[7313] | 231 | class CaptchaSource(BasicSourceFactory): |
---|
| 232 | """A source for captchas. |
---|
| 233 | """ |
---|
| 234 | def getValues(self): |
---|
[7323] | 235 | captchas = ['No captcha', 'Testing captcha', 'ReCaptcha'] |
---|
[7313] | 236 | try: |
---|
| 237 | # we have to 'try' because IConfiguration can only handle |
---|
[7817] | 238 | # interfaces from w.k.interface. |
---|
[7811] | 239 | from waeup.kofa.browser.interfaces import ICaptchaManager |
---|
[7313] | 240 | except: |
---|
| 241 | return captchas |
---|
| 242 | return sorted(getUtility(ICaptchaManager).getAvailCaptchas().keys()) |
---|
| 243 | |
---|
| 244 | def getTitle(self, value): |
---|
| 245 | return value |
---|
| 246 | |
---|
[7795] | 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 | |
---|
[7819] | 266 | class IKofaUtils(Interface): |
---|
[7358] | 267 | """A collection of methods which are subject to customization. |
---|
| 268 | """ |
---|
[7568] | 269 | |
---|
[7841] | 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") |
---|
[11799] | 273 | EXAM_GRADES = Attribute("Dict of examination grades") |
---|
[7841] | 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") |
---|
[11799] | 278 | SYSTEM_MAX_LOAD = Attribute("Dict of maximum system loads.") |
---|
[7568] | 279 | |
---|
[7404] | 280 | def sendContactForm( |
---|
| 281 | from_name,from_addr,rcpt_name,rcpt_addr, |
---|
| 282 | from_username,usertype,portal,body,subject): |
---|
[7358] | 283 | """Send an email with data provided by forms. |
---|
| 284 | """ |
---|
| 285 | |
---|
[7475] | 286 | def fullname(firstname,lastname,middlename): |
---|
| 287 | """Full name constructor. |
---|
| 288 | """ |
---|
| 289 | |
---|
[8853] | 290 | def sendCredentials(user, password, url_info, msg): |
---|
[7475] | 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 | |
---|
[7819] | 303 | class IKofaObject(Interface): |
---|
| 304 | """A Kofa object. |
---|
[5663] | 305 | |
---|
| 306 | This is merely a marker interface. |
---|
[4789] | 307 | """ |
---|
| 308 | |
---|
[7819] | 309 | class IUniversity(IKofaObject): |
---|
[3521] | 310 | """Representation of a university. |
---|
| 311 | """ |
---|
[5955] | 312 | |
---|
[6065] | 313 | |
---|
[7819] | 314 | class IKofaContainer(IKofaObject): |
---|
| 315 | """A container for Kofa objects. |
---|
[4789] | 316 | """ |
---|
| 317 | |
---|
[7819] | 318 | class IKofaContained(IKofaObject): |
---|
| 319 | """An item contained in an IKofaContainer. |
---|
[4789] | 320 | """ |
---|
[6136] | 321 | |
---|
[7726] | 322 | class ICSVExporter(Interface): |
---|
| 323 | """A CSV file exporter for objects. |
---|
| 324 | """ |
---|
| 325 | fields = Attribute("""List of fieldnames in resulting CSV""") |
---|
[7907] | 326 | |
---|
| 327 | title = schema.TextLine( |
---|
| 328 | title = u'Title', |
---|
| 329 | description = u'Description to be displayed in selections.', |
---|
| 330 | ) |
---|
[7726] | 331 | def mangle_value(value, name, obj): |
---|
| 332 | """Mangle `value` extracted from `obj` or suobjects thereof. |
---|
| 333 | |
---|
[8394] | 334 | This is called by export before actually writing to the result |
---|
| 335 | file. |
---|
[7726] | 336 | """ |
---|
| 337 | |
---|
[9797] | 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 | |
---|
[12516] | 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 | |
---|
[7730] | 355 | def export(iterable, filepath=None): |
---|
| 356 | """Export iterables as rows in a CSV file. |
---|
[7726] | 357 | |
---|
[8394] | 358 | If `filepath` is not given, a string with the data should be |
---|
| 359 | returned. |
---|
[7730] | 360 | |
---|
| 361 | What kind of iterables are acceptable depends on the specific |
---|
| 362 | exporter implementation. |
---|
[7726] | 363 | """ |
---|
| 364 | |
---|
[9766] | 365 | def export_all(site, filepath=None): |
---|
[7726] | 366 | """Export all items in `site` as CSV file. |
---|
| 367 | |
---|
[8394] | 368 | if `filepath` is not given, a string with the data should be |
---|
| 369 | returned. |
---|
[7726] | 370 | """ |
---|
| 371 | |
---|
[9797] | 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 | |
---|
[12516] | 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 | |
---|
[7819] | 390 | class IKofaExporter(Interface): |
---|
[4789] | 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 | |
---|
[7819] | 402 | class IKofaXMLExporter(Interface): |
---|
[4789] | 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 | |
---|
[7819] | 414 | class IKofaXMLImporter(Interface): |
---|
[4789] | 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 | |
---|
[4858] | 423 | class IBatchProcessor(Interface): |
---|
| 424 | """A batch processor that handles mass-operations. |
---|
| 425 | """ |
---|
| 426 | name = schema.TextLine( |
---|
[7933] | 427 | title = _(u'Processor name') |
---|
[4858] | 428 | ) |
---|
| 429 | |
---|
[5476] | 430 | def doImport(path, headerfields, mode='create', user='Unknown', |
---|
[8218] | 431 | logger=None, ignore_empty=True): |
---|
[4858] | 432 | """Read data from ``path`` and update connected object. |
---|
[5476] | 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. |
---|
[8218] | 444 | |
---|
| 445 | `ignore_emtpy` in update mode ignores empty fields if true. |
---|
[4858] | 446 | """ |
---|
| 447 | |
---|
[7819] | 448 | class IContactForm(IKofaObject): |
---|
[7225] | 449 | """A contact form. |
---|
| 450 | """ |
---|
| 451 | |
---|
| 452 | email_from = schema.ASCIILine( |
---|
[7828] | 453 | title = _(u'Email Address:'), |
---|
[7225] | 454 | default = None, |
---|
| 455 | required = True, |
---|
| 456 | constraint=validate_email, |
---|
| 457 | ) |
---|
| 458 | |
---|
| 459 | email_to = schema.ASCIILine( |
---|
[7828] | 460 | title = _(u'Email to:'), |
---|
[7225] | 461 | default = None, |
---|
| 462 | required = True, |
---|
| 463 | constraint=validate_email, |
---|
| 464 | ) |
---|
| 465 | |
---|
| 466 | subject = schema.TextLine( |
---|
[7828] | 467 | title = _(u'Subject:'), |
---|
[7225] | 468 | required = True,) |
---|
| 469 | |
---|
| 470 | fullname = schema.TextLine( |
---|
[7828] | 471 | title = _(u'Full Name:'), |
---|
[7225] | 472 | required = True,) |
---|
| 473 | |
---|
| 474 | body = schema.Text( |
---|
[7828] | 475 | title = _(u'Text:'), |
---|
[7225] | 476 | required = True,) |
---|
| 477 | |
---|
[7819] | 478 | class IKofaPrincipalInfo(IPrincipalInfo): |
---|
| 479 | """Infos about principals that are users of Kofa Kofa. |
---|
[7233] | 480 | """ |
---|
| 481 | email = Attribute("The email address of a user") |
---|
| 482 | phone = Attribute("The phone number of a user") |
---|
[8757] | 483 | public_name = Attribute("The public name of a user") |
---|
[12915] | 484 | user_type = Attribute("The type of a user") |
---|
[7225] | 485 | |
---|
[7233] | 486 | |
---|
[7819] | 487 | class IKofaPrincipal(IPrincipal): |
---|
| 488 | """A principle for Kofa Kofa. |
---|
[7233] | 489 | |
---|
| 490 | This interface extends zope.security.interfaces.IPrincipal and |
---|
| 491 | requires also an `id` and other attributes defined there. |
---|
| 492 | """ |
---|
| 493 | |
---|
| 494 | email = schema.TextLine( |
---|
[7828] | 495 | title = _(u'Email Address'), |
---|
[7233] | 496 | description = u'', |
---|
| 497 | required=False,) |
---|
| 498 | |
---|
[8176] | 499 | phone = PhoneNumber( |
---|
[7828] | 500 | title = _(u'Phone'), |
---|
[7233] | 501 | description = u'', |
---|
| 502 | required=False,) |
---|
| 503 | |
---|
[8757] | 504 | public_name = schema.TextLine( |
---|
| 505 | title = _(u'Public Name'), |
---|
| 506 | required = False,) |
---|
| 507 | |
---|
[12915] | 508 | user_type = Attribute('The user type of the principal') |
---|
| 509 | |
---|
[10055] | 510 | class IFailedLoginInfo(IKofaObject): |
---|
| 511 | """Info about failed logins. |
---|
| 512 | |
---|
| 513 | Timestamps are supposed to be stored as floats using time.time() |
---|
| 514 | or similar. |
---|
| 515 | """ |
---|
| 516 | num = schema.Int( |
---|
| 517 | title = _(u'Number of failed logins'), |
---|
| 518 | description = _(u'Number of failed logins'), |
---|
| 519 | required = True, |
---|
| 520 | default = 0, |
---|
| 521 | ) |
---|
| 522 | |
---|
| 523 | last = schema.Float( |
---|
| 524 | title = _(u'Timestamp'), |
---|
| 525 | description = _(u'Timestamp of last failed login or `None`'), |
---|
| 526 | required = False, |
---|
| 527 | default = None, |
---|
| 528 | ) |
---|
| 529 | |
---|
| 530 | def as_tuple(): |
---|
| 531 | """Get login info as tuple ``<NUM>, <TIMESTAMP>``. |
---|
| 532 | """ |
---|
| 533 | |
---|
| 534 | def set_values(num=0, last=None): |
---|
| 535 | """Set number of failed logins and timestamp of last one. |
---|
| 536 | """ |
---|
| 537 | |
---|
| 538 | def increase(): |
---|
| 539 | """Increase the current number of failed logins and set timestamp. |
---|
| 540 | """ |
---|
| 541 | |
---|
| 542 | def reset(): |
---|
| 543 | """Set failed login counters back to zero. |
---|
| 544 | """ |
---|
| 545 | |
---|
| 546 | |
---|
[7819] | 547 | class IUserAccount(IKofaObject): |
---|
[4789] | 548 | """A user account. |
---|
| 549 | """ |
---|
[10055] | 550 | |
---|
[12926] | 551 | failed_logins = Attribute('FailedLoginInfo for this account') |
---|
[10055] | 552 | |
---|
[4789] | 553 | name = schema.TextLine( |
---|
[7828] | 554 | title = _(u'User Id'), |
---|
[12926] | 555 | description = _(u'Login name of user'), |
---|
[4789] | 556 | required = True,) |
---|
[7221] | 557 | |
---|
[4789] | 558 | title = schema.TextLine( |
---|
[7828] | 559 | title = _(u'Full Name'), |
---|
[8759] | 560 | required = True,) |
---|
[7221] | 561 | |
---|
[8756] | 562 | public_name = schema.TextLine( |
---|
| 563 | title = _(u'Public Name'), |
---|
[12926] | 564 | description = _(u"Substitute for officer's real name " |
---|
| 565 | "in student object histories."), |
---|
[8756] | 566 | required = False,) |
---|
| 567 | |
---|
[7197] | 568 | description = schema.Text( |
---|
[7828] | 569 | title = _(u'Description/Notice'), |
---|
[4789] | 570 | required = False,) |
---|
[7221] | 571 | |
---|
| 572 | email = schema.ASCIILine( |
---|
[7828] | 573 | title = _(u'Email Address'), |
---|
[7221] | 574 | default = None, |
---|
[7222] | 575 | required = True, |
---|
[7221] | 576 | constraint=validate_email, |
---|
| 577 | ) |
---|
| 578 | |
---|
[8176] | 579 | phone = PhoneNumber( |
---|
[7828] | 580 | title = _(u'Phone'), |
---|
[7233] | 581 | default = None, |
---|
[8062] | 582 | required = False, |
---|
[7233] | 583 | ) |
---|
| 584 | |
---|
[4789] | 585 | roles = schema.List( |
---|
[8486] | 586 | title = _(u'Portal Roles'), |
---|
[8079] | 587 | value_type = schema.Choice(source=RoleSource()), |
---|
| 588 | required = False, |
---|
| 589 | ) |
---|
[6136] | 590 | |
---|
[12926] | 591 | suspended = schema.Bool( |
---|
| 592 | title = _(u'Account suspended'), |
---|
| 593 | description = _(u'If set, the account is immediately blocked.'), |
---|
| 594 | default = False, |
---|
| 595 | required = False, |
---|
| 596 | ) |
---|
[10055] | 597 | |
---|
| 598 | |
---|
[7147] | 599 | class IPasswordValidator(Interface): |
---|
| 600 | """A password validator utility. |
---|
| 601 | """ |
---|
[6136] | 602 | |
---|
[7147] | 603 | def validate_password(password, password_repeat): |
---|
| 604 | """Validates a password by comparing it with |
---|
| 605 | control password and checking some other requirements. |
---|
| 606 | """ |
---|
| 607 | |
---|
| 608 | |
---|
[7819] | 609 | class IUsersContainer(IKofaObject): |
---|
[12915] | 610 | """A container for officers. |
---|
[4789] | 611 | """ |
---|
| 612 | |
---|
| 613 | def addUser(name, password, title=None, description=None): |
---|
| 614 | """Add a user. |
---|
| 615 | """ |
---|
| 616 | |
---|
| 617 | def delUser(name): |
---|
| 618 | """Delete a user if it exists. |
---|
| 619 | """ |
---|
| 620 | |
---|
[6141] | 621 | class ILocalRolesAssignable(Interface): |
---|
| 622 | """The local roles assignable to an object. |
---|
| 623 | """ |
---|
| 624 | def __call__(): |
---|
| 625 | """Returns a list of dicts. |
---|
| 626 | |
---|
| 627 | Each dict contains a ``name`` referring to the role assignable |
---|
| 628 | for the specified object and a `title` to describe the range |
---|
| 629 | of users to which this role can be assigned. |
---|
| 630 | """ |
---|
| 631 | |
---|
[7819] | 632 | class IConfigurationContainer(IKofaObject): |
---|
[6907] | 633 | """A container for session configuration objects. |
---|
| 634 | """ |
---|
| 635 | |
---|
| 636 | name = schema.TextLine( |
---|
[7828] | 637 | title = _(u'Name of University'), |
---|
| 638 | default = _(u'Sample University'), |
---|
[6907] | 639 | required = True, |
---|
| 640 | ) |
---|
| 641 | |
---|
[7459] | 642 | acronym = schema.TextLine( |
---|
[7828] | 643 | title = _(u'Abbreviated Title of University'), |
---|
[7819] | 644 | default = u'WAeUP.Kofa', |
---|
[7459] | 645 | required = True, |
---|
| 646 | ) |
---|
| 647 | |
---|
[6907] | 648 | frontpage = schema.Text( |
---|
[8361] | 649 | title = _(u'Content in HTML format'), |
---|
[6907] | 650 | required = False, |
---|
[8361] | 651 | default = default_html_frontpage, |
---|
[6907] | 652 | ) |
---|
| 653 | |
---|
[7702] | 654 | frontpage_dict = schema.Dict( |
---|
| 655 | title = u'Content as language dictionary with values in html format', |
---|
[7485] | 656 | required = False, |
---|
[7702] | 657 | default = {}, |
---|
[7485] | 658 | ) |
---|
| 659 | |
---|
[7223] | 660 | name_admin = schema.TextLine( |
---|
[7828] | 661 | title = _(u'Name of Administrator'), |
---|
[7223] | 662 | default = u'Administrator', |
---|
[8230] | 663 | required = True, |
---|
[7223] | 664 | ) |
---|
| 665 | |
---|
[7221] | 666 | email_admin = schema.ASCIILine( |
---|
[7828] | 667 | title = _(u'Email Address of Administrator'), |
---|
[7221] | 668 | default = 'contact@waeup.org', |
---|
[8230] | 669 | required = True, |
---|
[7221] | 670 | constraint=validate_email, |
---|
| 671 | ) |
---|
| 672 | |
---|
| 673 | email_subject = schema.TextLine( |
---|
[7828] | 674 | title = _(u'Subject of Email to Administrator'), |
---|
| 675 | default = _(u'Kofa Contact'), |
---|
[8230] | 676 | required = True, |
---|
[7221] | 677 | ) |
---|
| 678 | |
---|
[7470] | 679 | smtp_mailer = schema.Choice( |
---|
[7828] | 680 | title = _(u'SMTP mailer to use when sending mail'), |
---|
[7470] | 681 | vocabulary = 'Mail Delivery Names', |
---|
| 682 | default = 'No email service', |
---|
| 683 | required = True, |
---|
| 684 | ) |
---|
| 685 | |
---|
[7313] | 686 | captcha = schema.Choice( |
---|
[7828] | 687 | title = _(u'Captcha used for public registration pages'), |
---|
[7313] | 688 | source = CaptchaSource(), |
---|
| 689 | default = u'No captcha', |
---|
| 690 | required = True, |
---|
| 691 | ) |
---|
[7221] | 692 | |
---|
[7664] | 693 | carry_over = schema.Bool( |
---|
[7828] | 694 | title = _(u'Carry-over Course Registration'), |
---|
[7664] | 695 | default = False, |
---|
| 696 | ) |
---|
| 697 | |
---|
[10627] | 698 | current_academic_session = schema.Choice( |
---|
| 699 | title = _(u'Current Academic Session'), |
---|
[10631] | 700 | description = _(u'Session for which score editing is allowed'), |
---|
[10627] | 701 | source = academic_sessions_vocab, |
---|
| 702 | default = None, |
---|
| 703 | required = False, |
---|
| 704 | readonly = False, |
---|
| 705 | ) |
---|
| 706 | |
---|
[11589] | 707 | next_matric_integer = schema.Int( |
---|
| 708 | title = _(u'Next Matriculation Number Integer'), |
---|
| 709 | description = _(u'Integer used for constructing the next ' |
---|
| 710 | 'matriculation number'), |
---|
| 711 | default = 0, |
---|
| 712 | readonly = False, |
---|
| 713 | required = False, |
---|
| 714 | ) |
---|
| 715 | |
---|
[7819] | 716 | class ISessionConfiguration(IKofaObject): |
---|
[6915] | 717 | """A session configuration object. |
---|
[6907] | 718 | """ |
---|
| 719 | |
---|
[6915] | 720 | academic_session = schema.Choice( |
---|
[7828] | 721 | title = _(u'Academic Session'), |
---|
[6915] | 722 | source = academic_sessions_vocab, |
---|
| 723 | default = None, |
---|
| 724 | required = True, |
---|
| 725 | readonly = True, |
---|
| 726 | ) |
---|
| 727 | |
---|
[13033] | 728 | clearance_enabled = schema.Bool( |
---|
| 729 | title = _(u'Clearance enabled'), |
---|
| 730 | default = False, |
---|
| 731 | ) |
---|
| 732 | |
---|
| 733 | payment_disabled = schema.List( |
---|
| 734 | title = _(u'Payment disabled'), |
---|
| 735 | value_type = schema.Choice( |
---|
| 736 | source = DisablePaymentGroupSource(), |
---|
| 737 | ), |
---|
| 738 | required = False, |
---|
| 739 | default = [], |
---|
| 740 | ) |
---|
| 741 | |
---|
[13034] | 742 | coursereg_deadline = schema.Datetime( |
---|
| 743 | title = _(u'Course Reg. Deadline'), |
---|
| 744 | required = False, |
---|
| 745 | description = _('Example: ') + u'2011-12-31 23:59:59+01:00', |
---|
| 746 | ) |
---|
| 747 | |
---|
| 748 | late_registration_fee = schema.Float( |
---|
| 749 | title = _(u'Late Course Reg. Fee'), |
---|
| 750 | default = 0.0, |
---|
| 751 | required = False, |
---|
| 752 | ) |
---|
| 753 | |
---|
[8260] | 754 | application_fee = schema.Float( |
---|
| 755 | title = _(u'Application Fee'), |
---|
[7927] | 756 | default = 0.0, |
---|
[7881] | 757 | required = False, |
---|
[6916] | 758 | ) |
---|
| 759 | |
---|
[8260] | 760 | clearance_fee = schema.Float( |
---|
[9243] | 761 | title = _(u'Acceptance Fee'), |
---|
[7927] | 762 | default = 0.0, |
---|
[7881] | 763 | required = False, |
---|
[6993] | 764 | ) |
---|
| 765 | |
---|
[8260] | 766 | booking_fee = schema.Float( |
---|
| 767 | title = _(u'Bed Booking Fee'), |
---|
[7927] | 768 | default = 0.0, |
---|
[7881] | 769 | required = False, |
---|
[7250] | 770 | ) |
---|
| 771 | |
---|
[9423] | 772 | maint_fee = schema.Float( |
---|
[10680] | 773 | title = _(u'Rent (fallback)'), |
---|
[9423] | 774 | default = 0.0, |
---|
| 775 | required = False, |
---|
| 776 | ) |
---|
| 777 | |
---|
[10449] | 778 | transcript_fee = schema.Float( |
---|
| 779 | title = _(u'Transcript Fee'), |
---|
| 780 | default = 0.0, |
---|
| 781 | required = False, |
---|
| 782 | ) |
---|
| 783 | |
---|
[6918] | 784 | def getSessionString(): |
---|
| 785 | """Returns the session string from the vocabulary. |
---|
| 786 | """ |
---|
| 787 | |
---|
| 788 | |
---|
[6916] | 789 | class ISessionConfigurationAdd(ISessionConfiguration): |
---|
| 790 | """A session configuration object in add mode. |
---|
| 791 | """ |
---|
| 792 | |
---|
| 793 | academic_session = schema.Choice( |
---|
[7828] | 794 | title = _(u'Academic Session'), |
---|
[6916] | 795 | source = academic_sessions_vocab, |
---|
| 796 | default = None, |
---|
| 797 | required = True, |
---|
| 798 | readonly = False, |
---|
| 799 | ) |
---|
| 800 | |
---|
| 801 | ISessionConfigurationAdd['academic_session'].order = ISessionConfiguration[ |
---|
| 802 | 'academic_session'].order |
---|
| 803 | |
---|
[7819] | 804 | class IDataCenter(IKofaObject): |
---|
[4789] | 805 | """A data center. |
---|
| 806 | |
---|
[8394] | 807 | A data center manages files (uploads, downloads, etc.). |
---|
| 808 | |
---|
| 809 | Beside providing the bare paths needed to keep files, it also |
---|
| 810 | provides some helpers to put results of batch processing into |
---|
| 811 | well-defined final locations (with well-defined filenames). |
---|
| 812 | |
---|
| 813 | The main use-case is managing of site-related files, i.e. files |
---|
| 814 | for import, export etc. |
---|
| 815 | |
---|
| 816 | DataCenters are _not_ meant as storages for object-specific files |
---|
| 817 | like passport photographs and similar. |
---|
| 818 | |
---|
| 819 | It is up to the datacenter implementation how to organize data |
---|
| 820 | (paths) inside its storage path. |
---|
[4789] | 821 | """ |
---|
[8394] | 822 | storage = schema.Bytes( |
---|
| 823 | title = u'Path to directory where everything is kept.' |
---|
| 824 | ) |
---|
[4789] | 825 | |
---|
[8394] | 826 | deleted_path = schema.Bytes( |
---|
| 827 | title = u'Path were data about deleted objects should be stored.' |
---|
| 828 | ) |
---|
| 829 | |
---|
[9023] | 830 | def getPendingFiles(sort='name'): |
---|
[8394] | 831 | """Get a list of files stored in `storage` sorted by basename. |
---|
| 832 | """ |
---|
[9023] | 833 | |
---|
[9074] | 834 | def getFinishedFiles(): |
---|
| 835 | """Get a list of files stored in `finished` subfolder of `storage`. |
---|
[9023] | 836 | """ |
---|
| 837 | |
---|
[8394] | 838 | def setStoragePath(path, move=False, overwrite=False): |
---|
| 839 | """Set the path where to store files. |
---|
| 840 | |
---|
| 841 | If `move` is True, move over files from the current location |
---|
| 842 | to the new one. |
---|
| 843 | |
---|
| 844 | If `overwrite` is also True, overwrite any already existing |
---|
| 845 | files of same name in target location. |
---|
| 846 | |
---|
| 847 | Triggers a DataCenterStorageMovedEvent. |
---|
| 848 | """ |
---|
| 849 | |
---|
| 850 | def distProcessedFiles(successful, source_path, finished_file, |
---|
| 851 | pending_file, mode='create', move_orig=True): |
---|
| 852 | """Distribute processed files over final locations. |
---|
| 853 | """ |
---|
| 854 | |
---|
| 855 | |
---|
[4789] | 856 | class IDataCenterFile(Interface): |
---|
| 857 | """A data center file. |
---|
| 858 | """ |
---|
[4858] | 859 | |
---|
| 860 | name = schema.TextLine( |
---|
| 861 | title = u'Filename') |
---|
| 862 | |
---|
| 863 | size = schema.TextLine( |
---|
| 864 | title = u'Human readable file size') |
---|
| 865 | |
---|
| 866 | uploaddate = schema.TextLine( |
---|
| 867 | title = u'Human readable upload datetime') |
---|
| 868 | |
---|
| 869 | lines = schema.Int( |
---|
| 870 | title = u'Number of lines in file') |
---|
[6136] | 871 | |
---|
[4789] | 872 | def getDate(): |
---|
| 873 | """Get creation timestamp from file in human readable form. |
---|
| 874 | """ |
---|
| 875 | |
---|
| 876 | def getSize(): |
---|
| 877 | """Get human readable size of file. |
---|
| 878 | """ |
---|
[4858] | 879 | |
---|
| 880 | def getLinesNumber(): |
---|
| 881 | """Get number of lines of file. |
---|
| 882 | """ |
---|
[4882] | 883 | |
---|
| 884 | class IDataCenterStorageMovedEvent(IObjectEvent): |
---|
| 885 | """Emitted, when the storage of a datacenter changes. |
---|
| 886 | """ |
---|
[5007] | 887 | |
---|
[6136] | 888 | class IObjectUpgradeEvent(IObjectEvent): |
---|
| 889 | """Can be fired, when an object shall be upgraded. |
---|
| 890 | """ |
---|
| 891 | |
---|
[6180] | 892 | class ILocalRoleSetEvent(IObjectEvent): |
---|
| 893 | """A local role was granted/revoked for a principal on an object. |
---|
| 894 | """ |
---|
| 895 | role_id = Attribute( |
---|
| 896 | "The role id that was set.") |
---|
| 897 | principal_id = Attribute( |
---|
| 898 | "The principal id for which the role was granted/revoked.") |
---|
| 899 | granted = Attribute( |
---|
| 900 | "Boolean. If false, then the role was revoked.") |
---|
| 901 | |
---|
[5007] | 902 | class IQueryResultItem(Interface): |
---|
| 903 | """An item in a search result. |
---|
| 904 | """ |
---|
| 905 | url = schema.TextLine( |
---|
| 906 | title = u'URL that links to the found item') |
---|
| 907 | title = schema.TextLine( |
---|
| 908 | title = u'Title displayed in search results.') |
---|
| 909 | description = schema.Text( |
---|
| 910 | title = u'Longer description of the item found.') |
---|
[6136] | 911 | |
---|
[7819] | 912 | class IKofaPluggable(Interface): |
---|
| 913 | """A component that might be plugged into a Kofa Kofa app. |
---|
[5658] | 914 | |
---|
| 915 | Components implementing this interface are referred to as |
---|
| 916 | 'plugins'. They are normally called when a new |
---|
[7811] | 917 | :class:`waeup.kofa.app.University` instance is created. |
---|
[5658] | 918 | |
---|
| 919 | Plugins can setup and update parts of the central site without the |
---|
[7811] | 920 | site object (normally a :class:`waeup.kofa.app.University` object) |
---|
[5658] | 921 | needing to know about that parts. The site simply collects all |
---|
| 922 | available plugins, calls them and the plugins care for their |
---|
[5676] | 923 | respective subarea like the applicants area or the datacenter |
---|
[5658] | 924 | area. |
---|
| 925 | |
---|
| 926 | Currently we have no mechanism to define an order of plugins. A |
---|
| 927 | plugin should therefore make no assumptions about the state of the |
---|
| 928 | site or other plugins being run before and instead do appropriate |
---|
| 929 | checks if necessary. |
---|
| 930 | |
---|
| 931 | Updates can be triggered for instance by the respective form in |
---|
| 932 | the site configuration. You normally do updates when the |
---|
| 933 | underlying software changed. |
---|
[5013] | 934 | """ |
---|
[5069] | 935 | def setup(site, name, logger): |
---|
| 936 | """Create an instance of the plugin. |
---|
[5013] | 937 | |
---|
[5658] | 938 | The method is meant to be called by the central app (site) |
---|
| 939 | when it is created. |
---|
| 940 | |
---|
| 941 | `site`: |
---|
| 942 | The site that requests a setup. |
---|
| 943 | |
---|
| 944 | `name`: |
---|
| 945 | The name under which the plugin was registered (utility name). |
---|
| 946 | |
---|
| 947 | `logger`: |
---|
| 948 | A standard Python logger for the plugins use. |
---|
[5069] | 949 | """ |
---|
| 950 | |
---|
| 951 | def update(site, name, logger): |
---|
| 952 | """Method to update an already existing plugin. |
---|
| 953 | |
---|
| 954 | This might be called by a site when something serious |
---|
[5658] | 955 | changes. It is a poor-man replacement for Zope generations |
---|
| 956 | (but probably more comprehensive and better understandable). |
---|
| 957 | |
---|
| 958 | `site`: |
---|
| 959 | The site that requests an update. |
---|
| 960 | |
---|
| 961 | `name`: |
---|
| 962 | The name under which the plugin was registered (utility name). |
---|
| 963 | |
---|
| 964 | `logger`: |
---|
| 965 | A standard Python logger for the plugins use. |
---|
[5069] | 966 | """ |
---|
[5898] | 967 | |
---|
[5899] | 968 | class IAuthPluginUtility(Interface): |
---|
[5898] | 969 | """A component that cares for authentication setup at site creation. |
---|
| 970 | |
---|
| 971 | Utilities providing this interface are looked up when a Pluggable |
---|
| 972 | Authentication Utility (PAU) for any |
---|
[7811] | 973 | :class:`waeup.kofa.app.University` instance is created and put |
---|
[5898] | 974 | into ZODB. |
---|
| 975 | |
---|
| 976 | The setup-code then calls the `register` method of the utility and |
---|
| 977 | expects a modified (or unmodified) version of the PAU back. |
---|
| 978 | |
---|
| 979 | This allows to define any authentication setup modifications by |
---|
| 980 | submodules or third-party modules/packages. |
---|
| 981 | """ |
---|
| 982 | |
---|
| 983 | def register(pau): |
---|
| 984 | """Register any plugins wanted to be in the PAU. |
---|
| 985 | """ |
---|
| 986 | |
---|
| 987 | def unregister(pau): |
---|
| 988 | """Unregister any plugins not wanted to be in the PAU. |
---|
| 989 | """ |
---|
[6273] | 990 | |
---|
| 991 | class IObjectConverter(Interface): |
---|
| 992 | """Object converters are available as simple adapters, adapting |
---|
| 993 | interfaces (not regular instances). |
---|
| 994 | |
---|
| 995 | """ |
---|
| 996 | |
---|
[6277] | 997 | def fromStringDict(self, data_dict, context, form_fields=None): |
---|
| 998 | """Convert values in `data_dict`. |
---|
[6273] | 999 | |
---|
[6277] | 1000 | Converts data in `data_dict` into real values based on |
---|
| 1001 | `context` and `form_fields`. |
---|
[6273] | 1002 | |
---|
[6277] | 1003 | `data_dict` is a mapping (dict) from field names to values |
---|
| 1004 | represented as strings. |
---|
[6273] | 1005 | |
---|
[6277] | 1006 | The fields (keys) to convert can be given in optional |
---|
| 1007 | `form_fields`. If given, form_fields should be an instance of |
---|
| 1008 | :class:`zope.formlib.form.Fields`. Suitable instances are for |
---|
| 1009 | example created by :class:`grok.AutoFields`. |
---|
[6273] | 1010 | |
---|
[6277] | 1011 | If no `form_fields` are given, a default is computed from the |
---|
| 1012 | associated interface. |
---|
[6273] | 1013 | |
---|
[6277] | 1014 | The `context` can be an existing object (implementing the |
---|
| 1015 | associated interface) or a factory name. If it is a string, we |
---|
| 1016 | try to create an object using |
---|
| 1017 | :func:`zope.component.createObject`. |
---|
| 1018 | |
---|
| 1019 | Returns a tuple ``(<FIELD_ERRORS>, <INVARIANT_ERRORS>, |
---|
| 1020 | <DATA_DICT>)`` where |
---|
| 1021 | |
---|
| 1022 | ``<FIELD_ERRORS>`` |
---|
| 1023 | is a list of tuples ``(<FIELD_NAME>, <ERROR>)`` for each |
---|
| 1024 | error that happened when validating the input data in |
---|
| 1025 | `data_dict` |
---|
| 1026 | |
---|
| 1027 | ``<INVARIANT_ERRORS>`` |
---|
| 1028 | is a list of invariant errors concerning several fields |
---|
| 1029 | |
---|
| 1030 | ``<DATA_DICT>`` |
---|
| 1031 | is a dict with the values from input dict converted. |
---|
| 1032 | |
---|
| 1033 | If errors happen, i.e. the error lists are not empty, always |
---|
| 1034 | an empty ``<DATA_DICT>`` is returned. |
---|
| 1035 | |
---|
[12836] | 1036 | If ``<DATA_DICT>`` is non-empty, there were no errors. |
---|
[6273] | 1037 | """ |
---|
[6293] | 1038 | |
---|
[7932] | 1039 | class IFieldConverter(Interface): |
---|
[8214] | 1040 | def request_data(name, value, schema_field, prefix='', mode='create'): |
---|
[7932] | 1041 | """Create a dict with key-value mapping as created by a request. |
---|
| 1042 | |
---|
| 1043 | `name` and `value` are expected to be parsed from CSV or a |
---|
| 1044 | similar input and represent an attribute to be set to a |
---|
| 1045 | representation of value. |
---|
| 1046 | |
---|
[8214] | 1047 | `mode` gives the mode of import. |
---|
| 1048 | |
---|
[7932] | 1049 | :meth:`update_request_data` is then requested to turn this |
---|
| 1050 | name and value into vars as they would be sent by a regular |
---|
| 1051 | form submit. This means we do not create the real values to be |
---|
| 1052 | set but we only define the values that would be sent in a |
---|
| 1053 | browser request to request the creation of those values. |
---|
| 1054 | |
---|
| 1055 | The returned dict should contain names and values of a faked |
---|
| 1056 | browser request for the given `schema_field`. |
---|
| 1057 | |
---|
| 1058 | Field converters are normally registered as adapters to some |
---|
| 1059 | specific zope.schema field. |
---|
| 1060 | """ |
---|
| 1061 | |
---|
[6338] | 1062 | class IObjectHistory(Interface): |
---|
| 1063 | |
---|
| 1064 | messages = schema.List( |
---|
| 1065 | title = u'List of messages stored', |
---|
| 1066 | required = True, |
---|
| 1067 | ) |
---|
| 1068 | |
---|
| 1069 | def addMessage(message): |
---|
| 1070 | """Add a message. |
---|
| 1071 | """ |
---|
[6353] | 1072 | |
---|
[7819] | 1073 | class IKofaWorkflowInfo(IWorkflowInfo): |
---|
[6353] | 1074 | """A :class:`hurry.workflow.workflow.WorkflowInfo` with additional |
---|
| 1075 | methods for convenience. |
---|
| 1076 | """ |
---|
| 1077 | def getManualTransitions(): |
---|
| 1078 | """Get allowed manual transitions. |
---|
| 1079 | |
---|
| 1080 | Get a sorted list of tuples containing the `transition_id` and |
---|
| 1081 | `title` of each allowed transition. |
---|
| 1082 | """ |
---|
[6481] | 1083 | |
---|
| 1084 | class ISiteLoggers(Interface): |
---|
| 1085 | |
---|
[7819] | 1086 | loggers = Attribute("A list or generator of registered KofaLoggers") |
---|
[6481] | 1087 | |
---|
| 1088 | def register(name, filename=None, site=None, **options): |
---|
| 1089 | """Register a logger `name` which logs to `filename`. |
---|
| 1090 | |
---|
| 1091 | If `filename` is not given, logfile will be `name` with |
---|
| 1092 | ``.log`` as filename extension. |
---|
| 1093 | """ |
---|
| 1094 | |
---|
| 1095 | def unregister(name): |
---|
| 1096 | """Unregister a once registered logger. |
---|
| 1097 | """ |
---|
| 1098 | |
---|
| 1099 | class ILogger(Interface): |
---|
| 1100 | """A logger cares for setup, update and restarting of a Python logger. |
---|
| 1101 | """ |
---|
| 1102 | |
---|
| 1103 | logger = Attribute("""A :class:`logging.Logger` instance""") |
---|
| 1104 | |
---|
| 1105 | |
---|
| 1106 | def __init__(name, filename=None, site=None, **options): |
---|
[7819] | 1107 | """Create a Kofa logger instance. |
---|
[6481] | 1108 | """ |
---|
| 1109 | |
---|
| 1110 | def setup(): |
---|
| 1111 | """Create a Python :class:`logging.Logger` instance. |
---|
| 1112 | |
---|
| 1113 | The created logger is based on the params given by constructor. |
---|
| 1114 | """ |
---|
| 1115 | |
---|
| 1116 | def update(**options): |
---|
| 1117 | """Update the logger. |
---|
| 1118 | |
---|
| 1119 | Updates the logger respecting modified `options` and changed |
---|
| 1120 | paths. |
---|
| 1121 | """ |
---|
[6754] | 1122 | |
---|
| 1123 | class ILoggerCollector(Interface): |
---|
| 1124 | |
---|
| 1125 | def getLoggers(site): |
---|
| 1126 | """Return all loggers registered for `site`. |
---|
| 1127 | """ |
---|
| 1128 | |
---|
| 1129 | def registerLogger(site, logging_component): |
---|
| 1130 | """Register a logging component residing in `site`. |
---|
| 1131 | """ |
---|
| 1132 | |
---|
| 1133 | def unregisterLogger(site, logging_component): |
---|
| 1134 | """Unregister a logger. |
---|
| 1135 | """ |
---|
[7063] | 1136 | |
---|
| 1137 | # |
---|
| 1138 | # External File Storage and relatives |
---|
| 1139 | # |
---|
| 1140 | class IFileStoreNameChooser(INameChooser): |
---|
| 1141 | """See zope.container.interfaces.INameChooser for base methods. |
---|
| 1142 | """ |
---|
[7066] | 1143 | def checkName(name, attr=None): |
---|
[7063] | 1144 | """Check whether an object name is valid. |
---|
| 1145 | |
---|
| 1146 | Raises a user error if the name is not valid. |
---|
| 1147 | """ |
---|
| 1148 | |
---|
[7066] | 1149 | def chooseName(name, attr=None): |
---|
| 1150 | """Choose a unique valid file id for the object. |
---|
[7063] | 1151 | |
---|
[7066] | 1152 | The given name may be taken into account when choosing the |
---|
| 1153 | name (file id). |
---|
[7063] | 1154 | |
---|
[7066] | 1155 | chooseName is expected to always choose a valid file id (that |
---|
| 1156 | would pass the checkName test) and never raise an error. |
---|
| 1157 | |
---|
| 1158 | If `attr` is not ``None`` it might been taken into account as |
---|
| 1159 | well when generating the file id. Usual behaviour is to |
---|
| 1160 | interpret `attr` as a hint for what type of file for a given |
---|
| 1161 | context should be stored if there are several types |
---|
| 1162 | possible. For instance for a certain student some file could |
---|
| 1163 | be the connected passport photograph or some certificate scan |
---|
| 1164 | or whatever. Each of them has to be stored in a different |
---|
| 1165 | location so setting `attr` to a sensible value should give |
---|
| 1166 | different file ids returned. |
---|
[7063] | 1167 | """ |
---|
| 1168 | |
---|
| 1169 | class IExtFileStore(IFileRetrieval): |
---|
| 1170 | """A file storage that stores files in filesystem (not as blobs). |
---|
| 1171 | """ |
---|
| 1172 | root = schema.TextLine( |
---|
| 1173 | title = u'Root path of file store.', |
---|
| 1174 | ) |
---|
| 1175 | |
---|
| 1176 | def getFile(file_id): |
---|
| 1177 | """Get raw file data stored under file with `file_id`. |
---|
| 1178 | |
---|
| 1179 | Returns a file descriptor open for reading or ``None`` if the |
---|
| 1180 | file cannot be found. |
---|
| 1181 | """ |
---|
| 1182 | |
---|
[7071] | 1183 | def getFileByContext(context, attr=None): |
---|
[7063] | 1184 | """Get raw file data stored for the given context. |
---|
| 1185 | |
---|
| 1186 | Returns a file descriptor open for reading or ``None`` if no |
---|
| 1187 | such file can be found. |
---|
| 1188 | |
---|
[7071] | 1189 | Both, `context` and `attr` might be used to find (`context`) |
---|
| 1190 | and feed (`attr`) an appropriate file name chooser. |
---|
| 1191 | |
---|
[7063] | 1192 | This is a convenience method. |
---|
| 1193 | """ |
---|
| 1194 | |
---|
[7090] | 1195 | def deleteFile(file_id): |
---|
| 1196 | """Delete file stored under `file_id`. |
---|
| 1197 | |
---|
| 1198 | Remove file from filestore so, that it is not available |
---|
| 1199 | anymore on next call to getFile for the same file_id. |
---|
| 1200 | |
---|
| 1201 | Should not complain if no such file exists. |
---|
| 1202 | """ |
---|
| 1203 | |
---|
| 1204 | def deleteFileByContext(context, attr=None): |
---|
| 1205 | """Delete file for given `context` and `attr`. |
---|
| 1206 | |
---|
| 1207 | Both, `context` and `attr` might be used to find (`context`) |
---|
| 1208 | and feed (`attr`) an appropriate file name chooser. |
---|
| 1209 | |
---|
| 1210 | This is a convenience method. |
---|
| 1211 | """ |
---|
| 1212 | |
---|
[7063] | 1213 | def createFile(filename, f): |
---|
| 1214 | """Create file given by f with filename `filename` |
---|
| 1215 | |
---|
| 1216 | Returns a hurry.file.File-based object. |
---|
| 1217 | """ |
---|
| 1218 | |
---|
| 1219 | class IFileStoreHandler(Interface): |
---|
| 1220 | """Filestore handlers handle specific files for file stores. |
---|
| 1221 | |
---|
| 1222 | If a file to store/get provides a specific filename, a file store |
---|
| 1223 | looks up special handlers for that type of file. |
---|
| 1224 | |
---|
| 1225 | """ |
---|
| 1226 | def pathFromFileID(store, root, filename): |
---|
| 1227 | """Turn file id into path to store. |
---|
| 1228 | |
---|
| 1229 | Returned path should be absolute. |
---|
| 1230 | """ |
---|
| 1231 | |
---|
| 1232 | def createFile(store, root, filename, file_id, file): |
---|
| 1233 | """Return some hurry.file based on `store` and `file_id`. |
---|
| 1234 | |
---|
| 1235 | Some kind of callback method called by file stores to create |
---|
| 1236 | file objects from file_id. |
---|
| 1237 | |
---|
| 1238 | Returns a tuple ``(raw_file, path, file_like_obj)`` where the |
---|
[7819] | 1239 | ``file_like_obj`` should be a HurryFile, a KofaImageFile or |
---|
[7063] | 1240 | similar. ``raw_file`` is the (maybe changed) input file and |
---|
| 1241 | ``path`` the relative internal path to store the file at. |
---|
| 1242 | |
---|
| 1243 | Please make sure the ``raw_file`` is opened for reading and |
---|
| 1244 | the file descriptor set at position 0 when returned. |
---|
| 1245 | |
---|
| 1246 | This method also gets the raw input file object that is about |
---|
| 1247 | to be stored and is expected to raise any exceptions if some |
---|
| 1248 | kind of validation or similar fails. |
---|
| 1249 | """ |
---|
[7389] | 1250 | |
---|
| 1251 | class IPDF(Interface): |
---|
| 1252 | """A PDF representation of some context. |
---|
| 1253 | """ |
---|
| 1254 | |
---|
[8257] | 1255 | def __call__(view=None, note=None): |
---|
[7389] | 1256 | """Create a bytestream representing a PDF from context. |
---|
| 1257 | |
---|
| 1258 | If `view` is passed in additional infos might be rendered into |
---|
| 1259 | the document. |
---|
[8257] | 1260 | |
---|
| 1261 | `note` is optional HTML rendered at bottom of the created |
---|
| 1262 | PDF. Please consider the limited reportlab support for HTML, |
---|
| 1263 | but using font-tags and friends you certainly can get the |
---|
| 1264 | desired look. |
---|
[7389] | 1265 | """ |
---|
[7473] | 1266 | |
---|
| 1267 | class IMailService(Interface): |
---|
| 1268 | """A mail service. |
---|
| 1269 | """ |
---|
| 1270 | |
---|
| 1271 | def __call__(): |
---|
| 1272 | """Get the default mail delivery. |
---|
| 1273 | """ |
---|
[7576] | 1274 | |
---|
[9217] | 1275 | |
---|
[7576] | 1276 | class IDataCenterConfig(Interface): |
---|
| 1277 | path = Path( |
---|
| 1278 | title = u'Path', |
---|
[7828] | 1279 | description = u"Directory where the datacenter should store " |
---|
| 1280 | u"files by default (adjustable in web UI).", |
---|
[7576] | 1281 | required = True, |
---|
| 1282 | ) |
---|
[8346] | 1283 | |
---|
[9217] | 1284 | # |
---|
| 1285 | # Asynchronous job handling and related |
---|
| 1286 | # |
---|
| 1287 | class IJobManager(IKofaObject): |
---|
| 1288 | """A manager for asynchronous running jobs (tasks). |
---|
| 1289 | """ |
---|
| 1290 | def put(job, site=None): |
---|
| 1291 | """Put a job into task queue. |
---|
[8346] | 1292 | |
---|
[9217] | 1293 | If no `site` is given, queue job in context of current local |
---|
| 1294 | site. |
---|
| 1295 | |
---|
| 1296 | Returns a job_id to identify the put job. This job_id is |
---|
| 1297 | needed for further references to the job. |
---|
| 1298 | """ |
---|
| 1299 | |
---|
| 1300 | def jobs(site=None): |
---|
| 1301 | """Get an iterable of jobs stored. |
---|
| 1302 | """ |
---|
| 1303 | |
---|
| 1304 | def get(job_id, site=None): |
---|
| 1305 | """Get the job with id `job_id`. |
---|
| 1306 | |
---|
| 1307 | For the `site` parameter see :meth:`put`. |
---|
| 1308 | """ |
---|
| 1309 | |
---|
| 1310 | def remove(job_id, site=None): |
---|
| 1311 | """Remove job with `job_id` from stored jobs. |
---|
| 1312 | """ |
---|
| 1313 | |
---|
| 1314 | def start_test_job(site=None): |
---|
| 1315 | """Start a test job. |
---|
| 1316 | """ |
---|
| 1317 | |
---|
| 1318 | class IProgressable(Interface): |
---|
| 1319 | """A component that can indicate its progress status. |
---|
[8346] | 1320 | """ |
---|
[9217] | 1321 | percent = schema.Float( |
---|
| 1322 | title = u'Percent of job done already.', |
---|
[8346] | 1323 | ) |
---|
| 1324 | |
---|
[9217] | 1325 | class IJobContainer(IContainer): |
---|
| 1326 | """A job container contains IJob objects. |
---|
| 1327 | """ |
---|
| 1328 | |
---|
| 1329 | class IExportJob(zc.async.interfaces.IJob): |
---|
| 1330 | def __init__(site, exporter_name): |
---|
| 1331 | pass |
---|
| 1332 | |
---|
[9816] | 1333 | finished = schema.Bool( |
---|
| 1334 | title = u'`True` if the job finished.`', |
---|
| 1335 | default = False, |
---|
| 1336 | ) |
---|
| 1337 | |
---|
| 1338 | failed = schema.Bool( |
---|
| 1339 | title = u"`True` iff the job finished and didn't provide a file.", |
---|
| 1340 | default = None, |
---|
| 1341 | ) |
---|
| 1342 | |
---|
[9764] | 1343 | class IExportJobContainer(IKofaObject): |
---|
[9217] | 1344 | """A component that contains (maybe virtually) export jobs. |
---|
| 1345 | """ |
---|
[9718] | 1346 | def start_export_job(exporter_name, user_id, *args, **kwargs): |
---|
[9217] | 1347 | """Start asynchronous export job. |
---|
| 1348 | |
---|
| 1349 | `exporter_name` is the name of an exporter utility to be used. |
---|
| 1350 | |
---|
| 1351 | `user_id` is the ID of the user that triggers the export. |
---|
| 1352 | |
---|
[9718] | 1353 | `args` positional arguments passed to the export job created. |
---|
| 1354 | |
---|
| 1355 | `kwargs` keyword arguments passed to the export job. |
---|
| 1356 | |
---|
[9217] | 1357 | The job_id is stored along with exporter name and user id in a |
---|
| 1358 | persistent list. |
---|
| 1359 | |
---|
| 1360 | Returns the job ID of the job started. |
---|
| 1361 | """ |
---|
| 1362 | |
---|
| 1363 | def get_running_export_jobs(user_id=None): |
---|
| 1364 | """Get export jobs for user with `user_id` as list of tuples. |
---|
| 1365 | |
---|
| 1366 | Each tuples holds ``<job_id>, <exporter_name>, <user_id>`` in |
---|
| 1367 | that order. The ``<exporter_name>`` is the utility name of the |
---|
| 1368 | used exporter. |
---|
| 1369 | |
---|
| 1370 | If `user_id` is ``None``, all running jobs are returned. |
---|
| 1371 | """ |
---|
| 1372 | |
---|
| 1373 | def get_export_jobs_status(user_id=None): |
---|
| 1374 | """Get running/completed export jobs for `user_id` as list of tuples. |
---|
| 1375 | |
---|
| 1376 | Each tuple holds ``<raw status>, <status translated>, |
---|
| 1377 | <exporter title>`` in that order, where ``<status |
---|
| 1378 | translated>`` and ``<exporter title>`` are translated strings |
---|
| 1379 | representing the status of the job and the human readable |
---|
| 1380 | title of the exporter used. |
---|
| 1381 | """ |
---|
| 1382 | |
---|
| 1383 | def delete_export_entry(entry): |
---|
| 1384 | """Delete the export denoted by `entry`. |
---|
| 1385 | |
---|
| 1386 | Removes `entry` from the local `running_exports` list and also |
---|
| 1387 | removes the regarding job via the local job manager. |
---|
| 1388 | |
---|
| 1389 | `entry` is a tuple ``(<job id>, <exporter name>, <user id>)`` |
---|
| 1390 | as created by :meth:`start_export_job` or returned by |
---|
| 1391 | :meth:`get_running_export_jobs`. |
---|
| 1392 | """ |
---|
| 1393 | |
---|
| 1394 | def entry_from_job_id(job_id): |
---|
| 1395 | """Get entry tuple for `job_id`. |
---|
| 1396 | |
---|
| 1397 | Returns ``None`` if no such entry can be found. |
---|
| 1398 | """ |
---|
[9726] | 1399 | |
---|
| 1400 | class IExportContainerFinder(Interface): |
---|
| 1401 | """A finder for the central export container. |
---|
| 1402 | """ |
---|
| 1403 | def __call__(): |
---|
| 1404 | """Return the currently used global or site-wide IExportContainer. |
---|
| 1405 | """ |
---|
[9766] | 1406 | |
---|
| 1407 | class IFilteredQuery(IKofaObject): |
---|
| 1408 | """A query for objects. |
---|
| 1409 | """ |
---|
| 1410 | |
---|
| 1411 | defaults = schema.Dict( |
---|
| 1412 | title = u'Default Parameters', |
---|
| 1413 | required = True, |
---|
| 1414 | ) |
---|
| 1415 | |
---|
| 1416 | def __init__(**parameters): |
---|
| 1417 | """Instantiate a filtered query by passing in parameters. |
---|
| 1418 | """ |
---|
| 1419 | |
---|
| 1420 | def query(): |
---|
| 1421 | """Get an iterable of objects denoted by the set parameters. |
---|
| 1422 | |
---|
| 1423 | The search should be applied to objects inside current |
---|
| 1424 | site. It's the caller's duty to set the correct site before. |
---|
| 1425 | |
---|
| 1426 | Result can be any iterable like a catalog result set, a list, |
---|
| 1427 | or similar. |
---|
| 1428 | """ |
---|
| 1429 | |
---|
| 1430 | class IFilteredCatalogQuery(IFilteredQuery): |
---|
| 1431 | """A catalog-based query for objects. |
---|
| 1432 | """ |
---|
| 1433 | |
---|
| 1434 | cat_name = schema.TextLine( |
---|
| 1435 | title = u'Registered name of the catalog to search.', |
---|
| 1436 | required = True, |
---|
| 1437 | ) |
---|
| 1438 | |
---|
| 1439 | def query_catalog(catalog): |
---|
| 1440 | """Query catalog with the parameters passed to constructor. |
---|
| 1441 | """ |
---|