[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 |
---|
[6115] | 23 | from grok import index |
---|
[5318] | 24 | from zope.component.interfaces import IFactory |
---|
[5479] | 25 | from zope.interface import implementedBy |
---|
[5272] | 26 | from zope.schema.fieldproperty import FieldProperty |
---|
| 27 | from waeup.sirp.interfaces import IWAeUPSIRPPluggable |
---|
[6115] | 28 | from waeup.sirp.app import University |
---|
[5753] | 29 | from waeup.sirp.applicants.interfaces import ( |
---|
[6196] | 30 | IResultEntry, IApplicant, IApplicantEdit, |
---|
[5983] | 31 | DEFAULT_PASSPORT_IMAGE_MALE, |
---|
[5272] | 32 | ) |
---|
[6115] | 33 | from waeup.sirp.utils.helpers import attrs_to_fields |
---|
[5272] | 34 | |
---|
| 35 | class ResultEntry(grok.Context): |
---|
| 36 | grok.implements(IResultEntry) |
---|
| 37 | |
---|
| 38 | def __init__(self, subject=None, score=None): |
---|
| 39 | self.subject = subject |
---|
| 40 | self.score = score |
---|
[5983] | 41 | |
---|
[6187] | 42 | class Applicant(grok.Model): |
---|
[6196] | 43 | grok.implements(IApplicant,IApplicantEdit) |
---|
[5483] | 44 | grok.provides(IApplicant) |
---|
[5272] | 45 | |
---|
[5983] | 46 | # Set all attributes of Applicant required in IApplicant as field |
---|
| 47 | # properties. Doing this, we do not have to set initial attributes |
---|
| 48 | # ourselves and as a bonus we get free validation when an attribute is |
---|
| 49 | # set. |
---|
[6115] | 50 | Applicant = attrs_to_fields(Applicant) |
---|
[5272] | 51 | |
---|
[6115] | 52 | class ApplicantCatalog(grok.Indexes): |
---|
| 53 | """A catalog indexing :class:`Applicant` instances in the ZODB. |
---|
| 54 | """ |
---|
| 55 | grok.site(University) |
---|
| 56 | grok.name('applicants_catalog') |
---|
| 57 | grok.context(IApplicant) |
---|
| 58 | |
---|
| 59 | access_code = index.Field(attribute='access_code') |
---|
| 60 | |
---|
[5668] | 61 | class ApplicantTraverser(grok.Traverser): |
---|
[5763] | 62 | """Get image of the context applicant. |
---|
| 63 | |
---|
| 64 | Each applicant can provide a passport photograph which will be |
---|
| 65 | returned by this traverser if: |
---|
| 66 | |
---|
| 67 | - we request the exact filename of the picture or |
---|
| 68 | |
---|
| 69 | - ask for a picture named 'passport.jpg'. |
---|
| 70 | |
---|
| 71 | If no picture was stored yet, we get a placeholder image when |
---|
| 72 | asking for `passport.jpg`. |
---|
| 73 | |
---|
| 74 | If none of the above applies, we return ``None``, most probably |
---|
| 75 | resulting a :exc:`NotFound` exception. |
---|
[6114] | 76 | |
---|
[5763] | 77 | """ |
---|
[5668] | 78 | grok.context(IApplicant) |
---|
| 79 | def traverse(self, name): |
---|
| 80 | passport_filename = getattr(self.context.passport, 'filename', None) |
---|
| 81 | if name == passport_filename: |
---|
| 82 | return self.context.passport |
---|
| 83 | if name == 'passport.jpg': |
---|
[5911] | 84 | if self.context.passport is not None: |
---|
[5668] | 85 | return self.context.passport |
---|
[5983] | 86 | return DEFAULT_PASSPORT_IMAGE_MALE |
---|
[5763] | 87 | return |
---|
[5668] | 88 | |
---|
[5318] | 89 | class ApplicantFactory(grok.GlobalUtility): |
---|
| 90 | """A factory for faculty containers. |
---|
| 91 | """ |
---|
| 92 | grok.implements(IFactory) |
---|
| 93 | grok.name(u'waeup.Applicant') |
---|
| 94 | title = u"Create a new applicant.", |
---|
| 95 | description = u"This factory instantiates new applicant instances." |
---|
| 96 | |
---|
| 97 | def __call__(self, *args, **kw): |
---|
| 98 | return Applicant() |
---|
| 99 | |
---|
| 100 | def getInterfaces(self): |
---|
[5479] | 101 | return implementedBy(Applicant) |
---|