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