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