[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 | ## |
---|
| 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 | ## |
---|
| 22 | import grok |
---|
[5318] | 23 | from zope.component.interfaces import IFactory |
---|
[5479] | 24 | from zope.interface import implementedBy |
---|
[5272] | 25 | from zope.schema.fieldproperty import FieldProperty |
---|
| 26 | from waeup.sirp.interfaces import IWAeUPSIRPPluggable |
---|
[5753] | 27 | from waeup.sirp.applicants.interfaces import ( |
---|
[5983] | 28 | IResultEntry, IApplicant, IApplicantPDEEditData, |
---|
| 29 | DEFAULT_PASSPORT_IMAGE_MALE, |
---|
[5272] | 30 | ) |
---|
| 31 | |
---|
| 32 | class ResultEntry(grok.Context): |
---|
| 33 | grok.implements(IResultEntry) |
---|
| 34 | |
---|
| 35 | def __init__(self, subject=None, score=None): |
---|
| 36 | self.subject = subject |
---|
| 37 | self.score = score |
---|
[5983] | 38 | |
---|
[5272] | 39 | class Applicant(grok.Context): |
---|
[5483] | 40 | grok.implements(IApplicant, IApplicantPDEEditData) |
---|
| 41 | grok.provides(IApplicant) |
---|
[5272] | 42 | |
---|
[5983] | 43 | # Set all attributes of Applicant required in IApplicant as field |
---|
| 44 | # properties. Doing this, we do not have to set initial attributes |
---|
| 45 | # ourselves and as a bonus we get free validation when an attribute is |
---|
| 46 | # set. |
---|
| 47 | for field_name in list(IApplicant): |
---|
| 48 | setattr(Applicant, field_name, FieldProperty(IApplicant[field_name])) |
---|
[5272] | 49 | |
---|
[5668] | 50 | class ApplicantTraverser(grok.Traverser): |
---|
[5763] | 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 | """ |
---|
[5668] | 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': |
---|
[5911] | 73 | if self.context.passport is not None: |
---|
[5668] | 74 | return self.context.passport |
---|
[5983] | 75 | return DEFAULT_PASSPORT_IMAGE_MALE |
---|
[5763] | 76 | return |
---|
[5668] | 77 | |
---|
[5318] | 78 | class 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): |
---|
[5479] | 90 | return implementedBy(Applicant) |
---|