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

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