[7193] | 1 | ## $Id: interfaces.py 9074 2012-07-28 04:47:58Z henrik $ |
---|
[3521] | 2 | ## |
---|
[7193] | 3 | ## Copyright (C) 2011 Uli Fouquet & Henrik Bettermann |
---|
| 4 | ## This program is free software; you can redistribute it and/or modify |
---|
| 5 | ## it under the terms of the GNU General Public License as published by |
---|
| 6 | ## the Free Software Foundation; either version 2 of the License, or |
---|
| 7 | ## (at your option) any later version. |
---|
| 8 | ## |
---|
| 9 | ## This program is distributed in the hope that it will be useful, |
---|
| 10 | ## but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
| 11 | ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
| 12 | ## GNU General Public License for more details. |
---|
| 13 | ## |
---|
| 14 | ## You should have received a copy of the GNU General Public License |
---|
| 15 | ## along with this program; if not, write to the Free Software |
---|
| 16 | ## Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
---|
| 17 | ## |
---|
[6361] | 18 | import os |
---|
[7221] | 19 | import re |
---|
[7702] | 20 | import codecs |
---|
[7670] | 21 | import zope.i18nmessageid |
---|
[6915] | 22 | from datetime import datetime |
---|
[7063] | 23 | from hurry.file.interfaces import IFileRetrieval |
---|
[8394] | 24 | from hurry.workflow.interfaces import IWorkflowInfo |
---|
[4789] | 25 | from zc.sourcefactory.basic import BasicSourceFactory |
---|
[6147] | 26 | from zope import schema |
---|
[7233] | 27 | from zope.pluggableauth.interfaces import IPrincipalInfo |
---|
| 28 | from zope.security.interfaces import IGroupClosureAwarePrincipal as IPrincipal |
---|
[4789] | 29 | from zope.component import getUtility |
---|
[4882] | 30 | from zope.component.interfaces import IObjectEvent |
---|
[7063] | 31 | from zope.container.interfaces import INameChooser |
---|
[8394] | 32 | from zope.interface import Interface, Attribute |
---|
[7795] | 33 | from zope.schema.interfaces import IObject |
---|
[4789] | 34 | from zope.schema.vocabulary import SimpleVocabulary, SimpleTerm |
---|
[8176] | 35 | from waeup.kofa.schema import PhoneNumber |
---|
[3521] | 36 | |
---|
[7811] | 37 | _ = MessageFactory = zope.i18nmessageid.MessageFactory('waeup.kofa') |
---|
[6990] | 38 | |
---|
[8214] | 39 | DELETION_MARKER = 'XXX' |
---|
| 40 | IGNORE_MARKER = '<IGNORE>' |
---|
[8202] | 41 | |
---|
[7673] | 42 | CREATED = 'created' |
---|
| 43 | ADMITTED = 'admitted' |
---|
| 44 | CLEARANCE = 'clearance started' |
---|
| 45 | REQUESTED = 'clearance requested' |
---|
| 46 | CLEARED = 'cleared' |
---|
| 47 | PAID = 'school fee paid' |
---|
| 48 | RETURNING = 'returning' |
---|
| 49 | REGISTERED = 'courses registered' |
---|
| 50 | VALIDATED = 'courses validated' |
---|
[7670] | 51 | |
---|
[8361] | 52 | #default_rest_frontpage = u'' + codecs.open(os.path.join( |
---|
| 53 | # os.path.dirname(__file__), 'frontpage.rst'), |
---|
| 54 | # encoding='utf-8', mode='rb').read() |
---|
| 55 | |
---|
| 56 | default_html_frontpage = u'' + codecs.open(os.path.join( |
---|
| 57 | os.path.dirname(__file__), 'frontpage.html'), |
---|
[7702] | 58 | encoding='utf-8', mode='rb').read() |
---|
[6361] | 59 | |
---|
[7819] | 60 | def SimpleKofaVocabulary(*terms): |
---|
[6915] | 61 | """A well-buildt vocabulary provides terms with a value, token and |
---|
| 62 | title for each term |
---|
| 63 | """ |
---|
| 64 | return SimpleVocabulary([ |
---|
| 65 | SimpleTerm(value, value, title) for title, value in terms]) |
---|
| 66 | |
---|
| 67 | def year_range(): |
---|
| 68 | curr_year = datetime.now().year |
---|
[7459] | 69 | return range(curr_year - 4, curr_year + 5) |
---|
[6915] | 70 | |
---|
| 71 | def academic_sessions(): |
---|
| 72 | curr_year = datetime.now().year |
---|
[8948] | 73 | year_range = range(curr_year - 15, curr_year + 2) |
---|
[6915] | 74 | return [('%s/%s' % (year,year+1), year) for year in year_range] |
---|
| 75 | |
---|
[7819] | 76 | academic_sessions_vocab = SimpleKofaVocabulary(*academic_sessions()) |
---|
[6915] | 77 | |
---|
[7819] | 78 | registration_states_vocab = SimpleKofaVocabulary( |
---|
[7677] | 79 | (_('created'), CREATED), |
---|
| 80 | (_('admitted'), ADMITTED), |
---|
| 81 | (_('clearance started'), CLEARANCE), |
---|
| 82 | (_('clearance requested'), REQUESTED), |
---|
| 83 | (_('cleared'), CLEARED), |
---|
| 84 | (_('school fee paid'), PAID), |
---|
| 85 | (_('returning'), RETURNING), |
---|
| 86 | (_('courses registered'), REGISTERED), |
---|
| 87 | (_('courses validated'), VALIDATED), |
---|
[6990] | 88 | ) |
---|
| 89 | |
---|
[7795] | 90 | class SubjectSource(BasicSourceFactory): |
---|
[7918] | 91 | """A source for school subjects used in exam documentation. |
---|
| 92 | """ |
---|
[7795] | 93 | def getValues(self): |
---|
[7841] | 94 | subjects_dict = getUtility(IKofaUtils).EXAM_SUBJECTS_DICT |
---|
[7837] | 95 | return sorted(subjects_dict.keys()) |
---|
| 96 | |
---|
[7795] | 97 | def getTitle(self, value): |
---|
[7841] | 98 | subjects_dict = getUtility(IKofaUtils).EXAM_SUBJECTS_DICT |
---|
[7837] | 99 | return "%s:" % subjects_dict[value] |
---|
[7795] | 100 | |
---|
| 101 | class GradeSource(BasicSourceFactory): |
---|
[7918] | 102 | """A source for exam grades. |
---|
| 103 | """ |
---|
[7795] | 104 | def getValues(self): |
---|
[7918] | 105 | for entry in getUtility(IKofaUtils).EXAM_GRADES: |
---|
| 106 | yield entry[0] |
---|
[7837] | 107 | |
---|
[7795] | 108 | def getTitle(self, value): |
---|
[7918] | 109 | return dict(getUtility(IKofaUtils).EXAM_GRADES)[value] |
---|
[7795] | 110 | |
---|
[7850] | 111 | # Define a validation method for email addresses |
---|
[7221] | 112 | class NotAnEmailAddress(schema.ValidationError): |
---|
| 113 | __doc__ = u"Invalid email address" |
---|
| 114 | |
---|
[8638] | 115 | #: Regular expression to check email-address formats. As these can |
---|
| 116 | #: become rather complex (nearly everything is allowed by RFCs), we only |
---|
| 117 | #: forbid whitespaces, commas and dots following onto each other. |
---|
[7221] | 118 | check_email = re.compile( |
---|
[8638] | 119 | r"^[^@\s,]+@[^@\.\s,]+(\.[^@\.\s,]+)*$").match |
---|
[7221] | 120 | |
---|
| 121 | def validate_email(value): |
---|
| 122 | if not check_email(value): |
---|
| 123 | raise NotAnEmailAddress(value) |
---|
| 124 | return True |
---|
| 125 | |
---|
[7850] | 126 | # Define a validation method for international phone numbers |
---|
| 127 | class InvalidPhoneNumber(schema.ValidationError): |
---|
| 128 | __doc__ = u"Invalid phone number" |
---|
| 129 | |
---|
| 130 | # represent format +NNN-NNNN-NNNN |
---|
| 131 | RE_INT_PHONE = re.compile(r"^\+?\d+\-\d+\-[\d\-]+$") |
---|
| 132 | |
---|
| 133 | def validate_phone(value): |
---|
[7851] | 134 | if not RE_INT_PHONE.match(value): |
---|
[7850] | 135 | raise InvalidPhoneNumber(value) |
---|
| 136 | return True |
---|
| 137 | |
---|
[4858] | 138 | class FatalCSVError(Exception): |
---|
| 139 | """Some row could not be processed. |
---|
| 140 | """ |
---|
| 141 | pass |
---|
| 142 | |
---|
[6226] | 143 | class DuplicationError(Exception): |
---|
| 144 | """An exception that can be raised when duplicates are found. |
---|
| 145 | |
---|
| 146 | When raising :exc:`DuplicationError` you can, beside the usual |
---|
| 147 | message, specify a list of objects which are duplicates. These |
---|
| 148 | values can be used by catching code to print something helpful or |
---|
| 149 | similar. |
---|
| 150 | """ |
---|
| 151 | def __init__(self, msg, entries=[]): |
---|
| 152 | self.msg = msg |
---|
| 153 | self.entries = entries |
---|
| 154 | |
---|
| 155 | def __str__(self): |
---|
| 156 | return '%r' % self.msg |
---|
| 157 | |
---|
[6143] | 158 | class RoleSource(BasicSourceFactory): |
---|
[7178] | 159 | """A source for site roles. |
---|
[6508] | 160 | """ |
---|
[6143] | 161 | def getValues(self): |
---|
[6157] | 162 | # late import: in interfaces we should not import local modules |
---|
[7811] | 163 | from waeup.kofa.permissions import get_waeup_role_names |
---|
[7186] | 164 | return get_waeup_role_names() |
---|
[6157] | 165 | |
---|
| 166 | def getTitle(self, value): |
---|
| 167 | # late import: in interfaces we should not import local modules |
---|
[7811] | 168 | from waeup.kofa.permissions import get_all_roles |
---|
[7186] | 169 | roles = dict(get_all_roles()) |
---|
[6157] | 170 | if value in roles.keys(): |
---|
| 171 | title = roles[value].title |
---|
[6569] | 172 | if '.' in title: |
---|
| 173 | title = title.split('.', 2)[1] |
---|
[6157] | 174 | return title |
---|
[6143] | 175 | |
---|
[7313] | 176 | class CaptchaSource(BasicSourceFactory): |
---|
| 177 | """A source for captchas. |
---|
| 178 | """ |
---|
| 179 | def getValues(self): |
---|
[7323] | 180 | captchas = ['No captcha', 'Testing captcha', 'ReCaptcha'] |
---|
[7313] | 181 | try: |
---|
| 182 | # we have to 'try' because IConfiguration can only handle |
---|
[7817] | 183 | # interfaces from w.k.interface. |
---|
[7811] | 184 | from waeup.kofa.browser.interfaces import ICaptchaManager |
---|
[7313] | 185 | except: |
---|
| 186 | return captchas |
---|
| 187 | return sorted(getUtility(ICaptchaManager).getAvailCaptchas().keys()) |
---|
| 188 | |
---|
| 189 | def getTitle(self, value): |
---|
| 190 | return value |
---|
| 191 | |
---|
[7795] | 192 | class IResultEntry(Interface): |
---|
| 193 | """A school grade entry. |
---|
| 194 | """ |
---|
| 195 | subject = schema.Choice( |
---|
| 196 | title = _(u'Subject'), |
---|
| 197 | source = SubjectSource(), |
---|
| 198 | ) |
---|
| 199 | grade = schema.Choice( |
---|
| 200 | title = _(u'Grade'), |
---|
| 201 | source = GradeSource(), |
---|
| 202 | ) |
---|
| 203 | |
---|
| 204 | class IResultEntryField(IObject): |
---|
| 205 | """A zope.schema-like field for usage in interfaces. |
---|
| 206 | |
---|
| 207 | Marker interface to distuingish result entries from ordinary |
---|
| 208 | object fields. Needed for registration of widgets. |
---|
| 209 | """ |
---|
| 210 | |
---|
[7819] | 211 | class IKofaUtils(Interface): |
---|
[7358] | 212 | """A collection of methods which are subject to customization. |
---|
| 213 | """ |
---|
[7568] | 214 | |
---|
[7841] | 215 | PORTAL_LANGUAGE = Attribute("Dict of global language setting") |
---|
| 216 | PREFERRED_LANGUAGES_DICT = Attribute("Dict of preferred languages") |
---|
| 217 | EXAM_SUBJECTS_DICT = Attribute("Dict of examination subjects") |
---|
| 218 | EXAM_GRADES_DICT = Attribute("Dict of examination grades") |
---|
| 219 | INST_TYPES_DICT = Attribute("Dict if institution types") |
---|
| 220 | STUDY_MODES_DICT = Attribute("Dict of study modes") |
---|
| 221 | APP_CATS_DICT = Attribute("Dict of application categories") |
---|
| 222 | SEMESTER_DICT = Attribute("Dict of semesters or trimesters") |
---|
[8394] | 223 | INT_PHONE_PREFIXES = Attribute( |
---|
| 224 | "Dict of international phone number prefixes") |
---|
[7568] | 225 | |
---|
[7404] | 226 | def sendContactForm( |
---|
| 227 | from_name,from_addr,rcpt_name,rcpt_addr, |
---|
| 228 | from_username,usertype,portal,body,subject): |
---|
[7358] | 229 | """Send an email with data provided by forms. |
---|
| 230 | """ |
---|
| 231 | |
---|
[7475] | 232 | def fullname(firstname,lastname,middlename): |
---|
| 233 | """Full name constructor. |
---|
| 234 | """ |
---|
| 235 | |
---|
[8853] | 236 | def sendCredentials(user, password, url_info, msg): |
---|
[7475] | 237 | """Send credentials as email. |
---|
| 238 | |
---|
| 239 | Input is the applicant for which credentials are sent and the |
---|
| 240 | password. |
---|
| 241 | |
---|
| 242 | Returns True or False to indicate successful operation. |
---|
| 243 | """ |
---|
| 244 | |
---|
| 245 | def genPassword(length, chars): |
---|
| 246 | """Generate a random password. |
---|
| 247 | """ |
---|
| 248 | |
---|
[7819] | 249 | class IKofaObject(Interface): |
---|
| 250 | """A Kofa object. |
---|
[5663] | 251 | |
---|
| 252 | This is merely a marker interface. |
---|
[4789] | 253 | """ |
---|
| 254 | |
---|
[7819] | 255 | class IUniversity(IKofaObject): |
---|
[3521] | 256 | """Representation of a university. |
---|
| 257 | """ |
---|
[5955] | 258 | |
---|
[6065] | 259 | |
---|
[7819] | 260 | class IKofaContainer(IKofaObject): |
---|
| 261 | """A container for Kofa objects. |
---|
[4789] | 262 | """ |
---|
| 263 | |
---|
[7819] | 264 | class IKofaContained(IKofaObject): |
---|
| 265 | """An item contained in an IKofaContainer. |
---|
[4789] | 266 | """ |
---|
[6136] | 267 | |
---|
[7726] | 268 | class ICSVExporter(Interface): |
---|
| 269 | """A CSV file exporter for objects. |
---|
| 270 | """ |
---|
| 271 | fields = Attribute("""List of fieldnames in resulting CSV""") |
---|
[7907] | 272 | |
---|
| 273 | title = schema.TextLine( |
---|
| 274 | title = u'Title', |
---|
| 275 | description = u'Description to be displayed in selections.', |
---|
| 276 | ) |
---|
[7726] | 277 | def mangle_value(value, name, obj): |
---|
| 278 | """Mangle `value` extracted from `obj` or suobjects thereof. |
---|
| 279 | |
---|
[8394] | 280 | This is called by export before actually writing to the result |
---|
| 281 | file. |
---|
[7726] | 282 | """ |
---|
| 283 | |
---|
[7730] | 284 | def export(iterable, filepath=None): |
---|
| 285 | """Export iterables as rows in a CSV file. |
---|
[7726] | 286 | |
---|
[8394] | 287 | If `filepath` is not given, a string with the data should be |
---|
| 288 | returned. |
---|
[7730] | 289 | |
---|
| 290 | What kind of iterables are acceptable depends on the specific |
---|
| 291 | exporter implementation. |
---|
[7726] | 292 | """ |
---|
| 293 | |
---|
| 294 | def export_all(site, filapath=None): |
---|
| 295 | """Export all items in `site` as CSV file. |
---|
| 296 | |
---|
[8394] | 297 | if `filepath` is not given, a string with the data should be |
---|
| 298 | returned. |
---|
[7726] | 299 | """ |
---|
| 300 | |
---|
[7819] | 301 | class IKofaExporter(Interface): |
---|
[4789] | 302 | """An exporter for objects. |
---|
| 303 | """ |
---|
| 304 | def export(obj, filepath=None): |
---|
| 305 | """Export by pickling. |
---|
| 306 | |
---|
| 307 | Returns a file-like object containing a representation of `obj`. |
---|
| 308 | |
---|
| 309 | This is done using `pickle`. If `filepath` is ``None``, a |
---|
| 310 | `cStringIO` object is returned, that contains the saved data. |
---|
| 311 | """ |
---|
| 312 | |
---|
[7819] | 313 | class IKofaXMLExporter(Interface): |
---|
[4789] | 314 | """An XML exporter for objects. |
---|
| 315 | """ |
---|
| 316 | def export(obj, filepath=None): |
---|
| 317 | """Export as XML. |
---|
| 318 | |
---|
| 319 | Returns an XML representation of `obj`. |
---|
| 320 | |
---|
| 321 | If `filepath` is ``None``, a StringIO` object is returned, |
---|
| 322 | that contains the transformed data. |
---|
| 323 | """ |
---|
| 324 | |
---|
[7819] | 325 | class IKofaXMLImporter(Interface): |
---|
[4789] | 326 | """An XML import for objects. |
---|
| 327 | """ |
---|
| 328 | def doImport(filepath): |
---|
| 329 | """Create Python object from XML. |
---|
| 330 | |
---|
| 331 | Returns a Python object. |
---|
| 332 | """ |
---|
| 333 | |
---|
[4858] | 334 | class IBatchProcessor(Interface): |
---|
| 335 | """A batch processor that handles mass-operations. |
---|
| 336 | """ |
---|
| 337 | name = schema.TextLine( |
---|
[7933] | 338 | title = _(u'Processor name') |
---|
[4858] | 339 | ) |
---|
| 340 | |
---|
[5476] | 341 | def doImport(path, headerfields, mode='create', user='Unknown', |
---|
[8218] | 342 | logger=None, ignore_empty=True): |
---|
[4858] | 343 | """Read data from ``path`` and update connected object. |
---|
[5476] | 344 | |
---|
| 345 | `headerfields` is a list of headerfields as read from the file |
---|
| 346 | to import. |
---|
| 347 | |
---|
| 348 | `mode` gives the import mode to use (``'create'``, |
---|
| 349 | ``'update'``, or ``'remove'``. |
---|
| 350 | |
---|
| 351 | `user` is a string describing the user performing the |
---|
| 352 | import. Normally fetched from current principal. |
---|
| 353 | |
---|
| 354 | `logger` is the logger to use during import. |
---|
[8218] | 355 | |
---|
| 356 | `ignore_emtpy` in update mode ignores empty fields if true. |
---|
[4858] | 357 | """ |
---|
| 358 | |
---|
[7819] | 359 | class IContactForm(IKofaObject): |
---|
[7225] | 360 | """A contact form. |
---|
| 361 | """ |
---|
| 362 | |
---|
| 363 | email_from = schema.ASCIILine( |
---|
[7828] | 364 | title = _(u'Email Address:'), |
---|
[7225] | 365 | default = None, |
---|
| 366 | required = True, |
---|
| 367 | constraint=validate_email, |
---|
| 368 | ) |
---|
| 369 | |
---|
| 370 | email_to = schema.ASCIILine( |
---|
[7828] | 371 | title = _(u'Email to:'), |
---|
[7225] | 372 | default = None, |
---|
| 373 | required = True, |
---|
| 374 | constraint=validate_email, |
---|
| 375 | ) |
---|
| 376 | |
---|
| 377 | subject = schema.TextLine( |
---|
[7828] | 378 | title = _(u'Subject:'), |
---|
[7225] | 379 | required = True,) |
---|
| 380 | |
---|
| 381 | fullname = schema.TextLine( |
---|
[7828] | 382 | title = _(u'Full Name:'), |
---|
[7225] | 383 | required = True,) |
---|
| 384 | |
---|
| 385 | body = schema.Text( |
---|
[7828] | 386 | title = _(u'Text:'), |
---|
[7225] | 387 | required = True,) |
---|
| 388 | |
---|
[7819] | 389 | class IKofaPrincipalInfo(IPrincipalInfo): |
---|
| 390 | """Infos about principals that are users of Kofa Kofa. |
---|
[7233] | 391 | """ |
---|
| 392 | email = Attribute("The email address of a user") |
---|
| 393 | phone = Attribute("The phone number of a user") |
---|
[8757] | 394 | public_name = Attribute("The public name of a user") |
---|
[7225] | 395 | |
---|
[7233] | 396 | |
---|
[7819] | 397 | class IKofaPrincipal(IPrincipal): |
---|
| 398 | """A principle for Kofa Kofa. |
---|
[7233] | 399 | |
---|
| 400 | This interface extends zope.security.interfaces.IPrincipal and |
---|
| 401 | requires also an `id` and other attributes defined there. |
---|
| 402 | """ |
---|
| 403 | |
---|
| 404 | email = schema.TextLine( |
---|
[7828] | 405 | title = _(u'Email Address'), |
---|
[7233] | 406 | description = u'', |
---|
| 407 | required=False,) |
---|
| 408 | |
---|
[8176] | 409 | phone = PhoneNumber( |
---|
[7828] | 410 | title = _(u'Phone'), |
---|
[7233] | 411 | description = u'', |
---|
| 412 | required=False,) |
---|
| 413 | |
---|
[8757] | 414 | public_name = schema.TextLine( |
---|
| 415 | title = _(u'Public Name'), |
---|
| 416 | required = False,) |
---|
| 417 | |
---|
[7819] | 418 | class IUserAccount(IKofaObject): |
---|
[4789] | 419 | """A user account. |
---|
| 420 | """ |
---|
| 421 | name = schema.TextLine( |
---|
[7828] | 422 | title = _(u'User Id'), |
---|
[6512] | 423 | description = u'Login name of user', |
---|
[4789] | 424 | required = True,) |
---|
[7221] | 425 | |
---|
[4789] | 426 | title = schema.TextLine( |
---|
[7828] | 427 | title = _(u'Full Name'), |
---|
[8759] | 428 | required = True,) |
---|
[7221] | 429 | |
---|
[8756] | 430 | public_name = schema.TextLine( |
---|
| 431 | title = _(u'Public Name'), |
---|
[8759] | 432 | description = u"Substitute for officer's real name " |
---|
| 433 | "in student object histories.", |
---|
[8756] | 434 | required = False,) |
---|
| 435 | |
---|
[7197] | 436 | description = schema.Text( |
---|
[7828] | 437 | title = _(u'Description/Notice'), |
---|
[4789] | 438 | required = False,) |
---|
[7221] | 439 | |
---|
| 440 | email = schema.ASCIILine( |
---|
[7828] | 441 | title = _(u'Email Address'), |
---|
[7221] | 442 | default = None, |
---|
[7222] | 443 | required = True, |
---|
[7221] | 444 | constraint=validate_email, |
---|
| 445 | ) |
---|
| 446 | |
---|
[8176] | 447 | phone = PhoneNumber( |
---|
[7828] | 448 | title = _(u'Phone'), |
---|
[7233] | 449 | default = None, |
---|
[8062] | 450 | required = False, |
---|
[7233] | 451 | ) |
---|
| 452 | |
---|
[4789] | 453 | roles = schema.List( |
---|
[8486] | 454 | title = _(u'Portal Roles'), |
---|
[8079] | 455 | value_type = schema.Choice(source=RoleSource()), |
---|
| 456 | required = False, |
---|
| 457 | ) |
---|
[6136] | 458 | |
---|
[7147] | 459 | class IPasswordValidator(Interface): |
---|
| 460 | """A password validator utility. |
---|
| 461 | """ |
---|
[6136] | 462 | |
---|
[7147] | 463 | def validate_password(password, password_repeat): |
---|
| 464 | """Validates a password by comparing it with |
---|
| 465 | control password and checking some other requirements. |
---|
| 466 | """ |
---|
| 467 | |
---|
| 468 | |
---|
[7819] | 469 | class IUsersContainer(IKofaObject): |
---|
[4789] | 470 | """A container for users (principals). |
---|
| 471 | |
---|
| 472 | These users are used for authentication purposes. |
---|
| 473 | """ |
---|
| 474 | |
---|
| 475 | def addUser(name, password, title=None, description=None): |
---|
| 476 | """Add a user. |
---|
| 477 | """ |
---|
| 478 | |
---|
| 479 | def delUser(name): |
---|
| 480 | """Delete a user if it exists. |
---|
| 481 | """ |
---|
| 482 | |
---|
[6141] | 483 | class ILocalRolesAssignable(Interface): |
---|
| 484 | """The local roles assignable to an object. |
---|
| 485 | """ |
---|
| 486 | def __call__(): |
---|
| 487 | """Returns a list of dicts. |
---|
| 488 | |
---|
| 489 | Each dict contains a ``name`` referring to the role assignable |
---|
| 490 | for the specified object and a `title` to describe the range |
---|
| 491 | of users to which this role can be assigned. |
---|
| 492 | """ |
---|
| 493 | |
---|
[7819] | 494 | class IConfigurationContainer(IKofaObject): |
---|
[6907] | 495 | """A container for session configuration objects. |
---|
| 496 | """ |
---|
| 497 | |
---|
| 498 | name = schema.TextLine( |
---|
[7828] | 499 | title = _(u'Name of University'), |
---|
| 500 | default = _(u'Sample University'), |
---|
[6907] | 501 | required = True, |
---|
| 502 | ) |
---|
| 503 | |
---|
[7459] | 504 | acronym = schema.TextLine( |
---|
[7828] | 505 | title = _(u'Abbreviated Title of University'), |
---|
[7819] | 506 | default = u'WAeUP.Kofa', |
---|
[7459] | 507 | required = True, |
---|
| 508 | ) |
---|
| 509 | |
---|
[6907] | 510 | skin = schema.Choice( |
---|
[7828] | 511 | title = _(u'Skin'), |
---|
[6907] | 512 | default = u'gray waeup theme', |
---|
[7811] | 513 | vocabulary = 'waeup.kofa.browser.theming.ThemesVocabulary', |
---|
[6907] | 514 | required = True, |
---|
| 515 | ) |
---|
| 516 | |
---|
| 517 | frontpage = schema.Text( |
---|
[8361] | 518 | title = _(u'Content in HTML format'), |
---|
[6907] | 519 | required = False, |
---|
[8361] | 520 | default = default_html_frontpage, |
---|
[6907] | 521 | ) |
---|
| 522 | |
---|
[7702] | 523 | frontpage_dict = schema.Dict( |
---|
| 524 | title = u'Content as language dictionary with values in html format', |
---|
[7485] | 525 | required = False, |
---|
[7702] | 526 | default = {}, |
---|
[7485] | 527 | ) |
---|
| 528 | |
---|
[7223] | 529 | name_admin = schema.TextLine( |
---|
[7828] | 530 | title = _(u'Name of Administrator'), |
---|
[7223] | 531 | default = u'Administrator', |
---|
[8230] | 532 | required = True, |
---|
[7223] | 533 | ) |
---|
| 534 | |
---|
[7221] | 535 | email_admin = schema.ASCIILine( |
---|
[7828] | 536 | title = _(u'Email Address of Administrator'), |
---|
[7221] | 537 | default = 'contact@waeup.org', |
---|
[8230] | 538 | required = True, |
---|
[7221] | 539 | constraint=validate_email, |
---|
| 540 | ) |
---|
| 541 | |
---|
| 542 | email_subject = schema.TextLine( |
---|
[7828] | 543 | title = _(u'Subject of Email to Administrator'), |
---|
| 544 | default = _(u'Kofa Contact'), |
---|
[8230] | 545 | required = True, |
---|
[7221] | 546 | ) |
---|
| 547 | |
---|
[7470] | 548 | smtp_mailer = schema.Choice( |
---|
[7828] | 549 | title = _(u'SMTP mailer to use when sending mail'), |
---|
[7470] | 550 | vocabulary = 'Mail Delivery Names', |
---|
| 551 | default = 'No email service', |
---|
| 552 | required = True, |
---|
| 553 | ) |
---|
| 554 | |
---|
[7313] | 555 | captcha = schema.Choice( |
---|
[7828] | 556 | title = _(u'Captcha used for public registration pages'), |
---|
[7313] | 557 | source = CaptchaSource(), |
---|
| 558 | default = u'No captcha', |
---|
| 559 | required = True, |
---|
| 560 | ) |
---|
[7221] | 561 | |
---|
[7664] | 562 | carry_over = schema.Bool( |
---|
[7828] | 563 | title = _(u'Carry-over Course Registration'), |
---|
[7664] | 564 | default = False, |
---|
| 565 | ) |
---|
| 566 | |
---|
[7819] | 567 | class ISessionConfiguration(IKofaObject): |
---|
[6915] | 568 | """A session configuration object. |
---|
[6907] | 569 | """ |
---|
| 570 | |
---|
[6915] | 571 | academic_session = schema.Choice( |
---|
[7828] | 572 | title = _(u'Academic Session'), |
---|
[6915] | 573 | source = academic_sessions_vocab, |
---|
| 574 | default = None, |
---|
| 575 | required = True, |
---|
| 576 | readonly = True, |
---|
| 577 | ) |
---|
| 578 | |
---|
[8260] | 579 | application_fee = schema.Float( |
---|
| 580 | title = _(u'Application Fee'), |
---|
[7927] | 581 | default = 0.0, |
---|
[7881] | 582 | required = False, |
---|
[6916] | 583 | ) |
---|
| 584 | |
---|
[8260] | 585 | clearance_fee = schema.Float( |
---|
| 586 | title = _(u'Clearance Fee'), |
---|
[7927] | 587 | default = 0.0, |
---|
[7881] | 588 | required = False, |
---|
[6993] | 589 | ) |
---|
| 590 | |
---|
[8260] | 591 | booking_fee = schema.Float( |
---|
| 592 | title = _(u'Bed Booking Fee'), |
---|
[7927] | 593 | default = 0.0, |
---|
[7881] | 594 | required = False, |
---|
[7250] | 595 | ) |
---|
| 596 | |
---|
[6918] | 597 | def getSessionString(): |
---|
| 598 | """Returns the session string from the vocabulary. |
---|
| 599 | """ |
---|
| 600 | |
---|
| 601 | |
---|
[6916] | 602 | class ISessionConfigurationAdd(ISessionConfiguration): |
---|
| 603 | """A session configuration object in add mode. |
---|
| 604 | """ |
---|
| 605 | |
---|
| 606 | academic_session = schema.Choice( |
---|
[7828] | 607 | title = _(u'Academic Session'), |
---|
[6916] | 608 | source = academic_sessions_vocab, |
---|
| 609 | default = None, |
---|
| 610 | required = True, |
---|
| 611 | readonly = False, |
---|
| 612 | ) |
---|
| 613 | |
---|
| 614 | ISessionConfigurationAdd['academic_session'].order = ISessionConfiguration[ |
---|
| 615 | 'academic_session'].order |
---|
| 616 | |
---|
[7819] | 617 | class IDataCenter(IKofaObject): |
---|
[4789] | 618 | """A data center. |
---|
| 619 | |
---|
[8394] | 620 | A data center manages files (uploads, downloads, etc.). |
---|
| 621 | |
---|
| 622 | Beside providing the bare paths needed to keep files, it also |
---|
| 623 | provides some helpers to put results of batch processing into |
---|
| 624 | well-defined final locations (with well-defined filenames). |
---|
| 625 | |
---|
| 626 | The main use-case is managing of site-related files, i.e. files |
---|
| 627 | for import, export etc. |
---|
| 628 | |
---|
| 629 | DataCenters are _not_ meant as storages for object-specific files |
---|
| 630 | like passport photographs and similar. |
---|
| 631 | |
---|
| 632 | It is up to the datacenter implementation how to organize data |
---|
| 633 | (paths) inside its storage path. |
---|
[4789] | 634 | """ |
---|
[8394] | 635 | storage = schema.Bytes( |
---|
| 636 | title = u'Path to directory where everything is kept.' |
---|
| 637 | ) |
---|
[4789] | 638 | |
---|
[8394] | 639 | deleted_path = schema.Bytes( |
---|
| 640 | title = u'Path were data about deleted objects should be stored.' |
---|
| 641 | ) |
---|
| 642 | |
---|
[9023] | 643 | def getPendingFiles(sort='name'): |
---|
[8394] | 644 | """Get a list of files stored in `storage` sorted by basename. |
---|
| 645 | """ |
---|
[9023] | 646 | |
---|
[9074] | 647 | def getFinishedFiles(): |
---|
| 648 | """Get a list of files stored in `finished` subfolder of `storage`. |
---|
[9023] | 649 | """ |
---|
| 650 | |
---|
[8394] | 651 | def setStoragePath(path, move=False, overwrite=False): |
---|
| 652 | """Set the path where to store files. |
---|
| 653 | |
---|
| 654 | If `move` is True, move over files from the current location |
---|
| 655 | to the new one. |
---|
| 656 | |
---|
| 657 | If `overwrite` is also True, overwrite any already existing |
---|
| 658 | files of same name in target location. |
---|
| 659 | |
---|
| 660 | Triggers a DataCenterStorageMovedEvent. |
---|
| 661 | """ |
---|
| 662 | |
---|
| 663 | def distProcessedFiles(successful, source_path, finished_file, |
---|
| 664 | pending_file, mode='create', move_orig=True): |
---|
| 665 | """Distribute processed files over final locations. |
---|
| 666 | """ |
---|
| 667 | |
---|
| 668 | |
---|
[4789] | 669 | class IDataCenterFile(Interface): |
---|
| 670 | """A data center file. |
---|
| 671 | """ |
---|
[4858] | 672 | |
---|
| 673 | name = schema.TextLine( |
---|
| 674 | title = u'Filename') |
---|
| 675 | |
---|
| 676 | size = schema.TextLine( |
---|
| 677 | title = u'Human readable file size') |
---|
| 678 | |
---|
| 679 | uploaddate = schema.TextLine( |
---|
| 680 | title = u'Human readable upload datetime') |
---|
| 681 | |
---|
| 682 | lines = schema.Int( |
---|
| 683 | title = u'Number of lines in file') |
---|
[6136] | 684 | |
---|
[4789] | 685 | def getDate(): |
---|
| 686 | """Get creation timestamp from file in human readable form. |
---|
| 687 | """ |
---|
| 688 | |
---|
| 689 | def getSize(): |
---|
| 690 | """Get human readable size of file. |
---|
| 691 | """ |
---|
[4858] | 692 | |
---|
| 693 | def getLinesNumber(): |
---|
| 694 | """Get number of lines of file. |
---|
| 695 | """ |
---|
[4882] | 696 | |
---|
| 697 | class IDataCenterStorageMovedEvent(IObjectEvent): |
---|
| 698 | """Emitted, when the storage of a datacenter changes. |
---|
| 699 | """ |
---|
[5007] | 700 | |
---|
[6136] | 701 | class IObjectUpgradeEvent(IObjectEvent): |
---|
| 702 | """Can be fired, when an object shall be upgraded. |
---|
| 703 | """ |
---|
| 704 | |
---|
[6180] | 705 | class ILocalRoleSetEvent(IObjectEvent): |
---|
| 706 | """A local role was granted/revoked for a principal on an object. |
---|
| 707 | """ |
---|
| 708 | role_id = Attribute( |
---|
| 709 | "The role id that was set.") |
---|
| 710 | principal_id = Attribute( |
---|
| 711 | "The principal id for which the role was granted/revoked.") |
---|
| 712 | granted = Attribute( |
---|
| 713 | "Boolean. If false, then the role was revoked.") |
---|
| 714 | |
---|
[5007] | 715 | class IQueryResultItem(Interface): |
---|
| 716 | """An item in a search result. |
---|
| 717 | """ |
---|
| 718 | url = schema.TextLine( |
---|
| 719 | title = u'URL that links to the found item') |
---|
| 720 | title = schema.TextLine( |
---|
| 721 | title = u'Title displayed in search results.') |
---|
| 722 | description = schema.Text( |
---|
| 723 | title = u'Longer description of the item found.') |
---|
[6136] | 724 | |
---|
[7819] | 725 | class IKofaPluggable(Interface): |
---|
| 726 | """A component that might be plugged into a Kofa Kofa app. |
---|
[5658] | 727 | |
---|
| 728 | Components implementing this interface are referred to as |
---|
| 729 | 'plugins'. They are normally called when a new |
---|
[7811] | 730 | :class:`waeup.kofa.app.University` instance is created. |
---|
[5658] | 731 | |
---|
| 732 | Plugins can setup and update parts of the central site without the |
---|
[7811] | 733 | site object (normally a :class:`waeup.kofa.app.University` object) |
---|
[5658] | 734 | needing to know about that parts. The site simply collects all |
---|
| 735 | available plugins, calls them and the plugins care for their |
---|
[5676] | 736 | respective subarea like the applicants area or the datacenter |
---|
[5658] | 737 | area. |
---|
| 738 | |
---|
| 739 | Currently we have no mechanism to define an order of plugins. A |
---|
| 740 | plugin should therefore make no assumptions about the state of the |
---|
| 741 | site or other plugins being run before and instead do appropriate |
---|
| 742 | checks if necessary. |
---|
| 743 | |
---|
| 744 | Updates can be triggered for instance by the respective form in |
---|
| 745 | the site configuration. You normally do updates when the |
---|
| 746 | underlying software changed. |
---|
[5013] | 747 | """ |
---|
[5069] | 748 | def setup(site, name, logger): |
---|
| 749 | """Create an instance of the plugin. |
---|
[5013] | 750 | |
---|
[5658] | 751 | The method is meant to be called by the central app (site) |
---|
| 752 | when it is created. |
---|
| 753 | |
---|
| 754 | `site`: |
---|
| 755 | The site that requests a setup. |
---|
| 756 | |
---|
| 757 | `name`: |
---|
| 758 | The name under which the plugin was registered (utility name). |
---|
| 759 | |
---|
| 760 | `logger`: |
---|
| 761 | A standard Python logger for the plugins use. |
---|
[5069] | 762 | """ |
---|
| 763 | |
---|
| 764 | def update(site, name, logger): |
---|
| 765 | """Method to update an already existing plugin. |
---|
| 766 | |
---|
| 767 | This might be called by a site when something serious |
---|
[5658] | 768 | changes. It is a poor-man replacement for Zope generations |
---|
| 769 | (but probably more comprehensive and better understandable). |
---|
| 770 | |
---|
| 771 | `site`: |
---|
| 772 | The site that requests an update. |
---|
| 773 | |
---|
| 774 | `name`: |
---|
| 775 | The name under which the plugin was registered (utility name). |
---|
| 776 | |
---|
| 777 | `logger`: |
---|
| 778 | A standard Python logger for the plugins use. |
---|
[5069] | 779 | """ |
---|
[5898] | 780 | |
---|
[5899] | 781 | class IAuthPluginUtility(Interface): |
---|
[5898] | 782 | """A component that cares for authentication setup at site creation. |
---|
| 783 | |
---|
| 784 | Utilities providing this interface are looked up when a Pluggable |
---|
| 785 | Authentication Utility (PAU) for any |
---|
[7811] | 786 | :class:`waeup.kofa.app.University` instance is created and put |
---|
[5898] | 787 | into ZODB. |
---|
| 788 | |
---|
| 789 | The setup-code then calls the `register` method of the utility and |
---|
| 790 | expects a modified (or unmodified) version of the PAU back. |
---|
| 791 | |
---|
| 792 | This allows to define any authentication setup modifications by |
---|
| 793 | submodules or third-party modules/packages. |
---|
| 794 | """ |
---|
| 795 | |
---|
| 796 | def register(pau): |
---|
| 797 | """Register any plugins wanted to be in the PAU. |
---|
| 798 | """ |
---|
| 799 | |
---|
| 800 | def unregister(pau): |
---|
| 801 | """Unregister any plugins not wanted to be in the PAU. |
---|
| 802 | """ |
---|
[6273] | 803 | |
---|
| 804 | class IObjectConverter(Interface): |
---|
| 805 | """Object converters are available as simple adapters, adapting |
---|
| 806 | interfaces (not regular instances). |
---|
| 807 | |
---|
| 808 | """ |
---|
| 809 | |
---|
[6277] | 810 | def fromStringDict(self, data_dict, context, form_fields=None): |
---|
| 811 | """Convert values in `data_dict`. |
---|
[6273] | 812 | |
---|
[6277] | 813 | Converts data in `data_dict` into real values based on |
---|
| 814 | `context` and `form_fields`. |
---|
[6273] | 815 | |
---|
[6277] | 816 | `data_dict` is a mapping (dict) from field names to values |
---|
| 817 | represented as strings. |
---|
[6273] | 818 | |
---|
[6277] | 819 | The fields (keys) to convert can be given in optional |
---|
| 820 | `form_fields`. If given, form_fields should be an instance of |
---|
| 821 | :class:`zope.formlib.form.Fields`. Suitable instances are for |
---|
| 822 | example created by :class:`grok.AutoFields`. |
---|
[6273] | 823 | |
---|
[6277] | 824 | If no `form_fields` are given, a default is computed from the |
---|
| 825 | associated interface. |
---|
[6273] | 826 | |
---|
[6277] | 827 | The `context` can be an existing object (implementing the |
---|
| 828 | associated interface) or a factory name. If it is a string, we |
---|
| 829 | try to create an object using |
---|
| 830 | :func:`zope.component.createObject`. |
---|
| 831 | |
---|
| 832 | Returns a tuple ``(<FIELD_ERRORS>, <INVARIANT_ERRORS>, |
---|
| 833 | <DATA_DICT>)`` where |
---|
| 834 | |
---|
| 835 | ``<FIELD_ERRORS>`` |
---|
| 836 | is a list of tuples ``(<FIELD_NAME>, <ERROR>)`` for each |
---|
| 837 | error that happened when validating the input data in |
---|
| 838 | `data_dict` |
---|
| 839 | |
---|
| 840 | ``<INVARIANT_ERRORS>`` |
---|
| 841 | is a list of invariant errors concerning several fields |
---|
| 842 | |
---|
| 843 | ``<DATA_DICT>`` |
---|
| 844 | is a dict with the values from input dict converted. |
---|
| 845 | |
---|
| 846 | If errors happen, i.e. the error lists are not empty, always |
---|
| 847 | an empty ``<DATA_DICT>`` is returned. |
---|
| 848 | |
---|
| 849 | If ``<DATA_DICT>` is non-empty, there were no errors. |
---|
[6273] | 850 | """ |
---|
[6293] | 851 | |
---|
[7932] | 852 | class IFieldConverter(Interface): |
---|
[8214] | 853 | def request_data(name, value, schema_field, prefix='', mode='create'): |
---|
[7932] | 854 | """Create a dict with key-value mapping as created by a request. |
---|
| 855 | |
---|
| 856 | `name` and `value` are expected to be parsed from CSV or a |
---|
| 857 | similar input and represent an attribute to be set to a |
---|
| 858 | representation of value. |
---|
| 859 | |
---|
[8214] | 860 | `mode` gives the mode of import. |
---|
| 861 | |
---|
[7932] | 862 | :meth:`update_request_data` is then requested to turn this |
---|
| 863 | name and value into vars as they would be sent by a regular |
---|
| 864 | form submit. This means we do not create the real values to be |
---|
| 865 | set but we only define the values that would be sent in a |
---|
| 866 | browser request to request the creation of those values. |
---|
| 867 | |
---|
| 868 | The returned dict should contain names and values of a faked |
---|
| 869 | browser request for the given `schema_field`. |
---|
| 870 | |
---|
| 871 | Field converters are normally registered as adapters to some |
---|
| 872 | specific zope.schema field. |
---|
| 873 | """ |
---|
| 874 | |
---|
[6338] | 875 | class IObjectHistory(Interface): |
---|
| 876 | |
---|
| 877 | messages = schema.List( |
---|
| 878 | title = u'List of messages stored', |
---|
| 879 | required = True, |
---|
| 880 | ) |
---|
| 881 | |
---|
| 882 | def addMessage(message): |
---|
| 883 | """Add a message. |
---|
| 884 | """ |
---|
[6353] | 885 | |
---|
[7819] | 886 | class IKofaWorkflowInfo(IWorkflowInfo): |
---|
[6353] | 887 | """A :class:`hurry.workflow.workflow.WorkflowInfo` with additional |
---|
| 888 | methods for convenience. |
---|
| 889 | """ |
---|
| 890 | def getManualTransitions(): |
---|
| 891 | """Get allowed manual transitions. |
---|
| 892 | |
---|
| 893 | Get a sorted list of tuples containing the `transition_id` and |
---|
| 894 | `title` of each allowed transition. |
---|
| 895 | """ |
---|
[6481] | 896 | |
---|
| 897 | class ISiteLoggers(Interface): |
---|
| 898 | |
---|
[7819] | 899 | loggers = Attribute("A list or generator of registered KofaLoggers") |
---|
[6481] | 900 | |
---|
| 901 | def register(name, filename=None, site=None, **options): |
---|
| 902 | """Register a logger `name` which logs to `filename`. |
---|
| 903 | |
---|
| 904 | If `filename` is not given, logfile will be `name` with |
---|
| 905 | ``.log`` as filename extension. |
---|
| 906 | """ |
---|
| 907 | |
---|
| 908 | def unregister(name): |
---|
| 909 | """Unregister a once registered logger. |
---|
| 910 | """ |
---|
| 911 | |
---|
| 912 | class ILogger(Interface): |
---|
| 913 | """A logger cares for setup, update and restarting of a Python logger. |
---|
| 914 | """ |
---|
| 915 | |
---|
| 916 | logger = Attribute("""A :class:`logging.Logger` instance""") |
---|
| 917 | |
---|
| 918 | |
---|
| 919 | def __init__(name, filename=None, site=None, **options): |
---|
[7819] | 920 | """Create a Kofa logger instance. |
---|
[6481] | 921 | """ |
---|
| 922 | |
---|
| 923 | def setup(): |
---|
| 924 | """Create a Python :class:`logging.Logger` instance. |
---|
| 925 | |
---|
| 926 | The created logger is based on the params given by constructor. |
---|
| 927 | """ |
---|
| 928 | |
---|
| 929 | def update(**options): |
---|
| 930 | """Update the logger. |
---|
| 931 | |
---|
| 932 | Updates the logger respecting modified `options` and changed |
---|
| 933 | paths. |
---|
| 934 | """ |
---|
[6754] | 935 | |
---|
| 936 | class ILoggerCollector(Interface): |
---|
| 937 | |
---|
| 938 | def getLoggers(site): |
---|
| 939 | """Return all loggers registered for `site`. |
---|
| 940 | """ |
---|
| 941 | |
---|
| 942 | def registerLogger(site, logging_component): |
---|
| 943 | """Register a logging component residing in `site`. |
---|
| 944 | """ |
---|
| 945 | |
---|
| 946 | def unregisterLogger(site, logging_component): |
---|
| 947 | """Unregister a logger. |
---|
| 948 | """ |
---|
[7063] | 949 | |
---|
| 950 | # |
---|
| 951 | # External File Storage and relatives |
---|
| 952 | # |
---|
| 953 | class IFileStoreNameChooser(INameChooser): |
---|
| 954 | """See zope.container.interfaces.INameChooser for base methods. |
---|
| 955 | """ |
---|
[7066] | 956 | def checkName(name, attr=None): |
---|
[7063] | 957 | """Check whether an object name is valid. |
---|
| 958 | |
---|
| 959 | Raises a user error if the name is not valid. |
---|
| 960 | """ |
---|
| 961 | |
---|
[7066] | 962 | def chooseName(name, attr=None): |
---|
| 963 | """Choose a unique valid file id for the object. |
---|
[7063] | 964 | |
---|
[7066] | 965 | The given name may be taken into account when choosing the |
---|
| 966 | name (file id). |
---|
[7063] | 967 | |
---|
[7066] | 968 | chooseName is expected to always choose a valid file id (that |
---|
| 969 | would pass the checkName test) and never raise an error. |
---|
| 970 | |
---|
| 971 | If `attr` is not ``None`` it might been taken into account as |
---|
| 972 | well when generating the file id. Usual behaviour is to |
---|
| 973 | interpret `attr` as a hint for what type of file for a given |
---|
| 974 | context should be stored if there are several types |
---|
| 975 | possible. For instance for a certain student some file could |
---|
| 976 | be the connected passport photograph or some certificate scan |
---|
| 977 | or whatever. Each of them has to be stored in a different |
---|
| 978 | location so setting `attr` to a sensible value should give |
---|
| 979 | different file ids returned. |
---|
[7063] | 980 | """ |
---|
| 981 | |
---|
| 982 | class IExtFileStore(IFileRetrieval): |
---|
| 983 | """A file storage that stores files in filesystem (not as blobs). |
---|
| 984 | """ |
---|
| 985 | root = schema.TextLine( |
---|
| 986 | title = u'Root path of file store.', |
---|
| 987 | ) |
---|
| 988 | |
---|
| 989 | def getFile(file_id): |
---|
| 990 | """Get raw file data stored under file with `file_id`. |
---|
| 991 | |
---|
| 992 | Returns a file descriptor open for reading or ``None`` if the |
---|
| 993 | file cannot be found. |
---|
| 994 | """ |
---|
| 995 | |
---|
[7071] | 996 | def getFileByContext(context, attr=None): |
---|
[7063] | 997 | """Get raw file data stored for the given context. |
---|
| 998 | |
---|
| 999 | Returns a file descriptor open for reading or ``None`` if no |
---|
| 1000 | such file can be found. |
---|
| 1001 | |
---|
[7071] | 1002 | Both, `context` and `attr` might be used to find (`context`) |
---|
| 1003 | and feed (`attr`) an appropriate file name chooser. |
---|
| 1004 | |
---|
[7063] | 1005 | This is a convenience method. |
---|
| 1006 | """ |
---|
| 1007 | |
---|
[7090] | 1008 | def deleteFile(file_id): |
---|
| 1009 | """Delete file stored under `file_id`. |
---|
| 1010 | |
---|
| 1011 | Remove file from filestore so, that it is not available |
---|
| 1012 | anymore on next call to getFile for the same file_id. |
---|
| 1013 | |
---|
| 1014 | Should not complain if no such file exists. |
---|
| 1015 | """ |
---|
| 1016 | |
---|
| 1017 | def deleteFileByContext(context, attr=None): |
---|
| 1018 | """Delete file for given `context` and `attr`. |
---|
| 1019 | |
---|
| 1020 | Both, `context` and `attr` might be used to find (`context`) |
---|
| 1021 | and feed (`attr`) an appropriate file name chooser. |
---|
| 1022 | |
---|
| 1023 | This is a convenience method. |
---|
| 1024 | """ |
---|
| 1025 | |
---|
[7063] | 1026 | def createFile(filename, f): |
---|
| 1027 | """Create file given by f with filename `filename` |
---|
| 1028 | |
---|
| 1029 | Returns a hurry.file.File-based object. |
---|
| 1030 | """ |
---|
| 1031 | |
---|
| 1032 | class IFileStoreHandler(Interface): |
---|
| 1033 | """Filestore handlers handle specific files for file stores. |
---|
| 1034 | |
---|
| 1035 | If a file to store/get provides a specific filename, a file store |
---|
| 1036 | looks up special handlers for that type of file. |
---|
| 1037 | |
---|
| 1038 | """ |
---|
| 1039 | def pathFromFileID(store, root, filename): |
---|
| 1040 | """Turn file id into path to store. |
---|
| 1041 | |
---|
| 1042 | Returned path should be absolute. |
---|
| 1043 | """ |
---|
| 1044 | |
---|
| 1045 | def createFile(store, root, filename, file_id, file): |
---|
| 1046 | """Return some hurry.file based on `store` and `file_id`. |
---|
| 1047 | |
---|
| 1048 | Some kind of callback method called by file stores to create |
---|
| 1049 | file objects from file_id. |
---|
| 1050 | |
---|
| 1051 | Returns a tuple ``(raw_file, path, file_like_obj)`` where the |
---|
[7819] | 1052 | ``file_like_obj`` should be a HurryFile, a KofaImageFile or |
---|
[7063] | 1053 | similar. ``raw_file`` is the (maybe changed) input file and |
---|
| 1054 | ``path`` the relative internal path to store the file at. |
---|
| 1055 | |
---|
| 1056 | Please make sure the ``raw_file`` is opened for reading and |
---|
| 1057 | the file descriptor set at position 0 when returned. |
---|
| 1058 | |
---|
| 1059 | This method also gets the raw input file object that is about |
---|
| 1060 | to be stored and is expected to raise any exceptions if some |
---|
| 1061 | kind of validation or similar fails. |
---|
| 1062 | """ |
---|
[7389] | 1063 | |
---|
| 1064 | class IPDF(Interface): |
---|
| 1065 | """A PDF representation of some context. |
---|
| 1066 | """ |
---|
| 1067 | |
---|
[8257] | 1068 | def __call__(view=None, note=None): |
---|
[7389] | 1069 | """Create a bytestream representing a PDF from context. |
---|
| 1070 | |
---|
| 1071 | If `view` is passed in additional infos might be rendered into |
---|
| 1072 | the document. |
---|
[8257] | 1073 | |
---|
| 1074 | `note` is optional HTML rendered at bottom of the created |
---|
| 1075 | PDF. Please consider the limited reportlab support for HTML, |
---|
| 1076 | but using font-tags and friends you certainly can get the |
---|
| 1077 | desired look. |
---|
[7389] | 1078 | """ |
---|
[7473] | 1079 | |
---|
| 1080 | class IMailService(Interface): |
---|
| 1081 | """A mail service. |
---|
| 1082 | """ |
---|
| 1083 | |
---|
| 1084 | def __call__(): |
---|
| 1085 | """Get the default mail delivery. |
---|
| 1086 | """ |
---|
[7576] | 1087 | |
---|
| 1088 | from zope.configuration.fields import Path |
---|
| 1089 | class IDataCenterConfig(Interface): |
---|
| 1090 | path = Path( |
---|
| 1091 | title = u'Path', |
---|
[7828] | 1092 | description = u"Directory where the datacenter should store " |
---|
| 1093 | u"files by default (adjustable in web UI).", |
---|
[7576] | 1094 | required = True, |
---|
| 1095 | ) |
---|
[8346] | 1096 | |
---|
| 1097 | class IChangePassword(IKofaObject): |
---|
| 1098 | """Interface needed for change pasword page. |
---|
| 1099 | |
---|
| 1100 | """ |
---|
| 1101 | identifier = schema.TextLine( |
---|
| 1102 | title = _(u'Unique Identifier'), |
---|
[8394] | 1103 | description = _( |
---|
| 1104 | u'User Name, Student or Applicant Id, Matriculation or ' |
---|
| 1105 | u'Registration Number'), |
---|
[8346] | 1106 | required = True, |
---|
| 1107 | readonly = False, |
---|
| 1108 | ) |
---|
| 1109 | |
---|
| 1110 | email = schema.ASCIILine( |
---|
| 1111 | title = _(u'Email Address'), |
---|
| 1112 | required = True, |
---|
| 1113 | constraint=validate_email, |
---|
[8394] | 1114 | ) |
---|