source: main/waeup.kofa/trunk/src/waeup/kofa/interfaces.py @ 8369

Last change on this file since 8369 was 8361, checked in by Henrik Bettermann, 13 years ago

Add HTMLDisplayWidget which is now used for the frontpage by default.

Add frontpage.html default content.

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