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