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