source: main/waeup.sirp/trunk/src/waeup/sirp/applicants/applicants.py @ 6602

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

Increase browser test coverage to 100%.

File size: 3.9 KB
RevLine 
[5272]1##
2## applicants.py
3## Login : <uli@pu.smp.net>
4## Started on  Fri Jul 16 11:46:55 2010 Uli Fouquet
5## $Id$
6##
[6478]7## Copyright (C) 2010 Uli Fouquet & Henrik Bettermann
[5272]8## This program is free software; you can redistribute it and/or modify
9## it under the terms of the GNU General Public License as published by
10## the Free Software Foundation; either version 2 of the License, or
11## (at your option) any later version.
12##
13## This program is distributed in the hope that it will be useful,
14## but WITHOUT ANY WARRANTY; without even the implied warranty of
15## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16## GNU General Public License for more details.
17##
18## You should have received a copy of the GNU General Public License
19## along with this program; if not, write to the Free Software
20## Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21##
22import grok
[6115]23from grok import index
[5318]24from zope.component.interfaces import IFactory
[5479]25from zope.interface import implementedBy
[6296]26from hurry.workflow.interfaces import IWorkflowInfo, IWorkflowState
[6347]27from waeup.sirp.interfaces import IObjectHistory
[6115]28from waeup.sirp.app import University
[5753]29from waeup.sirp.applicants.interfaces import (
[6314]30    IResultEntry, IApplicant, IApplicantEdit, default_passport_image,
[5272]31    )
[6115]32from waeup.sirp.utils.helpers import attrs_to_fields
[5272]33
34class ResultEntry(grok.Context):
35    grok.implements(IResultEntry)
36
37    def __init__(self, subject=None, score=None):
38        self.subject = subject
39        self.score = score
[5983]40
[6187]41class Applicant(grok.Model):
[6196]42    grok.implements(IApplicant,IApplicantEdit)
[5483]43    grok.provides(IApplicant)
[5272]44
[6296]45    def __init__(self):
46        super(Applicant, self).__init__()
[6301]47        IWorkflowInfo(self).fireTransition('init')
[6476]48        self.application_date = None
[6331]49        return
[6296]50
[6475]51    #def getApplicantsRootLogger(self):
52    #    return grok.getSite()['applicants'].logger
[6348]53
[6475]54    def loggerInfo(self, ob_class, comment=None):
55        target = self.__name__
56        return grok.getSite()['applicants'].logger_info(ob_class,target,comment)
57
[6324]58    @property
[6332]59    def state(self):
[6324]60        state = IWorkflowState(self).getState()
61        return state
62
[6339]63    @property
64    def history(self):
65        history = IObjectHistory(self)
66        return history
67
[5983]68# Set all attributes of Applicant required in IApplicant as field
69# properties. Doing this, we do not have to set initial attributes
70# ourselves and as a bonus we get free validation when an attribute is
71# set.
[6115]72Applicant = attrs_to_fields(Applicant)
[5272]73
[6115]74class ApplicantCatalog(grok.Indexes):
75    """A catalog indexing :class:`Applicant` instances in the ZODB.
76    """
77    grok.site(University)
78    grok.name('applicants_catalog')
79    grok.context(IApplicant)
80
81    access_code = index.Field(attribute='access_code')
82
[5668]83class ApplicantTraverser(grok.Traverser):
[5763]84    """Get image of the context applicant.
85
86    Each applicant can provide a passport photograph which will be
87    returned by this traverser if:
88
89    - we request the exact filename of the picture or
90
91    - ask for a picture named 'passport.jpg'.
92
93    If no picture was stored yet, we get a placeholder image when
94    asking for `passport.jpg`.
95
96    If none of the above applies, we return ``None``, most probably
97    resulting a :exc:`NotFound` exception.
[6114]98
[5763]99    """
[5668]100    grok.context(IApplicant)
101    def traverse(self, name):
102        passport_filename = getattr(self.context.passport, 'filename', None)
103        if name == passport_filename:
104            return self.context.passport
105        if name == 'passport.jpg':
[5911]106            if self.context.passport is not None:
[5668]107                return self.context.passport
[5763]108        return
[5668]109
[5318]110class ApplicantFactory(grok.GlobalUtility):
111    """A factory for faculty containers.
112    """
113    grok.implements(IFactory)
114    grok.name(u'waeup.Applicant')
115    title = u"Create a new applicant.",
116    description = u"This factory instantiates new applicant instances."
117
118    def __call__(self, *args, **kw):
119        return Applicant()
120
121    def getInterfaces(self):
[5479]122        return implementedBy(Applicant)
Note: See TracBrowser for help on using the repository browser.