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