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

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

Surcharge 1 is portal provider fee.

Show data on goto_interswitch page.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 29.8 KB
Line 
1## $Id: interfaces.py 7875 2012-03-14 07:52:17Z 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'Portal Fee'),
573        default = 0,
574        )
575
576    surcharge_2 = schema.Int(
577        title = _(u'Surcharge 2'),
578        default = 0,
579        )
580
581    surcharge_3 = schema.Int(
582        title = _(u'Surcharge 3'),
583        default = 0,
584        )
585
586    clearance_fee = schema.Int(
587        title = _(u'Clearance Fee'),
588        default = 0,
589        )
590
591    booking_fee = schema.Int(
592        title = _(u'Booking Fee'),
593        default = 0,
594        )
595
596    acceptance_fee = schema.Int(
597        title = _(u'Acceptance Fee'),
598        default = 0,
599        )
600
601    def getSessionString():
602        """Returns the session string from the vocabulary.
603        """
604
605
606class ISessionConfigurationAdd(ISessionConfiguration):
607    """A session configuration object in add mode.
608    """
609
610    academic_session = schema.Choice(
611        title = _(u'Academic Session'),
612        source = academic_sessions_vocab,
613        default = None,
614        required = True,
615        readonly = False,
616        )
617
618ISessionConfigurationAdd['academic_session'].order =  ISessionConfiguration[
619    'academic_session'].order
620
621class IDataCenter(IKofaObject):
622    """A data center.
623
624    TODO : declare methods, at least those needed by pages.
625    """
626    pass
627
628class IDataCenterFile(Interface):
629    """A data center file.
630    """
631
632    name = schema.TextLine(
633        title = u'Filename')
634
635    size = schema.TextLine(
636        title = u'Human readable file size')
637
638    uploaddate = schema.TextLine(
639        title = u'Human readable upload datetime')
640
641    lines = schema.Int(
642        title = u'Number of lines in file')
643
644    def getDate():
645        """Get creation timestamp from file in human readable form.
646        """
647
648    def getSize():
649        """Get human readable size of file.
650        """
651
652    def getLinesNumber():
653        """Get number of lines of file.
654        """
655
656class IDataCenterStorageMovedEvent(IObjectEvent):
657    """Emitted, when the storage of a datacenter changes.
658    """
659
660class IObjectUpgradeEvent(IObjectEvent):
661    """Can be fired, when an object shall be upgraded.
662    """
663
664class ILocalRoleSetEvent(IObjectEvent):
665    """A local role was granted/revoked for a principal on an object.
666    """
667    role_id = Attribute(
668        "The role id that was set.")
669    principal_id = Attribute(
670        "The principal id for which the role was granted/revoked.")
671    granted = Attribute(
672        "Boolean. If false, then the role was revoked.")
673
674class IQueryResultItem(Interface):
675    """An item in a search result.
676    """
677    url = schema.TextLine(
678        title = u'URL that links to the found item')
679    title = schema.TextLine(
680        title = u'Title displayed in search results.')
681    description = schema.Text(
682        title = u'Longer description of the item found.')
683
684class IKofaPluggable(Interface):
685    """A component that might be plugged into a Kofa Kofa app.
686
687    Components implementing this interface are referred to as
688    'plugins'. They are normally called when a new
689    :class:`waeup.kofa.app.University` instance is created.
690
691    Plugins can setup and update parts of the central site without the
692    site object (normally a :class:`waeup.kofa.app.University` object)
693    needing to know about that parts. The site simply collects all
694    available plugins, calls them and the plugins care for their
695    respective subarea like the applicants area or the datacenter
696    area.
697
698    Currently we have no mechanism to define an order of plugins. A
699    plugin should therefore make no assumptions about the state of the
700    site or other plugins being run before and instead do appropriate
701    checks if necessary.
702
703    Updates can be triggered for instance by the respective form in
704    the site configuration. You normally do updates when the
705    underlying software changed.
706    """
707    def setup(site, name, logger):
708        """Create an instance of the plugin.
709
710        The method is meant to be called by the central app (site)
711        when it is created.
712
713        `site`:
714           The site that requests a setup.
715
716        `name`:
717           The name under which the plugin was registered (utility name).
718
719        `logger`:
720           A standard Python logger for the plugins use.
721        """
722
723    def update(site, name, logger):
724        """Method to update an already existing plugin.
725
726        This might be called by a site when something serious
727        changes. It is a poor-man replacement for Zope generations
728        (but probably more comprehensive and better understandable).
729
730        `site`:
731           The site that requests an update.
732
733        `name`:
734           The name under which the plugin was registered (utility name).
735
736        `logger`:
737           A standard Python logger for the plugins use.
738        """
739
740class IAuthPluginUtility(Interface):
741    """A component that cares for authentication setup at site creation.
742
743    Utilities providing this interface are looked up when a Pluggable
744    Authentication Utility (PAU) for any
745    :class:`waeup.kofa.app.University` instance is created and put
746    into ZODB.
747
748    The setup-code then calls the `register` method of the utility and
749    expects a modified (or unmodified) version of the PAU back.
750
751    This allows to define any authentication setup modifications by
752    submodules or third-party modules/packages.
753    """
754
755    def register(pau):
756        """Register any plugins wanted to be in the PAU.
757        """
758
759    def unregister(pau):
760        """Unregister any plugins not wanted to be in the PAU.
761        """
762
763class IObjectConverter(Interface):
764    """Object converters are available as simple adapters, adapting
765       interfaces (not regular instances).
766
767    """
768
769    def fromStringDict(self, data_dict, context, form_fields=None):
770        """Convert values in `data_dict`.
771
772        Converts data in `data_dict` into real values based on
773        `context` and `form_fields`.
774
775        `data_dict` is a mapping (dict) from field names to values
776        represented as strings.
777
778        The fields (keys) to convert can be given in optional
779        `form_fields`. If given, form_fields should be an instance of
780        :class:`zope.formlib.form.Fields`. Suitable instances are for
781        example created by :class:`grok.AutoFields`.
782
783        If no `form_fields` are given, a default is computed from the
784        associated interface.
785
786        The `context` can be an existing object (implementing the
787        associated interface) or a factory name. If it is a string, we
788        try to create an object using
789        :func:`zope.component.createObject`.
790
791        Returns a tuple ``(<FIELD_ERRORS>, <INVARIANT_ERRORS>,
792        <DATA_DICT>)`` where
793
794        ``<FIELD_ERRORS>``
795           is a list of tuples ``(<FIELD_NAME>, <ERROR>)`` for each
796           error that happened when validating the input data in
797           `data_dict`
798
799        ``<INVARIANT_ERRORS>``
800           is a list of invariant errors concerning several fields
801
802        ``<DATA_DICT>``
803           is a dict with the values from input dict converted.
804
805        If errors happen, i.e. the error lists are not empty, always
806        an empty ``<DATA_DICT>`` is returned.
807
808        If ``<DATA_DICT>` is non-empty, there were no errors.
809        """
810
811class IObjectHistory(Interface):
812
813    messages = schema.List(
814        title = u'List of messages stored',
815        required = True,
816        )
817
818    def addMessage(message):
819        """Add a message.
820        """
821
822class IKofaWorkflowInfo(IWorkflowInfo):
823    """A :class:`hurry.workflow.workflow.WorkflowInfo` with additional
824       methods for convenience.
825    """
826    def getManualTransitions():
827        """Get allowed manual transitions.
828
829        Get a sorted list of tuples containing the `transition_id` and
830        `title` of each allowed transition.
831        """
832
833class ISiteLoggers(Interface):
834
835    loggers = Attribute("A list or generator of registered KofaLoggers")
836
837    def register(name, filename=None, site=None, **options):
838        """Register a logger `name` which logs to `filename`.
839
840        If `filename` is not given, logfile will be `name` with
841        ``.log`` as filename extension.
842        """
843
844    def unregister(name):
845        """Unregister a once registered logger.
846        """
847
848class ILogger(Interface):
849    """A logger cares for setup, update and restarting of a Python logger.
850    """
851
852    logger = Attribute("""A :class:`logging.Logger` instance""")
853
854
855    def __init__(name, filename=None, site=None, **options):
856        """Create a Kofa logger instance.
857        """
858
859    def setup():
860        """Create a Python :class:`logging.Logger` instance.
861
862        The created logger is based on the params given by constructor.
863        """
864
865    def update(**options):
866        """Update the logger.
867
868        Updates the logger respecting modified `options` and changed
869        paths.
870        """
871
872class ILoggerCollector(Interface):
873
874    def getLoggers(site):
875        """Return all loggers registered for `site`.
876        """
877
878    def registerLogger(site, logging_component):
879        """Register a logging component residing in `site`.
880        """
881
882    def unregisterLogger(site, logging_component):
883        """Unregister a logger.
884        """
885
886#
887# External File Storage and relatives
888#
889class IFileStoreNameChooser(INameChooser):
890    """See zope.container.interfaces.INameChooser for base methods.
891    """
892    def checkName(name, attr=None):
893        """Check whether an object name is valid.
894
895        Raises a user error if the name is not valid.
896        """
897
898    def chooseName(name, attr=None):
899        """Choose a unique valid file id for the object.
900
901        The given name may be taken into account when choosing the
902        name (file id).
903
904        chooseName is expected to always choose a valid file id (that
905        would pass the checkName test) and never raise an error.
906
907        If `attr` is not ``None`` it might been taken into account as
908        well when generating the file id. Usual behaviour is to
909        interpret `attr` as a hint for what type of file for a given
910        context should be stored if there are several types
911        possible. For instance for a certain student some file could
912        be the connected passport photograph or some certificate scan
913        or whatever. Each of them has to be stored in a different
914        location so setting `attr` to a sensible value should give
915        different file ids returned.
916        """
917
918class IExtFileStore(IFileRetrieval):
919    """A file storage that stores files in filesystem (not as blobs).
920    """
921    root = schema.TextLine(
922        title = u'Root path of file store.',
923        )
924
925    def getFile(file_id):
926        """Get raw file data stored under file with `file_id`.
927
928        Returns a file descriptor open for reading or ``None`` if the
929        file cannot be found.
930        """
931
932    def getFileByContext(context, attr=None):
933        """Get raw file data stored for the given context.
934
935        Returns a file descriptor open for reading or ``None`` if no
936        such file can be found.
937
938        Both, `context` and `attr` might be used to find (`context`)
939        and feed (`attr`) an appropriate file name chooser.
940
941        This is a convenience method.
942        """
943
944    def deleteFile(file_id):
945        """Delete file stored under `file_id`.
946
947        Remove file from filestore so, that it is not available
948        anymore on next call to getFile for the same file_id.
949
950        Should not complain if no such file exists.
951        """
952
953    def deleteFileByContext(context, attr=None):
954        """Delete file for given `context` and `attr`.
955
956        Both, `context` and `attr` might be used to find (`context`)
957        and feed (`attr`) an appropriate file name chooser.
958
959        This is a convenience method.
960        """
961
962    def createFile(filename, f):
963        """Create file given by f with filename `filename`
964
965        Returns a hurry.file.File-based object.
966        """
967
968class IFileStoreHandler(Interface):
969    """Filestore handlers handle specific files for file stores.
970
971    If a file to store/get provides a specific filename, a file store
972    looks up special handlers for that type of file.
973
974    """
975    def pathFromFileID(store, root, filename):
976        """Turn file id into path to store.
977
978        Returned path should be absolute.
979        """
980
981    def createFile(store, root, filename, file_id, file):
982        """Return some hurry.file based on `store` and `file_id`.
983
984        Some kind of callback method called by file stores to create
985        file objects from file_id.
986
987        Returns a tuple ``(raw_file, path, file_like_obj)`` where the
988        ``file_like_obj`` should be a HurryFile, a KofaImageFile or
989        similar. ``raw_file`` is the (maybe changed) input file and
990        ``path`` the relative internal path to store the file at.
991
992        Please make sure the ``raw_file`` is opened for reading and
993        the file descriptor set at position 0 when returned.
994
995        This method also gets the raw input file object that is about
996        to be stored and is expected to raise any exceptions if some
997        kind of validation or similar fails.
998        """
999
1000class IPDF(Interface):
1001    """A PDF representation of some context.
1002    """
1003
1004    def __call__(view=None):
1005        """Create a bytestream representing a PDF from context.
1006
1007        If `view` is passed in additional infos might be rendered into
1008        the document.
1009        """
1010
1011class IMailService(Interface):
1012    """A mail service.
1013    """
1014
1015    def __call__():
1016        """Get the default mail delivery.
1017        """
1018
1019from zope.configuration.fields import Path
1020class IDataCenterConfig(Interface):
1021    path = Path(
1022        title = u'Path',
1023        description = u"Directory where the datacenter should store "
1024                      u"files by default (adjustable in web UI).",
1025        required = True,
1026        )
Note: See TracBrowser for help on using the repository browser.