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

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

Fee parameters are not required.

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