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

Last change on this file since 6341 was 6339, checked in by uli, 14 years ago

Maintain history of objects in a separate component, similar to workflows, instead of storing everything with the object core object.

File size: 3.8 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
[6339]29from waeup.sirp.interfaces import IWAeUPSIRPPluggable, IObjectHistory
[6115]30from waeup.sirp.app import University
[5753]31from waeup.sirp.applicants.interfaces import (
[6314]32    IResultEntry, IApplicant, IApplicantEdit, default_passport_image,
[5272]33    )
[6115]34from waeup.sirp.utils.helpers import attrs_to_fields
[5272]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
[5983]42
[6187]43class 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__()
[6301]49        IWorkflowInfo(self).fireTransition('init')
[6331]50        return
[6296]51
[6324]52    @property
[6332]53    def state(self):
[6324]54        state = IWorkflowState(self).getState()
55        return state
56
[6339]57    @property
58    def history(self):
59        history = IObjectHistory(self)
60        return history
61
[5983]62# Set all attributes of Applicant required in IApplicant as field
63# properties. Doing this, we do not have to set initial attributes
64# ourselves and as a bonus we get free validation when an attribute is
65# set.
[6115]66Applicant = attrs_to_fields(Applicant)
[5272]67
[6115]68class ApplicantCatalog(grok.Indexes):
69    """A catalog indexing :class:`Applicant` instances in the ZODB.
70    """
71    grok.site(University)
72    grok.name('applicants_catalog')
73    grok.context(IApplicant)
74
75    access_code = index.Field(attribute='access_code')
76
[5668]77class ApplicantTraverser(grok.Traverser):
[5763]78    """Get image of the context applicant.
79
80    Each applicant can provide a passport photograph which will be
81    returned by this traverser if:
82
83    - we request the exact filename of the picture or
84
85    - ask for a picture named 'passport.jpg'.
86
87    If no picture was stored yet, we get a placeholder image when
88    asking for `passport.jpg`.
89
90    If none of the above applies, we return ``None``, most probably
91    resulting a :exc:`NotFound` exception.
[6114]92
[5763]93    """
[5668]94    grok.context(IApplicant)
95    def traverse(self, name):
96        passport_filename = getattr(self.context.passport, 'filename', None)
97        if name == passport_filename:
98            return self.context.passport
99        if name == 'passport.jpg':
[5911]100            if self.context.passport is not None:
[5668]101                return self.context.passport
[6314]102            return default_passport_image(self.context)
[5763]103        return
[5668]104
[5318]105class ApplicantFactory(grok.GlobalUtility):
106    """A factory for faculty containers.
107    """
108    grok.implements(IFactory)
109    grok.name(u'waeup.Applicant')
110    title = u"Create a new applicant.",
111    description = u"This factory instantiates new applicant instances."
112
113    def __call__(self, *args, **kw):
114        return Applicant()
115
116    def getInterfaces(self):
[5479]117        return implementedBy(Applicant)
Note: See TracBrowser for help on using the repository browser.