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