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