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

Last change on this file since 8376 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
Line 
1## $Id: interfaces.py 8361 2012-05-05 05:00:39Z henrik $
2##
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##
18import os
19import re
20import codecs
21import zope.i18nmessageid
22from datetime import datetime
23from hurry.file.interfaces import IFileRetrieval
24from hurry.workflow.interfaces import IWorkflow, IWorkflowInfo
25from zc.sourcefactory.basic import BasicSourceFactory
26from zope import schema
27from zope.pluggableauth.interfaces import IPrincipalInfo
28from zope.security.interfaces import IGroupClosureAwarePrincipal as IPrincipal
29from zope.component import getUtility
30from zope.component.interfaces import IObjectEvent
31from zope.container.interfaces import INameChooser
32from zope.interface import Interface, Attribute, implements
33from zope.schema.interfaces import IObject
34from zope.schema.vocabulary import SimpleVocabulary, SimpleTerm
35from waeup.kofa.schema import PhoneNumber
36
37_ = MessageFactory = zope.i18nmessageid.MessageFactory('waeup.kofa')
38
39DELETION_MARKER = 'XXX'
40IGNORE_MARKER = '<IGNORE>'
41
42CREATED = 'created'
43ADMITTED = 'admitted'
44CLEARANCE = 'clearance started'
45REQUESTED = 'clearance requested'
46CLEARED = 'cleared'
47PAID = 'school fee paid'
48RETURNING = 'returning'
49REGISTERED = 'courses registered'
50VALIDATED = 'courses validated'
51
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'),
58        encoding='utf-8', mode='rb').read()
59
60def SimpleKofaVocabulary(*terms):
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
69    return range(curr_year - 4, curr_year + 5)
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
76academic_sessions_vocab = SimpleKofaVocabulary(*academic_sessions())
77
78registration_states_vocab = SimpleKofaVocabulary(
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),
88    )
89
90class SubjectSource(BasicSourceFactory):
91    """A source for school subjects used in exam documentation.
92    """
93    def getValues(self):
94        subjects_dict = getUtility(IKofaUtils).EXAM_SUBJECTS_DICT
95        return sorted(subjects_dict.keys())
96
97    def getTitle(self, value):
98        subjects_dict = getUtility(IKofaUtils).EXAM_SUBJECTS_DICT
99        return "%s:" % subjects_dict[value]
100
101class GradeSource(BasicSourceFactory):
102    """A source for exam grades.
103    """
104    def getValues(self):
105        for entry in getUtility(IKofaUtils).EXAM_GRADES:
106            yield entry[0]
107
108    def getTitle(self, value):
109        return dict(getUtility(IKofaUtils).EXAM_GRADES)[value]
110
111# Define a validation method for email addresses
112class NotAnEmailAddress(schema.ValidationError):
113    __doc__ = u"Invalid email address"
114
115check_email = re.compile(
116    r"[a-zA-Z0-9._%-']+@([a-zA-Z0-9-]+.)*[a-zA-Z]{2,4}").match
117
118def validate_email(value):
119    if not check_email(value):
120        raise NotAnEmailAddress(value)
121    return True
122
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):
131    if not RE_INT_PHONE.match(value):
132        raise InvalidPhoneNumber(value)
133    return True
134
135class FatalCSVError(Exception):
136    """Some row could not be processed.
137    """
138    pass
139
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
155class RoleSource(BasicSourceFactory):
156    """A source for site roles.
157    """
158    def getValues(self):
159        # late import: in interfaces we should not import local modules
160        from waeup.kofa.permissions import get_waeup_role_names
161        return get_waeup_role_names()
162
163    def getTitle(self, value):
164        # late import: in interfaces we should not import local modules
165        from waeup.kofa.permissions import get_all_roles
166        roles = dict(get_all_roles())
167        if value in roles.keys():
168            title = roles[value].title
169            if '.' in title:
170                title = title.split('.', 2)[1]
171        return title
172
173class CaptchaSource(BasicSourceFactory):
174    """A source for captchas.
175    """
176    def getValues(self):
177        captchas = ['No captcha', 'Testing captcha', 'ReCaptcha']
178        try:
179            # we have to 'try' because IConfiguration can only handle
180            # interfaces from w.k.interface.
181            from waeup.kofa.browser.interfaces import ICaptchaManager
182        except:
183            return captchas
184        return sorted(getUtility(ICaptchaManager).getAvailCaptchas().keys())
185
186    def getTitle(self, value):
187        return value
188
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
208class IKofaUtils(Interface):
209    """A collection of methods which are subject to customization.
210    """
211
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")
220    INT_PHONE_PREFIXES = Attribute("Dict of international phone number prefixes")
221
222    def sendContactForm(
223          from_name,from_addr,rcpt_name,rcpt_addr,
224          from_username,usertype,portal,body,subject):
225        """Send an email with data provided by forms.
226        """
227
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
245class IKofaObject(Interface):
246    """A Kofa object.
247
248    This is merely a marker interface.
249    """
250
251class IUniversity(IKofaObject):
252    """Representation of a university.
253    """
254
255
256class IKofaContainer(IKofaObject):
257    """A container for Kofa objects.
258    """
259
260class IKofaContained(IKofaObject):
261    """An item contained in an IKofaContainer.
262    """
263
264class ICSVExporter(Interface):
265    """A CSV file exporter for objects.
266    """
267    fields = Attribute("""List of fieldnames in resulting CSV""")
268
269    title = schema.TextLine(
270        title = u'Title',
271        description = u'Description to be displayed in selections.',
272        )
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
279    def export(iterable, filepath=None):
280        """Export iterables as rows in a CSV file.
281
282        If `filepath` is not given, a string with the data should be returned.
283
284        What kind of iterables are acceptable depends on the specific
285        exporter implementation.
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
294class IKofaExporter(Interface):
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
306class IKofaXMLExporter(Interface):
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
318class IKofaXMLImporter(Interface):
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
327class IBatchProcessor(Interface):
328    """A batch processor that handles mass-operations.
329    """
330    name = schema.TextLine(
331        title = _(u'Processor name')
332        )
333
334    def doImport(path, headerfields, mode='create', user='Unknown',
335                 logger=None, ignore_empty=True):
336        """Read data from ``path`` and update connected object.
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.
348
349        `ignore_emtpy` in update mode ignores empty fields if true.
350        """
351
352class IContactForm(IKofaObject):
353    """A contact form.
354    """
355
356    email_from = schema.ASCIILine(
357        title = _(u'Email Address:'),
358        default = None,
359        required = True,
360        constraint=validate_email,
361        )
362
363    email_to = schema.ASCIILine(
364        title = _(u'Email to:'),
365        default = None,
366        required = True,
367        constraint=validate_email,
368        )
369
370    subject = schema.TextLine(
371        title = _(u'Subject:'),
372        required = True,)
373
374    fullname = schema.TextLine(
375        title = _(u'Full Name:'),
376        required = True,)
377
378    body = schema.Text(
379        title = _(u'Text:'),
380        required = True,)
381
382class IKofaPrincipalInfo(IPrincipalInfo):
383    """Infos about principals that are users of Kofa Kofa.
384    """
385    email = Attribute("The email address of a user")
386    phone = Attribute("The phone number of a user")
387
388
389class IKofaPrincipal(IPrincipal):
390    """A principle for Kofa Kofa.
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(
397        title = _(u'Email Address'),
398        description = u'',
399        required=False,)
400
401    phone = PhoneNumber(
402        title = _(u'Phone'),
403        description = u'',
404        required=False,)
405
406class IUserAccount(IKofaObject):
407    """A user account.
408    """
409    name = schema.TextLine(
410        title = _(u'User Id'),
411        description = u'Login name of user',
412        required = True,)
413
414    title = schema.TextLine(
415        title = _(u'Full Name'),
416        required = False,)
417
418    description = schema.Text(
419        title = _(u'Description/Notice'),
420        required = False,)
421
422    email = schema.ASCIILine(
423        title = _(u'Email Address'),
424        default = None,
425        required = True,
426        constraint=validate_email,
427        )
428
429    phone = PhoneNumber(
430        title = _(u'Phone'),
431        default = None,
432        required = False,
433        )
434
435    roles = schema.List(
436        title = _(u'Portal roles'),
437        value_type = schema.Choice(source=RoleSource()),
438        required = False,
439        )
440
441class IPasswordValidator(Interface):
442    """A password validator utility.
443    """
444
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
451class IUsersContainer(IKofaObject):
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
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
476class IConfigurationContainer(IKofaObject):
477    """A container for session configuration objects.
478    """
479
480    name = schema.TextLine(
481        title = _(u'Name of University'),
482        default = _(u'Sample University'),
483        required = True,
484        )
485
486    acronym = schema.TextLine(
487        title = _(u'Abbreviated Title of University'),
488        default = u'WAeUP.Kofa',
489        required = True,
490        )
491
492    skin = schema.Choice(
493        title = _(u'Skin'),
494        default = u'gray waeup theme',
495        vocabulary = 'waeup.kofa.browser.theming.ThemesVocabulary',
496        required = True,
497        )
498
499    frontpage = schema.Text(
500        title = _(u'Content in HTML format'),
501        required = False,
502        default = default_html_frontpage,
503        )
504
505    frontpage_dict = schema.Dict(
506        title = u'Content as language dictionary with values in html format',
507        required = False,
508        default = {},
509        )
510
511    accommodation_session = schema.Choice(
512        title = _(u'Accommodation Booking Session'),
513        source = academic_sessions_vocab,
514        default = datetime.now().year,
515        required = False,
516        readonly = False,
517        )
518
519    accommodation_states = schema.List(
520        title = _(u'Allowed States for Accommodation Booking'),
521        value_type = schema.Choice(
522            vocabulary = registration_states_vocab,
523            ),
524        default = [],
525        )
526
527    name_admin = schema.TextLine(
528        title = _(u'Name of Administrator'),
529        default = u'Administrator',
530        required = True,
531        )
532
533    email_admin = schema.ASCIILine(
534        title = _(u'Email Address of Administrator'),
535        default = 'contact@waeup.org',
536        required = True,
537        constraint=validate_email,
538        )
539
540    email_subject = schema.TextLine(
541        title = _(u'Subject of Email to Administrator'),
542        default = _(u'Kofa Contact'),
543        required = True,
544        )
545
546    smtp_mailer = schema.Choice(
547        title = _(u'SMTP mailer to use when sending mail'),
548        vocabulary = 'Mail Delivery Names',
549        default = 'No email service',
550        required = True,
551        )
552
553    captcha = schema.Choice(
554        title = _(u'Captcha used for public registration pages'),
555        source = CaptchaSource(),
556        default = u'No captcha',
557        required = True,
558        )
559
560    carry_over = schema.Bool(
561        title = _(u'Carry-over Course Registration'),
562        default = False,
563        )
564
565class ISessionConfiguration(IKofaObject):
566    """A session configuration object.
567    """
568
569    academic_session = schema.Choice(
570        title = _(u'Academic Session'),
571        source = academic_sessions_vocab,
572        default = None,
573        required = True,
574        readonly = True,
575        )
576
577    application_fee = schema.Float(
578        title = _(u'Application Fee'),
579        default = 0.0,
580        required = False,
581        )
582
583    clearance_fee = schema.Float(
584        title = _(u'Clearance Fee'),
585        default = 0.0,
586        required = False,
587        )
588
589    booking_fee = schema.Float(
590        title = _(u'Bed Booking Fee'),
591        default = 0.0,
592        required = False,
593        )
594
595    def getSessionString():
596        """Returns the session string from the vocabulary.
597        """
598
599
600class ISessionConfigurationAdd(ISessionConfiguration):
601    """A session configuration object in add mode.
602    """
603
604    academic_session = schema.Choice(
605        title = _(u'Academic Session'),
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
615class IDataCenter(IKofaObject):
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    """
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')
637
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        """
645
646    def getLinesNumber():
647        """Get number of lines of file.
648        """
649
650class IDataCenterStorageMovedEvent(IObjectEvent):
651    """Emitted, when the storage of a datacenter changes.
652    """
653
654class IObjectUpgradeEvent(IObjectEvent):
655    """Can be fired, when an object shall be upgraded.
656    """
657
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
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.')
677
678class IKofaPluggable(Interface):
679    """A component that might be plugged into a Kofa Kofa app.
680
681    Components implementing this interface are referred to as
682    'plugins'. They are normally called when a new
683    :class:`waeup.kofa.app.University` instance is created.
684
685    Plugins can setup and update parts of the central site without the
686    site object (normally a :class:`waeup.kofa.app.University` object)
687    needing to know about that parts. The site simply collects all
688    available plugins, calls them and the plugins care for their
689    respective subarea like the applicants area or the datacenter
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.
700    """
701    def setup(site, name, logger):
702        """Create an instance of the plugin.
703
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.
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
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.
732        """
733
734class IAuthPluginUtility(Interface):
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
739    :class:`waeup.kofa.app.University` instance is created and put
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        """
756
757class IObjectConverter(Interface):
758    """Object converters are available as simple adapters, adapting
759       interfaces (not regular instances).
760
761    """
762
763    def fromStringDict(self, data_dict, context, form_fields=None):
764        """Convert values in `data_dict`.
765
766        Converts data in `data_dict` into real values based on
767        `context` and `form_fields`.
768
769        `data_dict` is a mapping (dict) from field names to values
770        represented as strings.
771
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`.
776
777        If no `form_fields` are given, a default is computed from the
778        associated interface.
779
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.
803        """
804
805class IFieldConverter(Interface):
806    def request_data(name, value, schema_field, prefix='', mode='create'):
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
813        `mode` gives the mode of import.
814
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
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        """
838
839class IKofaWorkflowInfo(IWorkflowInfo):
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        """
849
850class ISiteLoggers(Interface):
851
852    loggers = Attribute("A list or generator of registered KofaLoggers")
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):
873        """Create a Kofa logger instance.
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        """
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        """
902
903#
904# External File Storage and relatives
905#
906class IFileStoreNameChooser(INameChooser):
907    """See zope.container.interfaces.INameChooser for base methods.
908    """
909    def checkName(name, attr=None):
910        """Check whether an object name is valid.
911
912        Raises a user error if the name is not valid.
913        """
914
915    def chooseName(name, attr=None):
916        """Choose a unique valid file id for the object.
917
918        The given name may be taken into account when choosing the
919        name (file id).
920
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.
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
949    def getFileByContext(context, attr=None):
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
955        Both, `context` and `attr` might be used to find (`context`)
956        and feed (`attr`) an appropriate file name chooser.
957
958        This is a convenience method.
959        """
960
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
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
1005        ``file_like_obj`` should be a HurryFile, a KofaImageFile or
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        """
1016
1017class IPDF(Interface):
1018    """A PDF representation of some context.
1019    """
1020
1021    def __call__(view=None, note=None):
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.
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.
1031        """
1032
1033class IMailService(Interface):
1034    """A mail service.
1035    """
1036
1037    def __call__():
1038        """Get the default mail delivery.
1039        """
1040
1041from zope.configuration.fields import Path
1042class IDataCenterConfig(Interface):
1043    path = Path(
1044        title = u'Path',
1045        description = u"Directory where the datacenter should store "
1046                      u"files by default (adjustable in web UI).",
1047        required = True,
1048        )
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.