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

Last change on this file since 6305 was 6304, checked in by Henrik Bettermann, 14 years ago

Add message attribute to log workflow transitions.

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