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