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

Last change on this file since 6475 was 6475, checked in by Henrik Bettermann, 13 years ago

Save detailed logging messages (experimental).

File size: 3.9 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 zope.component.interfaces import IFactory
25from zope.interface import implementedBy
26from hurry.workflow.interfaces import IWorkflowInfo, IWorkflowState
27from waeup.sirp.interfaces import IObjectHistory
28from waeup.sirp.app import University
29from waeup.sirp.applicants.interfaces import (
30    IResultEntry, IApplicant, IApplicantEdit, default_passport_image,
31    )
32from waeup.sirp.utils.helpers import attrs_to_fields
33
34class ResultEntry(grok.Context):
35    grok.implements(IResultEntry)
36
37    def __init__(self, subject=None, score=None):
38        self.subject = subject
39        self.score = score
40
41class Applicant(grok.Model):
42    grok.implements(IApplicant,IApplicantEdit)
43    grok.provides(IApplicant)
44
45    def __init__(self):
46        super(Applicant, self).__init__()
47        IWorkflowInfo(self).fireTransition('init')
48        return
49
50    #def getApplicantsRootLogger(self):
51    #    return grok.getSite()['applicants'].logger
52
53    def loggerInfo(self, ob_class, comment=None):
54        target = self.__name__
55        return grok.getSite()['applicants'].logger_info(ob_class,target,comment)
56
57    @property
58    def state(self):
59        state = IWorkflowState(self).getState()
60        return state
61
62    @property
63    def history(self):
64        history = IObjectHistory(self)
65        return history
66
67# Set all attributes of Applicant required in IApplicant as field
68# properties. Doing this, we do not have to set initial attributes
69# ourselves and as a bonus we get free validation when an attribute is
70# set.
71Applicant = attrs_to_fields(Applicant)
72
73class ApplicantCatalog(grok.Indexes):
74    """A catalog indexing :class:`Applicant` instances in the ZODB.
75    """
76    grok.site(University)
77    grok.name('applicants_catalog')
78    grok.context(IApplicant)
79
80    access_code = index.Field(attribute='access_code')
81
82class ApplicantTraverser(grok.Traverser):
83    """Get image of the context applicant.
84
85    Each applicant can provide a passport photograph which will be
86    returned by this traverser if:
87
88    - we request the exact filename of the picture or
89
90    - ask for a picture named 'passport.jpg'.
91
92    If no picture was stored yet, we get a placeholder image when
93    asking for `passport.jpg`.
94
95    If none of the above applies, we return ``None``, most probably
96    resulting a :exc:`NotFound` exception.
97
98    """
99    grok.context(IApplicant)
100    def traverse(self, name):
101        passport_filename = getattr(self.context.passport, 'filename', None)
102        if name == passport_filename:
103            return self.context.passport
104        if name == 'passport.jpg':
105            if self.context.passport is not None:
106                return self.context.passport
107            return default_passport_image(self.context)
108        return
109
110class ApplicantFactory(grok.GlobalUtility):
111    """A factory for faculty containers.
112    """
113    grok.implements(IFactory)
114    grok.name(u'waeup.Applicant')
115    title = u"Create a new applicant.",
116    description = u"This factory instantiates new applicant instances."
117
118    def __call__(self, *args, **kw):
119        return Applicant()
120
121    def getInterfaces(self):
122        return implementedBy(Applicant)
Note: See TracBrowser for help on using the repository browser.