[7193] | 1 | ## $Id: interfaces.py 7773 2012-03-07 10:04:38Z uli $ |
---|
[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 |
---|
[6353] | 24 | from hurry.workflow.interfaces import IWorkflow, 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 |
---|
[5955] | 32 | from zope.interface import Interface, Attribute, implements |
---|
[4789] | 33 | from zope.schema.vocabulary import SimpleVocabulary, SimpleTerm |
---|
[3521] | 34 | |
---|
[7670] | 35 | _ = MessageFactory = zope.i18nmessageid.MessageFactory('waeup.sirp') |
---|
[6990] | 36 | |
---|
[7673] | 37 | CREATED = 'created' |
---|
| 38 | ADMITTED = 'admitted' |
---|
| 39 | CLEARANCE = 'clearance started' |
---|
| 40 | REQUESTED = 'clearance requested' |
---|
| 41 | CLEARED = 'cleared' |
---|
| 42 | PAID = 'school fee paid' |
---|
| 43 | RETURNING = 'returning' |
---|
| 44 | REGISTERED = 'courses registered' |
---|
| 45 | VALIDATED = 'courses validated' |
---|
[7670] | 46 | |
---|
[7702] | 47 | default_frontpage = u'' + codecs.open(os.path.join( |
---|
| 48 | os.path.dirname(__file__), 'frontpage.rst'), |
---|
| 49 | encoding='utf-8', mode='rb').read() |
---|
[6361] | 50 | |
---|
[7321] | 51 | def SimpleSIRPVocabulary(*terms): |
---|
[6915] | 52 | """A well-buildt vocabulary provides terms with a value, token and |
---|
| 53 | title for each term |
---|
| 54 | """ |
---|
| 55 | return SimpleVocabulary([ |
---|
| 56 | SimpleTerm(value, value, title) for title, value in terms]) |
---|
| 57 | |
---|
| 58 | def year_range(): |
---|
| 59 | curr_year = datetime.now().year |
---|
[7459] | 60 | return range(curr_year - 4, curr_year + 5) |
---|
[6915] | 61 | |
---|
| 62 | def academic_sessions(): |
---|
| 63 | curr_year = datetime.now().year |
---|
| 64 | year_range = range(curr_year - 10, curr_year + 2) |
---|
| 65 | return [('%s/%s' % (year,year+1), year) for year in year_range] |
---|
| 66 | |
---|
[7321] | 67 | academic_sessions_vocab = SimpleSIRPVocabulary(*academic_sessions()) |
---|
[6915] | 68 | |
---|
[7321] | 69 | registration_states_vocab = SimpleSIRPVocabulary( |
---|
[7677] | 70 | (_('created'), CREATED), |
---|
| 71 | (_('admitted'), ADMITTED), |
---|
| 72 | (_('clearance started'), CLEARANCE), |
---|
| 73 | (_('clearance requested'), REQUESTED), |
---|
| 74 | (_('cleared'), CLEARED), |
---|
| 75 | (_('school fee paid'), PAID), |
---|
| 76 | (_('returning'), RETURNING), |
---|
| 77 | (_('courses registered'), REGISTERED), |
---|
| 78 | (_('courses validated'), VALIDATED), |
---|
[6990] | 79 | ) |
---|
| 80 | |
---|
[7772] | 81 | SUBJECTS = dict(math=_(u'Math'), |
---|
| 82 | bio=_(u'Biology'), |
---|
| 83 | eng=_(u'English'), |
---|
| 84 | ) |
---|
| 85 | class SubjectSource(BasicSourceFactory): |
---|
| 86 | def getValues(self): |
---|
| 87 | return sorted(SUBJECTS.keys()) |
---|
| 88 | def getTitle(self, value): |
---|
| 89 | return SUBJECTS.get(value, None) |
---|
| 90 | |
---|
| 91 | GRADES = {'A':_(u'Very Good'), |
---|
| 92 | 'B':_(u'Good'), |
---|
| 93 | 'C':_(u'Satisfactory'), |
---|
| 94 | 'D':_(u'Sufficient'), |
---|
| 95 | 'E':_(u'Fail'), |
---|
| 96 | } |
---|
| 97 | class GradeSource(BasicSourceFactory): |
---|
| 98 | def getValues(self): |
---|
| 99 | return sorted(GRADES.keys()) |
---|
| 100 | def getTitle(self, value): |
---|
| 101 | return GRADES.get(value, None) |
---|
| 102 | |
---|
[7221] | 103 | # Define a valiation method for email addresses |
---|
| 104 | class NotAnEmailAddress(schema.ValidationError): |
---|
| 105 | __doc__ = u"Invalid email address" |
---|
| 106 | |
---|
| 107 | check_email = re.compile( |
---|
[7608] | 108 | r"[a-zA-Z0-9._%-']+@([a-zA-Z0-9-]+.)*[a-zA-Z]{2,4}").match |
---|
[7221] | 109 | |
---|
| 110 | def validate_email(value): |
---|
| 111 | if not check_email(value): |
---|
| 112 | raise NotAnEmailAddress(value) |
---|
| 113 | return True |
---|
| 114 | |
---|
[4858] | 115 | class FatalCSVError(Exception): |
---|
| 116 | """Some row could not be processed. |
---|
| 117 | """ |
---|
| 118 | pass |
---|
| 119 | |
---|
[6226] | 120 | class DuplicationError(Exception): |
---|
| 121 | """An exception that can be raised when duplicates are found. |
---|
| 122 | |
---|
| 123 | When raising :exc:`DuplicationError` you can, beside the usual |
---|
| 124 | message, specify a list of objects which are duplicates. These |
---|
| 125 | values can be used by catching code to print something helpful or |
---|
| 126 | similar. |
---|
| 127 | """ |
---|
| 128 | def __init__(self, msg, entries=[]): |
---|
| 129 | self.msg = msg |
---|
| 130 | self.entries = entries |
---|
| 131 | |
---|
| 132 | def __str__(self): |
---|
| 133 | return '%r' % self.msg |
---|
| 134 | |
---|
[6143] | 135 | class RoleSource(BasicSourceFactory): |
---|
[7178] | 136 | """A source for site roles. |
---|
[6508] | 137 | """ |
---|
[6143] | 138 | def getValues(self): |
---|
[6157] | 139 | # late import: in interfaces we should not import local modules |
---|
[7186] | 140 | from waeup.sirp.permissions import get_waeup_role_names |
---|
| 141 | return get_waeup_role_names() |
---|
[6157] | 142 | |
---|
| 143 | def getTitle(self, value): |
---|
| 144 | # late import: in interfaces we should not import local modules |
---|
[7186] | 145 | from waeup.sirp.permissions import get_all_roles |
---|
| 146 | roles = dict(get_all_roles()) |
---|
[6157] | 147 | if value in roles.keys(): |
---|
| 148 | title = roles[value].title |
---|
[6569] | 149 | if '.' in title: |
---|
| 150 | title = title.split('.', 2)[1] |
---|
[6157] | 151 | return title |
---|
[6143] | 152 | |
---|
[7313] | 153 | class CaptchaSource(BasicSourceFactory): |
---|
| 154 | """A source for captchas. |
---|
| 155 | """ |
---|
| 156 | def getValues(self): |
---|
[7323] | 157 | captchas = ['No captcha', 'Testing captcha', 'ReCaptcha'] |
---|
[7313] | 158 | try: |
---|
| 159 | # we have to 'try' because IConfiguration can only handle |
---|
| 160 | # interfaces from w.s.interface. |
---|
| 161 | from waeup.sirp.browser.interfaces import ICaptchaManager |
---|
| 162 | except: |
---|
| 163 | return captchas |
---|
| 164 | return sorted(getUtility(ICaptchaManager).getAvailCaptchas().keys()) |
---|
| 165 | |
---|
| 166 | def getTitle(self, value): |
---|
| 167 | return value |
---|
| 168 | |
---|
[7773] | 169 | class IResultEntry(Interface): |
---|
| 170 | """A school grade entry. |
---|
| 171 | """ |
---|
| 172 | subject = schema.Choice( |
---|
| 173 | title = _(u'Subject'), |
---|
| 174 | source = SubjectSource(), |
---|
| 175 | ) |
---|
| 176 | grade = schema.Choice( |
---|
| 177 | title = _(u'Grade'), |
---|
| 178 | source = GradeSource(), |
---|
| 179 | ) |
---|
| 180 | |
---|
[7358] | 181 | class ISIRPUtils(Interface): |
---|
| 182 | """A collection of methods which are subject to customization. |
---|
| 183 | """ |
---|
[7568] | 184 | |
---|
| 185 | def storage(): |
---|
| 186 | """Return the initial storage path of the data center. |
---|
| 187 | """ |
---|
| 188 | |
---|
[7404] | 189 | def sendContactForm( |
---|
| 190 | from_name,from_addr,rcpt_name,rcpt_addr, |
---|
| 191 | from_username,usertype,portal,body,subject): |
---|
[7358] | 192 | """Send an email with data provided by forms. |
---|
| 193 | """ |
---|
| 194 | |
---|
[7475] | 195 | def fullname(firstname,lastname,middlename): |
---|
| 196 | """Full name constructor. |
---|
| 197 | """ |
---|
| 198 | |
---|
| 199 | def sendCredentials(user, password, login_url, msg): |
---|
| 200 | """Send credentials as email. |
---|
| 201 | |
---|
| 202 | Input is the applicant for which credentials are sent and the |
---|
| 203 | password. |
---|
| 204 | |
---|
| 205 | Returns True or False to indicate successful operation. |
---|
| 206 | """ |
---|
| 207 | |
---|
| 208 | def genPassword(length, chars): |
---|
| 209 | """Generate a random password. |
---|
| 210 | """ |
---|
| 211 | |
---|
[7619] | 212 | def getVerdictsDict(): |
---|
| 213 | """Provide a dict of verdicts. |
---|
| 214 | """ |
---|
| 215 | |
---|
[7321] | 216 | class ISIRPObject(Interface): |
---|
| 217 | """A SIRP object. |
---|
[5663] | 218 | |
---|
| 219 | This is merely a marker interface. |
---|
[4789] | 220 | """ |
---|
| 221 | |
---|
[7321] | 222 | class IUniversity(ISIRPObject): |
---|
[3521] | 223 | """Representation of a university. |
---|
| 224 | """ |
---|
[5955] | 225 | |
---|
[6065] | 226 | |
---|
[7321] | 227 | class ISIRPContainer(ISIRPObject): |
---|
| 228 | """A container for SIRP objects. |
---|
[4789] | 229 | """ |
---|
| 230 | |
---|
[7321] | 231 | class ISIRPContained(ISIRPObject): |
---|
| 232 | """An item contained in an ISIRPContainer. |
---|
[4789] | 233 | """ |
---|
[6136] | 234 | |
---|
[7726] | 235 | class ICSVExporter(Interface): |
---|
| 236 | """A CSV file exporter for objects. |
---|
| 237 | """ |
---|
| 238 | fields = Attribute("""List of fieldnames in resulting CSV""") |
---|
| 239 | |
---|
| 240 | def mangle_value(value, name, obj): |
---|
| 241 | """Mangle `value` extracted from `obj` or suobjects thereof. |
---|
| 242 | |
---|
| 243 | This is called by export before actually writing to the result file. |
---|
| 244 | """ |
---|
| 245 | |
---|
[7730] | 246 | def export(iterable, filepath=None): |
---|
| 247 | """Export iterables as rows in a CSV file. |
---|
[7726] | 248 | |
---|
| 249 | If `filepath` is not given, a string with the data should be returned. |
---|
[7730] | 250 | |
---|
| 251 | What kind of iterables are acceptable depends on the specific |
---|
| 252 | exporter implementation. |
---|
[7726] | 253 | """ |
---|
| 254 | |
---|
| 255 | def export_all(site, filapath=None): |
---|
| 256 | """Export all items in `site` as CSV file. |
---|
| 257 | |
---|
| 258 | if `filepath` is not given, a string with the data should be returned. |
---|
| 259 | """ |
---|
| 260 | |
---|
[7321] | 261 | class ISIRPExporter(Interface): |
---|
[4789] | 262 | """An exporter for objects. |
---|
| 263 | """ |
---|
| 264 | def export(obj, filepath=None): |
---|
| 265 | """Export by pickling. |
---|
| 266 | |
---|
| 267 | Returns a file-like object containing a representation of `obj`. |
---|
| 268 | |
---|
| 269 | This is done using `pickle`. If `filepath` is ``None``, a |
---|
| 270 | `cStringIO` object is returned, that contains the saved data. |
---|
| 271 | """ |
---|
| 272 | |
---|
[7321] | 273 | class ISIRPXMLExporter(Interface): |
---|
[4789] | 274 | """An XML exporter for objects. |
---|
| 275 | """ |
---|
| 276 | def export(obj, filepath=None): |
---|
| 277 | """Export as XML. |
---|
| 278 | |
---|
| 279 | Returns an XML representation of `obj`. |
---|
| 280 | |
---|
| 281 | If `filepath` is ``None``, a StringIO` object is returned, |
---|
| 282 | that contains the transformed data. |
---|
| 283 | """ |
---|
| 284 | |
---|
[7321] | 285 | class ISIRPXMLImporter(Interface): |
---|
[4789] | 286 | """An XML import for objects. |
---|
| 287 | """ |
---|
| 288 | def doImport(filepath): |
---|
| 289 | """Create Python object from XML. |
---|
| 290 | |
---|
| 291 | Returns a Python object. |
---|
| 292 | """ |
---|
| 293 | |
---|
[4858] | 294 | class IBatchProcessor(Interface): |
---|
| 295 | """A batch processor that handles mass-operations. |
---|
| 296 | """ |
---|
| 297 | name = schema.TextLine( |
---|
| 298 | title = u'Importer name' |
---|
| 299 | ) |
---|
| 300 | |
---|
| 301 | mode = schema.Choice( |
---|
| 302 | title = u'Import mode', |
---|
| 303 | values = ['create', 'update', 'remove'] |
---|
| 304 | ) |
---|
[6136] | 305 | |
---|
[5476] | 306 | def doImport(path, headerfields, mode='create', user='Unknown', |
---|
| 307 | logger=None): |
---|
[4858] | 308 | """Read data from ``path`` and update connected object. |
---|
[5476] | 309 | |
---|
| 310 | `headerfields` is a list of headerfields as read from the file |
---|
| 311 | to import. |
---|
| 312 | |
---|
| 313 | `mode` gives the import mode to use (``'create'``, |
---|
| 314 | ``'update'``, or ``'remove'``. |
---|
| 315 | |
---|
| 316 | `user` is a string describing the user performing the |
---|
| 317 | import. Normally fetched from current principal. |
---|
| 318 | |
---|
| 319 | `logger` is the logger to use during import. |
---|
[4858] | 320 | """ |
---|
| 321 | |
---|
[7321] | 322 | class IContactForm(ISIRPObject): |
---|
[7225] | 323 | """A contact form. |
---|
| 324 | """ |
---|
| 325 | |
---|
| 326 | email_from = schema.ASCIILine( |
---|
| 327 | title = u'Email Address:', |
---|
| 328 | default = None, |
---|
| 329 | required = True, |
---|
| 330 | constraint=validate_email, |
---|
| 331 | ) |
---|
| 332 | |
---|
| 333 | email_to = schema.ASCIILine( |
---|
| 334 | title = u'Email to:', |
---|
| 335 | default = None, |
---|
| 336 | required = True, |
---|
| 337 | constraint=validate_email, |
---|
| 338 | ) |
---|
| 339 | |
---|
| 340 | subject = schema.TextLine( |
---|
| 341 | title = u'Subject:', |
---|
| 342 | required = True,) |
---|
| 343 | |
---|
| 344 | fullname = schema.TextLine( |
---|
| 345 | title = u'Full Name:', |
---|
| 346 | required = True,) |
---|
| 347 | |
---|
| 348 | body = schema.Text( |
---|
| 349 | title = u'Text:', |
---|
| 350 | required = True,) |
---|
| 351 | |
---|
[7233] | 352 | class ISIRPPrincipalInfo(IPrincipalInfo): |
---|
[7321] | 353 | """Infos about principals that are users of SIRP SIRP. |
---|
[7233] | 354 | """ |
---|
| 355 | email = Attribute("The email address of a user") |
---|
| 356 | phone = Attribute("The phone number of a user") |
---|
[7225] | 357 | |
---|
[7233] | 358 | |
---|
| 359 | class ISIRPPrincipal(IPrincipal): |
---|
[7321] | 360 | """A principle for SIRP SIRP. |
---|
[7233] | 361 | |
---|
| 362 | This interface extends zope.security.interfaces.IPrincipal and |
---|
| 363 | requires also an `id` and other attributes defined there. |
---|
| 364 | """ |
---|
| 365 | |
---|
| 366 | email = schema.TextLine( |
---|
| 367 | title = u'Email', |
---|
| 368 | description = u'', |
---|
| 369 | required=False,) |
---|
| 370 | |
---|
[7323] | 371 | phone = schema.TextLine( |
---|
[7233] | 372 | title = u'Phone', |
---|
| 373 | description = u'', |
---|
| 374 | required=False,) |
---|
| 375 | |
---|
[7321] | 376 | class IUserAccount(ISIRPObject): |
---|
[4789] | 377 | """A user account. |
---|
| 378 | """ |
---|
| 379 | name = schema.TextLine( |
---|
| 380 | title = u'User ID', |
---|
[6512] | 381 | description = u'Login name of user', |
---|
[4789] | 382 | required = True,) |
---|
[7221] | 383 | |
---|
[4789] | 384 | title = schema.TextLine( |
---|
[7459] | 385 | title = u'Full Name', |
---|
[4789] | 386 | required = False,) |
---|
[7221] | 387 | |
---|
[7197] | 388 | description = schema.Text( |
---|
| 389 | title = u'Description/Notice', |
---|
[4789] | 390 | required = False,) |
---|
[7221] | 391 | |
---|
| 392 | email = schema.ASCIILine( |
---|
| 393 | title = u'Email', |
---|
| 394 | default = None, |
---|
[7222] | 395 | required = True, |
---|
[7221] | 396 | constraint=validate_email, |
---|
| 397 | ) |
---|
| 398 | |
---|
[7323] | 399 | phone = schema.TextLine( |
---|
[7233] | 400 | title = u'Phone', |
---|
| 401 | default = None, |
---|
| 402 | required = True, |
---|
| 403 | ) |
---|
| 404 | |
---|
[4789] | 405 | roles = schema.List( |
---|
[7178] | 406 | title = u'Portal roles', |
---|
[4789] | 407 | value_type = schema.Choice(source=RoleSource())) |
---|
[6136] | 408 | |
---|
[7147] | 409 | class IPasswordValidator(Interface): |
---|
| 410 | """A password validator utility. |
---|
| 411 | """ |
---|
[6136] | 412 | |
---|
[7147] | 413 | def validate_password(password, password_repeat): |
---|
| 414 | """Validates a password by comparing it with |
---|
| 415 | control password and checking some other requirements. |
---|
| 416 | """ |
---|
| 417 | |
---|
| 418 | |
---|
[7321] | 419 | class IUsersContainer(ISIRPObject): |
---|
[4789] | 420 | """A container for users (principals). |
---|
| 421 | |
---|
| 422 | These users are used for authentication purposes. |
---|
| 423 | """ |
---|
| 424 | |
---|
| 425 | def addUser(name, password, title=None, description=None): |
---|
| 426 | """Add a user. |
---|
| 427 | """ |
---|
| 428 | |
---|
| 429 | def delUser(name): |
---|
| 430 | """Delete a user if it exists. |
---|
| 431 | """ |
---|
| 432 | |
---|
[6141] | 433 | class ILocalRolesAssignable(Interface): |
---|
| 434 | """The local roles assignable to an object. |
---|
| 435 | """ |
---|
| 436 | def __call__(): |
---|
| 437 | """Returns a list of dicts. |
---|
| 438 | |
---|
| 439 | Each dict contains a ``name`` referring to the role assignable |
---|
| 440 | for the specified object and a `title` to describe the range |
---|
| 441 | of users to which this role can be assigned. |
---|
| 442 | """ |
---|
| 443 | |
---|
[7321] | 444 | class IConfigurationContainer(ISIRPObject): |
---|
[6907] | 445 | """A container for session configuration objects. |
---|
| 446 | """ |
---|
| 447 | |
---|
| 448 | name = schema.TextLine( |
---|
| 449 | title = u'Name of University', |
---|
| 450 | default = u'Sample University', |
---|
| 451 | required = True, |
---|
| 452 | ) |
---|
| 453 | |
---|
[7459] | 454 | acronym = schema.TextLine( |
---|
| 455 | title = u'Abbreviated Title of University', |
---|
| 456 | default = u'WAeUP.SIRP', |
---|
| 457 | required = True, |
---|
| 458 | ) |
---|
| 459 | |
---|
[6907] | 460 | skin = schema.Choice( |
---|
| 461 | title = u'Skin', |
---|
| 462 | default = u'gray waeup theme', |
---|
| 463 | vocabulary = 'waeup.sirp.browser.theming.ThemesVocabulary', |
---|
| 464 | required = True, |
---|
| 465 | ) |
---|
| 466 | |
---|
| 467 | frontpage = schema.Text( |
---|
| 468 | title = u'Content in reST format', |
---|
| 469 | required = False, |
---|
| 470 | default = default_frontpage, |
---|
| 471 | ) |
---|
| 472 | |
---|
[7702] | 473 | frontpage_dict = schema.Dict( |
---|
| 474 | title = u'Content as language dictionary with values in html format', |
---|
[7485] | 475 | required = False, |
---|
[7702] | 476 | default = {}, |
---|
[7485] | 477 | ) |
---|
| 478 | |
---|
[6990] | 479 | accommodation_session = schema.Choice( |
---|
| 480 | title = u'Accommodation Booking Session', |
---|
| 481 | source = academic_sessions_vocab, |
---|
| 482 | default = datetime.now().year, |
---|
| 483 | required = False, |
---|
| 484 | readonly = False, |
---|
| 485 | ) |
---|
| 486 | |
---|
| 487 | accommodation_states = schema.List( |
---|
| 488 | title = u'Allowed States for Accommodation Booking', |
---|
| 489 | value_type = schema.Choice( |
---|
| 490 | vocabulary = registration_states_vocab, |
---|
| 491 | ), |
---|
| 492 | default = [], |
---|
| 493 | ) |
---|
| 494 | |
---|
[7223] | 495 | name_admin = schema.TextLine( |
---|
| 496 | title = u'Name of Administrator', |
---|
| 497 | default = u'Administrator', |
---|
| 498 | required = False, |
---|
| 499 | ) |
---|
| 500 | |
---|
[7221] | 501 | email_admin = schema.ASCIILine( |
---|
[7223] | 502 | title = u'Email Address of Administrator', |
---|
[7221] | 503 | default = 'contact@waeup.org', |
---|
| 504 | required = False, |
---|
| 505 | constraint=validate_email, |
---|
| 506 | ) |
---|
| 507 | |
---|
| 508 | email_subject = schema.TextLine( |
---|
| 509 | title = u'Subject of Email to Administrator', |
---|
| 510 | default = u'SIRP Contact', |
---|
| 511 | required = False, |
---|
| 512 | ) |
---|
| 513 | |
---|
[7470] | 514 | smtp_mailer = schema.Choice( |
---|
| 515 | title = u'SMTP mailer to use when sending mail', |
---|
| 516 | vocabulary = 'Mail Delivery Names', |
---|
| 517 | default = 'No email service', |
---|
| 518 | required = True, |
---|
| 519 | ) |
---|
| 520 | |
---|
[7313] | 521 | captcha = schema.Choice( |
---|
[7475] | 522 | title = u'Captcha used for public registration pages', |
---|
[7313] | 523 | source = CaptchaSource(), |
---|
| 524 | default = u'No captcha', |
---|
| 525 | required = True, |
---|
| 526 | ) |
---|
[7221] | 527 | |
---|
[7664] | 528 | carry_over = schema.Bool( |
---|
| 529 | title = u'Carry-over Course Registration', |
---|
| 530 | default = False, |
---|
| 531 | ) |
---|
| 532 | |
---|
[7321] | 533 | class ISessionConfiguration(ISIRPObject): |
---|
[6915] | 534 | """A session configuration object. |
---|
[6907] | 535 | """ |
---|
| 536 | |
---|
[6915] | 537 | academic_session = schema.Choice( |
---|
| 538 | title = u'Academic Session', |
---|
| 539 | source = academic_sessions_vocab, |
---|
| 540 | default = None, |
---|
| 541 | required = True, |
---|
| 542 | readonly = True, |
---|
| 543 | ) |
---|
| 544 | |
---|
[7021] | 545 | school_fee_base = schema.Int( |
---|
[6915] | 546 | title = u'School Fee', |
---|
| 547 | default = 0, |
---|
| 548 | ) |
---|
| 549 | |
---|
[6929] | 550 | surcharge_1 = schema.Int( |
---|
| 551 | title = u'Surcharge 1', |
---|
| 552 | default = 0, |
---|
| 553 | ) |
---|
| 554 | |
---|
| 555 | surcharge_2 = schema.Int( |
---|
| 556 | title = u'Surcharge 2', |
---|
| 557 | default = 0, |
---|
| 558 | ) |
---|
| 559 | |
---|
| 560 | surcharge_3 = schema.Int( |
---|
| 561 | title = u'Surcharge 3', |
---|
| 562 | default = 0, |
---|
| 563 | ) |
---|
| 564 | |
---|
[7022] | 565 | clearance_fee = schema.Int( |
---|
[6929] | 566 | title = u'Clearance Fee', |
---|
[6916] | 567 | default = 0, |
---|
| 568 | ) |
---|
| 569 | |
---|
[6993] | 570 | booking_fee = schema.Int( |
---|
| 571 | title = u'Booking Fee', |
---|
| 572 | default = 0, |
---|
| 573 | ) |
---|
| 574 | |
---|
[7250] | 575 | acceptance_fee = schema.Int( |
---|
| 576 | title = u'Acceptance Fee', |
---|
| 577 | default = 0, |
---|
| 578 | ) |
---|
| 579 | |
---|
[6918] | 580 | def getSessionString(): |
---|
| 581 | """Returns the session string from the vocabulary. |
---|
| 582 | """ |
---|
| 583 | |
---|
| 584 | |
---|
[6916] | 585 | class ISessionConfigurationAdd(ISessionConfiguration): |
---|
| 586 | """A session configuration object in add mode. |
---|
| 587 | """ |
---|
| 588 | |
---|
| 589 | academic_session = schema.Choice( |
---|
| 590 | title = u'Academic Session', |
---|
| 591 | source = academic_sessions_vocab, |
---|
| 592 | default = None, |
---|
| 593 | required = True, |
---|
| 594 | readonly = False, |
---|
| 595 | ) |
---|
| 596 | |
---|
| 597 | ISessionConfigurationAdd['academic_session'].order = ISessionConfiguration[ |
---|
| 598 | 'academic_session'].order |
---|
| 599 | |
---|
[7321] | 600 | class IDataCenter(ISIRPObject): |
---|
[4789] | 601 | """A data center. |
---|
| 602 | |
---|
| 603 | TODO : declare methods, at least those needed by pages. |
---|
| 604 | """ |
---|
| 605 | pass |
---|
| 606 | |
---|
| 607 | class IDataCenterFile(Interface): |
---|
| 608 | """A data center file. |
---|
| 609 | """ |
---|
[4858] | 610 | |
---|
| 611 | name = schema.TextLine( |
---|
| 612 | title = u'Filename') |
---|
| 613 | |
---|
| 614 | size = schema.TextLine( |
---|
| 615 | title = u'Human readable file size') |
---|
| 616 | |
---|
| 617 | uploaddate = schema.TextLine( |
---|
| 618 | title = u'Human readable upload datetime') |
---|
| 619 | |
---|
| 620 | lines = schema.Int( |
---|
| 621 | title = u'Number of lines in file') |
---|
[6136] | 622 | |
---|
[4789] | 623 | def getDate(): |
---|
| 624 | """Get creation timestamp from file in human readable form. |
---|
| 625 | """ |
---|
| 626 | |
---|
| 627 | def getSize(): |
---|
| 628 | """Get human readable size of file. |
---|
| 629 | """ |
---|
[4858] | 630 | |
---|
| 631 | def getLinesNumber(): |
---|
| 632 | """Get number of lines of file. |
---|
| 633 | """ |
---|
[4882] | 634 | |
---|
| 635 | class IDataCenterStorageMovedEvent(IObjectEvent): |
---|
| 636 | """Emitted, when the storage of a datacenter changes. |
---|
| 637 | """ |
---|
[5007] | 638 | |
---|
[6136] | 639 | class IObjectUpgradeEvent(IObjectEvent): |
---|
| 640 | """Can be fired, when an object shall be upgraded. |
---|
| 641 | """ |
---|
| 642 | |
---|
[6180] | 643 | class ILocalRoleSetEvent(IObjectEvent): |
---|
| 644 | """A local role was granted/revoked for a principal on an object. |
---|
| 645 | """ |
---|
| 646 | role_id = Attribute( |
---|
| 647 | "The role id that was set.") |
---|
| 648 | principal_id = Attribute( |
---|
| 649 | "The principal id for which the role was granted/revoked.") |
---|
| 650 | granted = Attribute( |
---|
| 651 | "Boolean. If false, then the role was revoked.") |
---|
| 652 | |
---|
[5007] | 653 | class IQueryResultItem(Interface): |
---|
| 654 | """An item in a search result. |
---|
| 655 | """ |
---|
| 656 | url = schema.TextLine( |
---|
| 657 | title = u'URL that links to the found item') |
---|
| 658 | title = schema.TextLine( |
---|
| 659 | title = u'Title displayed in search results.') |
---|
| 660 | description = schema.Text( |
---|
| 661 | title = u'Longer description of the item found.') |
---|
[6136] | 662 | |
---|
[7321] | 663 | class ISIRPPluggable(Interface): |
---|
| 664 | """A component that might be plugged into a SIRP SIRP app. |
---|
[5658] | 665 | |
---|
| 666 | Components implementing this interface are referred to as |
---|
| 667 | 'plugins'. They are normally called when a new |
---|
| 668 | :class:`waeup.sirp.app.University` instance is created. |
---|
| 669 | |
---|
| 670 | Plugins can setup and update parts of the central site without the |
---|
| 671 | site object (normally a :class:`waeup.sirp.app.University` object) |
---|
| 672 | needing to know about that parts. The site simply collects all |
---|
| 673 | available plugins, calls them and the plugins care for their |
---|
[5676] | 674 | respective subarea like the applicants area or the datacenter |
---|
[5658] | 675 | area. |
---|
| 676 | |
---|
| 677 | Currently we have no mechanism to define an order of plugins. A |
---|
| 678 | plugin should therefore make no assumptions about the state of the |
---|
| 679 | site or other plugins being run before and instead do appropriate |
---|
| 680 | checks if necessary. |
---|
| 681 | |
---|
| 682 | Updates can be triggered for instance by the respective form in |
---|
| 683 | the site configuration. You normally do updates when the |
---|
| 684 | underlying software changed. |
---|
[5013] | 685 | """ |
---|
[5069] | 686 | def setup(site, name, logger): |
---|
| 687 | """Create an instance of the plugin. |
---|
[5013] | 688 | |
---|
[5658] | 689 | The method is meant to be called by the central app (site) |
---|
| 690 | when it is created. |
---|
| 691 | |
---|
| 692 | `site`: |
---|
| 693 | The site that requests a setup. |
---|
| 694 | |
---|
| 695 | `name`: |
---|
| 696 | The name under which the plugin was registered (utility name). |
---|
| 697 | |
---|
| 698 | `logger`: |
---|
| 699 | A standard Python logger for the plugins use. |
---|
[5069] | 700 | """ |
---|
| 701 | |
---|
| 702 | def update(site, name, logger): |
---|
| 703 | """Method to update an already existing plugin. |
---|
| 704 | |
---|
| 705 | This might be called by a site when something serious |
---|
[5658] | 706 | changes. It is a poor-man replacement for Zope generations |
---|
| 707 | (but probably more comprehensive and better understandable). |
---|
| 708 | |
---|
| 709 | `site`: |
---|
| 710 | The site that requests an update. |
---|
| 711 | |
---|
| 712 | `name`: |
---|
| 713 | The name under which the plugin was registered (utility name). |
---|
| 714 | |
---|
| 715 | `logger`: |
---|
| 716 | A standard Python logger for the plugins use. |
---|
[5069] | 717 | """ |
---|
[5898] | 718 | |
---|
[5899] | 719 | class IAuthPluginUtility(Interface): |
---|
[5898] | 720 | """A component that cares for authentication setup at site creation. |
---|
| 721 | |
---|
| 722 | Utilities providing this interface are looked up when a Pluggable |
---|
| 723 | Authentication Utility (PAU) for any |
---|
| 724 | :class:`waeup.sirp.app.University` instance is created and put |
---|
| 725 | into ZODB. |
---|
| 726 | |
---|
| 727 | The setup-code then calls the `register` method of the utility and |
---|
| 728 | expects a modified (or unmodified) version of the PAU back. |
---|
| 729 | |
---|
| 730 | This allows to define any authentication setup modifications by |
---|
| 731 | submodules or third-party modules/packages. |
---|
| 732 | """ |
---|
| 733 | |
---|
| 734 | def register(pau): |
---|
| 735 | """Register any plugins wanted to be in the PAU. |
---|
| 736 | """ |
---|
| 737 | |
---|
| 738 | def unregister(pau): |
---|
| 739 | """Unregister any plugins not wanted to be in the PAU. |
---|
| 740 | """ |
---|
[6273] | 741 | |
---|
| 742 | class IObjectConverter(Interface): |
---|
| 743 | """Object converters are available as simple adapters, adapting |
---|
| 744 | interfaces (not regular instances). |
---|
| 745 | |
---|
| 746 | """ |
---|
| 747 | |
---|
[6277] | 748 | def fromStringDict(self, data_dict, context, form_fields=None): |
---|
| 749 | """Convert values in `data_dict`. |
---|
[6273] | 750 | |
---|
[6277] | 751 | Converts data in `data_dict` into real values based on |
---|
| 752 | `context` and `form_fields`. |
---|
[6273] | 753 | |
---|
[6277] | 754 | `data_dict` is a mapping (dict) from field names to values |
---|
| 755 | represented as strings. |
---|
[6273] | 756 | |
---|
[6277] | 757 | The fields (keys) to convert can be given in optional |
---|
| 758 | `form_fields`. If given, form_fields should be an instance of |
---|
| 759 | :class:`zope.formlib.form.Fields`. Suitable instances are for |
---|
| 760 | example created by :class:`grok.AutoFields`. |
---|
[6273] | 761 | |
---|
[6277] | 762 | If no `form_fields` are given, a default is computed from the |
---|
| 763 | associated interface. |
---|
[6273] | 764 | |
---|
[6277] | 765 | The `context` can be an existing object (implementing the |
---|
| 766 | associated interface) or a factory name. If it is a string, we |
---|
| 767 | try to create an object using |
---|
| 768 | :func:`zope.component.createObject`. |
---|
| 769 | |
---|
| 770 | Returns a tuple ``(<FIELD_ERRORS>, <INVARIANT_ERRORS>, |
---|
| 771 | <DATA_DICT>)`` where |
---|
| 772 | |
---|
| 773 | ``<FIELD_ERRORS>`` |
---|
| 774 | is a list of tuples ``(<FIELD_NAME>, <ERROR>)`` for each |
---|
| 775 | error that happened when validating the input data in |
---|
| 776 | `data_dict` |
---|
| 777 | |
---|
| 778 | ``<INVARIANT_ERRORS>`` |
---|
| 779 | is a list of invariant errors concerning several fields |
---|
| 780 | |
---|
| 781 | ``<DATA_DICT>`` |
---|
| 782 | is a dict with the values from input dict converted. |
---|
| 783 | |
---|
| 784 | If errors happen, i.e. the error lists are not empty, always |
---|
| 785 | an empty ``<DATA_DICT>`` is returned. |
---|
| 786 | |
---|
| 787 | If ``<DATA_DICT>` is non-empty, there were no errors. |
---|
[6273] | 788 | """ |
---|
[6293] | 789 | |
---|
[6338] | 790 | class IObjectHistory(Interface): |
---|
| 791 | |
---|
| 792 | messages = schema.List( |
---|
| 793 | title = u'List of messages stored', |
---|
| 794 | required = True, |
---|
| 795 | ) |
---|
| 796 | |
---|
| 797 | def addMessage(message): |
---|
| 798 | """Add a message. |
---|
| 799 | """ |
---|
[6353] | 800 | |
---|
[7321] | 801 | class ISIRPWorkflowInfo(IWorkflowInfo): |
---|
[6353] | 802 | """A :class:`hurry.workflow.workflow.WorkflowInfo` with additional |
---|
| 803 | methods for convenience. |
---|
| 804 | """ |
---|
| 805 | def getManualTransitions(): |
---|
| 806 | """Get allowed manual transitions. |
---|
| 807 | |
---|
| 808 | Get a sorted list of tuples containing the `transition_id` and |
---|
| 809 | `title` of each allowed transition. |
---|
| 810 | """ |
---|
[6481] | 811 | |
---|
| 812 | class ISiteLoggers(Interface): |
---|
| 813 | |
---|
[7321] | 814 | loggers = Attribute("A list or generator of registered SIRPLoggers") |
---|
[6481] | 815 | |
---|
| 816 | def register(name, filename=None, site=None, **options): |
---|
| 817 | """Register a logger `name` which logs to `filename`. |
---|
| 818 | |
---|
| 819 | If `filename` is not given, logfile will be `name` with |
---|
| 820 | ``.log`` as filename extension. |
---|
| 821 | """ |
---|
| 822 | |
---|
| 823 | def unregister(name): |
---|
| 824 | """Unregister a once registered logger. |
---|
| 825 | """ |
---|
| 826 | |
---|
| 827 | class ILogger(Interface): |
---|
| 828 | """A logger cares for setup, update and restarting of a Python logger. |
---|
| 829 | """ |
---|
| 830 | |
---|
| 831 | logger = Attribute("""A :class:`logging.Logger` instance""") |
---|
| 832 | |
---|
| 833 | |
---|
| 834 | def __init__(name, filename=None, site=None, **options): |
---|
[7321] | 835 | """Create a SIRP logger instance. |
---|
[6481] | 836 | """ |
---|
| 837 | |
---|
| 838 | def setup(): |
---|
| 839 | """Create a Python :class:`logging.Logger` instance. |
---|
| 840 | |
---|
| 841 | The created logger is based on the params given by constructor. |
---|
| 842 | """ |
---|
| 843 | |
---|
| 844 | def update(**options): |
---|
| 845 | """Update the logger. |
---|
| 846 | |
---|
| 847 | Updates the logger respecting modified `options` and changed |
---|
| 848 | paths. |
---|
| 849 | """ |
---|
[6754] | 850 | |
---|
| 851 | class ILoggerCollector(Interface): |
---|
| 852 | |
---|
| 853 | def getLoggers(site): |
---|
| 854 | """Return all loggers registered for `site`. |
---|
| 855 | """ |
---|
| 856 | |
---|
| 857 | def registerLogger(site, logging_component): |
---|
| 858 | """Register a logging component residing in `site`. |
---|
| 859 | """ |
---|
| 860 | |
---|
| 861 | def unregisterLogger(site, logging_component): |
---|
| 862 | """Unregister a logger. |
---|
| 863 | """ |
---|
[7063] | 864 | |
---|
| 865 | # |
---|
| 866 | # External File Storage and relatives |
---|
| 867 | # |
---|
| 868 | class IFileStoreNameChooser(INameChooser): |
---|
| 869 | """See zope.container.interfaces.INameChooser for base methods. |
---|
| 870 | """ |
---|
[7066] | 871 | def checkName(name, attr=None): |
---|
[7063] | 872 | """Check whether an object name is valid. |
---|
| 873 | |
---|
| 874 | Raises a user error if the name is not valid. |
---|
| 875 | """ |
---|
| 876 | |
---|
[7066] | 877 | def chooseName(name, attr=None): |
---|
| 878 | """Choose a unique valid file id for the object. |
---|
[7063] | 879 | |
---|
[7066] | 880 | The given name may be taken into account when choosing the |
---|
| 881 | name (file id). |
---|
[7063] | 882 | |
---|
[7066] | 883 | chooseName is expected to always choose a valid file id (that |
---|
| 884 | would pass the checkName test) and never raise an error. |
---|
| 885 | |
---|
| 886 | If `attr` is not ``None`` it might been taken into account as |
---|
| 887 | well when generating the file id. Usual behaviour is to |
---|
| 888 | interpret `attr` as a hint for what type of file for a given |
---|
| 889 | context should be stored if there are several types |
---|
| 890 | possible. For instance for a certain student some file could |
---|
| 891 | be the connected passport photograph or some certificate scan |
---|
| 892 | or whatever. Each of them has to be stored in a different |
---|
| 893 | location so setting `attr` to a sensible value should give |
---|
| 894 | different file ids returned. |
---|
[7063] | 895 | """ |
---|
| 896 | |
---|
| 897 | class IExtFileStore(IFileRetrieval): |
---|
| 898 | """A file storage that stores files in filesystem (not as blobs). |
---|
| 899 | """ |
---|
| 900 | root = schema.TextLine( |
---|
| 901 | title = u'Root path of file store.', |
---|
| 902 | ) |
---|
| 903 | |
---|
| 904 | def getFile(file_id): |
---|
| 905 | """Get raw file data stored under file with `file_id`. |
---|
| 906 | |
---|
| 907 | Returns a file descriptor open for reading or ``None`` if the |
---|
| 908 | file cannot be found. |
---|
| 909 | """ |
---|
| 910 | |
---|
[7071] | 911 | def getFileByContext(context, attr=None): |
---|
[7063] | 912 | """Get raw file data stored for the given context. |
---|
| 913 | |
---|
| 914 | Returns a file descriptor open for reading or ``None`` if no |
---|
| 915 | such file can be found. |
---|
| 916 | |
---|
[7071] | 917 | Both, `context` and `attr` might be used to find (`context`) |
---|
| 918 | and feed (`attr`) an appropriate file name chooser. |
---|
| 919 | |
---|
[7063] | 920 | This is a convenience method. |
---|
| 921 | """ |
---|
| 922 | |
---|
[7090] | 923 | def deleteFile(file_id): |
---|
| 924 | """Delete file stored under `file_id`. |
---|
| 925 | |
---|
| 926 | Remove file from filestore so, that it is not available |
---|
| 927 | anymore on next call to getFile for the same file_id. |
---|
| 928 | |
---|
| 929 | Should not complain if no such file exists. |
---|
| 930 | """ |
---|
| 931 | |
---|
| 932 | def deleteFileByContext(context, attr=None): |
---|
| 933 | """Delete file for given `context` and `attr`. |
---|
| 934 | |
---|
| 935 | Both, `context` and `attr` might be used to find (`context`) |
---|
| 936 | and feed (`attr`) an appropriate file name chooser. |
---|
| 937 | |
---|
| 938 | This is a convenience method. |
---|
| 939 | """ |
---|
| 940 | |
---|
[7063] | 941 | def createFile(filename, f): |
---|
| 942 | """Create file given by f with filename `filename` |
---|
| 943 | |
---|
| 944 | Returns a hurry.file.File-based object. |
---|
| 945 | """ |
---|
| 946 | |
---|
| 947 | class IFileStoreHandler(Interface): |
---|
| 948 | """Filestore handlers handle specific files for file stores. |
---|
| 949 | |
---|
| 950 | If a file to store/get provides a specific filename, a file store |
---|
| 951 | looks up special handlers for that type of file. |
---|
| 952 | |
---|
| 953 | """ |
---|
| 954 | def pathFromFileID(store, root, filename): |
---|
| 955 | """Turn file id into path to store. |
---|
| 956 | |
---|
| 957 | Returned path should be absolute. |
---|
| 958 | """ |
---|
| 959 | |
---|
| 960 | def createFile(store, root, filename, file_id, file): |
---|
| 961 | """Return some hurry.file based on `store` and `file_id`. |
---|
| 962 | |
---|
| 963 | Some kind of callback method called by file stores to create |
---|
| 964 | file objects from file_id. |
---|
| 965 | |
---|
| 966 | Returns a tuple ``(raw_file, path, file_like_obj)`` where the |
---|
[7321] | 967 | ``file_like_obj`` should be a HurryFile, a SIRPImageFile or |
---|
[7063] | 968 | similar. ``raw_file`` is the (maybe changed) input file and |
---|
| 969 | ``path`` the relative internal path to store the file at. |
---|
| 970 | |
---|
| 971 | Please make sure the ``raw_file`` is opened for reading and |
---|
| 972 | the file descriptor set at position 0 when returned. |
---|
| 973 | |
---|
| 974 | This method also gets the raw input file object that is about |
---|
| 975 | to be stored and is expected to raise any exceptions if some |
---|
| 976 | kind of validation or similar fails. |
---|
| 977 | """ |
---|
[7389] | 978 | |
---|
| 979 | class IPDF(Interface): |
---|
| 980 | """A PDF representation of some context. |
---|
| 981 | """ |
---|
| 982 | |
---|
| 983 | def __call__(view=None): |
---|
| 984 | """Create a bytestream representing a PDF from context. |
---|
| 985 | |
---|
| 986 | If `view` is passed in additional infos might be rendered into |
---|
| 987 | the document. |
---|
| 988 | """ |
---|
[7473] | 989 | |
---|
| 990 | class IMailService(Interface): |
---|
| 991 | """A mail service. |
---|
| 992 | """ |
---|
| 993 | |
---|
| 994 | def __call__(): |
---|
| 995 | """Get the default mail delivery. |
---|
| 996 | """ |
---|
[7576] | 997 | |
---|
| 998 | from zope.configuration.fields import Path |
---|
| 999 | class IDataCenterConfig(Interface): |
---|
| 1000 | path = Path( |
---|
| 1001 | title = u'Path', |
---|
| 1002 | description = u"Directory where the datacenter should store" |
---|
| 1003 | u"files by default (adjustable in web UI).", |
---|
| 1004 | required = True, |
---|
| 1005 | ) |
---|
| 1006 | |
---|