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