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

Last change on this file since 6114 was 6114, checked in by uli, 13 years ago
  • Remove trailing whitespaces.
  • Use attr_to_fields.
File size: 3.1 KB
Line 
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##
7## Copyright (C) 2010 Uli Fouquet
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
23from zope.component.interfaces import IFactory
24from zope.interface import implementedBy
25from zope.schema.fieldproperty import FieldProperty
26from waeup.sirp.interfaces import IWAeUPSIRPPluggable
27from waeup.sirp.applicants.interfaces import (
28    IResultEntry, IApplicant, IApplicantPDEEditData,
29    DEFAULT_PASSPORT_IMAGE_MALE,
30    )
31from waeup.sirp.utils.helpers import attr_to_fields
32
33class ResultEntry(grok.Context):
34    grok.implements(IResultEntry)
35
36    def __init__(self, subject=None, score=None):
37        self.subject = subject
38        self.score = score
39
40class Applicant(grok.Context):
41    grok.implements(IApplicant, IApplicantPDEEditData)
42    grok.provides(IApplicant)
43
44# Set all attributes of Applicant required in IApplicant as field
45# properties. Doing this, we do not have to set initial attributes
46# ourselves and as a bonus we get free validation when an attribute is
47# set.
48Applicant = attr_to_fields(Applicant)
49
50class ApplicantTraverser(grok.Traverser):
51    """Get image of the context applicant.
52
53    Each applicant can provide a passport photograph which will be
54    returned by this traverser if:
55
56    - we request the exact filename of the picture or
57
58    - ask for a picture named 'passport.jpg'.
59
60    If no picture was stored yet, we get a placeholder image when
61    asking for `passport.jpg`.
62
63    If none of the above applies, we return ``None``, most probably
64    resulting a :exc:`NotFound` exception.
65
66    """
67    grok.context(IApplicant)
68    def traverse(self, name):
69        passport_filename = getattr(self.context.passport, 'filename', None)
70        if name == passport_filename:
71            return self.context.passport
72        if name == 'passport.jpg':
73            if self.context.passport is not None:
74                return self.context.passport
75            return DEFAULT_PASSPORT_IMAGE_MALE
76        return
77
78class ApplicantFactory(grok.GlobalUtility):
79    """A factory for faculty containers.
80    """
81    grok.implements(IFactory)
82    grok.name(u'waeup.Applicant')
83    title = u"Create a new applicant.",
84    description = u"This factory instantiates new applicant instances."
85
86    def __call__(self, *args, **kw):
87        return Applicant()
88
89    def getInterfaces(self):
90        return implementedBy(Applicant)
Note: See TracBrowser for help on using the repository browser.