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