source: main/waeup.futminna/trunk/src/waeup/futminna/applicants/browser.py @ 8835

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

Merged with waeup.uniben 8802:HEAD.

  • Property svn:keywords set to Id
File size: 8.1 KB
Line 
1## $Id: browser.py 8806 2012-06-26 07:46:43Z henrik $
2##
3## Copyright (C) 2011 Uli Fouquet & Henrik Bettermann
4## This program is free software; you can redistribute it and/or modify
5## it under the terms of the GNU General Public License as published by
6## the Free Software Foundation; either version 2 of the License, or
7## (at your option) any later version.
8##
9## This program is distributed in the hope that it will be useful,
10## but WITHOUT ANY WARRANTY; without even the implied warranty of
11## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12## GNU General Public License for more details.
13##
14## You should have received a copy of the GNU General Public License
15## along with this program; if not, write to the Free Software
16## Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17##
18"""UI components for basic applicants and related components.
19"""
20import grok
21from zope.component import getUtility
22from zope.i18n import translate
23from waeup.kofa.widgets.datewidget import FriendlyDatetimeDisplayWidget
24from waeup.kofa.students.interfaces import IStudentsUtils
25from waeup.kofa.applicants.interfaces import (
26    IApplicantRegisterUpdate, IApplicant, IApplicantEdit)
27from waeup.kofa.applicants.browser import (ApplicantDisplayFormPage,
28    ExportPDFPage,
29    ApplicantManageFormPage, ApplicantEditFormPage,
30    ApplicantRegistrationPage, ApplicantAddFormPage,
31    OnlinePaymentDisplayFormPage, ApplicationFeePaymentAddPage,
32    OnlinePaymentBreadcrumb, ExportPDFPaymentSlipPage,
33    ApplicantBaseDisplayFormPage)
34from waeup.kofa.applicants.viewlets import (
35    PaymentReceiptActionButton, PDFActionButton)
36from waeup.kofa.applicants.pdf import PDFApplicationSlip
37from waeup.futminna.applicants.interfaces import (
38    IPGApplicant, IUGApplicant, IPGApplicantEdit, IUGApplicantEdit,
39    ICustomApplicantOnlinePayment, IPUTMEApplicantEdit,
40    UG_OMIT_DISPLAY_FIELDS, PG_OMIT_DISPLAY_FIELDS,
41    UG_OMIT_PDF_FIELDS, PG_OMIT_PDF_FIELDS,
42    UG_OMIT_MANAGE_FIELDS, PG_OMIT_MANAGE_FIELDS,
43    UG_OMIT_EDIT_FIELDS, PG_OMIT_EDIT_FIELDS, PUTME_OMIT_EDIT_FIELDS,
44    UG_OMIT_RESULT_SLIP_FIELDS)
45from waeup.futminna.interfaces import MessageFactory as _
46
47#class RequestCallbackActionButton(RequestCallbackActionButton):
48#    """ Display the base package callback button in custom pages.
49#    """
50#    grok.context(ICustomApplicantOnlinePayment)
51
52#class CustomOnlinePaymentCallbackPage(OnlinePaymentCallbackPage):
53#    """ Activate callback simulation view
54#    """
55#    grok.context(ICustomApplicantOnlinePayment)
56
57class CustomOnlinePaymentBreadcrumb(OnlinePaymentBreadcrumb):
58    """A breadcrumb for payments.
59    """
60    grok.context(ICustomApplicantOnlinePayment)
61
62class PaymentReceiptActionButton(PaymentReceiptActionButton):
63    grok.order(4)
64    grok.context(ICustomApplicantOnlinePayment)
65
66class PDFActionButton(PDFActionButton):
67
68    @property
69    def text(self):
70        if getattr(self.context, 'result_uploaded', False):
71            return _('Download result slip')
72        return _('Download application slip')
73
74
75class CustomPDFApplicationSlip(PDFApplicationSlip):
76
77    def _reduced_slip(self):
78        return getattr(self.context, 'result_uploaded', False)
79
80    @property
81    def note(self):
82        target = getattr(self.context.__parent__, 'prefix', None)
83        if target is not None and not target.startswith('pg') \
84            and not self._reduced_slip():
85            return _(u'<br /><br /><br />'
86                      'Comfirm your exam venue 72 hours to the exam.')
87        return
88
89    @property
90    def form_fields(self):
91        target = getattr(self.context.__parent__, 'prefix', None)
92        if target is not None and target.startswith('pg'):
93            form_fields = grok.AutoFields(IPGApplicant)
94            for field in PG_OMIT_PDF_FIELDS:
95                form_fields = form_fields.omit(field)
96        else:
97            form_fields = grok.AutoFields(IUGApplicant)
98            if self._reduced_slip():
99                for field in UG_OMIT_RESULT_SLIP_FIELDS:
100                    form_fields = form_fields.omit(field)
101            else:
102                for field in UG_OMIT_PDF_FIELDS:
103                    form_fields = form_fields.omit(field)
104        if not getattr(self.context, 'student_id'):
105            form_fields = form_fields.omit('student_id')
106        return form_fields
107
108class CustomApplicantDisplayFormPage(ApplicantDisplayFormPage):
109    """A display view for applicant data.
110    """
111
112    @property
113    def form_fields(self):
114        target = getattr(self.context.__parent__, 'prefix', None)
115        if target is not None and target.startswith('pg'):
116            form_fields = grok.AutoFields(IPGApplicant)
117            for field in PG_OMIT_DISPLAY_FIELDS:
118                form_fields = form_fields.omit(field)
119        else:
120            form_fields = grok.AutoFields(IUGApplicant)
121            for field in UG_OMIT_DISPLAY_FIELDS:
122                form_fields = form_fields.omit(field)
123        return form_fields
124
125class CustomApplicantManageFormPage(ApplicantManageFormPage):
126    """A full edit view for applicant data.
127    """
128   
129    @property
130    def form_fields(self):
131        target = getattr(self.context.__parent__, 'prefix', None)
132        if target is not None and target.startswith('pg'):
133            form_fields = grok.AutoFields(IPGApplicant)
134            for field in PG_OMIT_MANAGE_FIELDS:
135                form_fields = form_fields.omit(field)
136        else:
137            form_fields = grok.AutoFields(IUGApplicant)
138            for field in UG_OMIT_MANAGE_FIELDS:
139                form_fields = form_fields.omit(field)
140        form_fields['student_id'].for_display = True
141        form_fields['applicant_id'].for_display = True
142        return form_fields
143
144class CustomApplicantEditFormPage(ApplicantEditFormPage):
145    """An applicant-centered edit view for applicant data.
146    """
147
148    @property
149    def form_fields(self):
150        target = getattr(self.context.__parent__, 'prefix', None)
151        if target is not None and target.startswith('pg'):
152            form_fields = grok.AutoFields(IPGApplicantEdit)
153            for field in PG_OMIT_EDIT_FIELDS:
154                form_fields = form_fields.omit(field)
155        elif target is not None and target.startswith('putme'):
156            form_fields = grok.AutoFields(IPUTMEApplicantEdit)
157            for field in PUTME_OMIT_EDIT_FIELDS:
158                form_fields = form_fields.omit(field)
159        else:
160            form_fields = grok.AutoFields(IUGApplicantEdit)
161            for field in UG_OMIT_EDIT_FIELDS:
162                form_fields = form_fields.omit(field)
163        form_fields['applicant_id'].for_display = True
164        form_fields['reg_number'].for_display = True
165        return form_fields
166
167class CustomOnlinePaymentDisplayFormPage(OnlinePaymentDisplayFormPage):
168    """ Page to view an online payment ticket
169    """
170    grok.context(ICustomApplicantOnlinePayment)
171    form_fields = grok.AutoFields(ICustomApplicantOnlinePayment).omit('ac')
172    form_fields[
173        'creation_date'].custom_widget = FriendlyDatetimeDisplayWidget('le')
174    form_fields[
175        'payment_date'].custom_widget = FriendlyDatetimeDisplayWidget('le')
176    grok.template('payment_view')
177
178    @property
179    def transaction_code(self):
180        tcode = self.context.p_id
181        return tcode[len(tcode)-8:len(tcode)]
182
183class CustomApplicationFeePaymentAddPage(ApplicationFeePaymentAddPage):
184    """ Page to add an online payment ticket
185    """
186    factory = u'waeup.CustomApplicantOnlinePayment'
187
188class CustomExportPDFPaymentSlipPage(ExportPDFPaymentSlipPage):
189    """Deliver a PDF slip of the context.
190    """
191    grok.context(ICustomApplicantOnlinePayment)
192    form_fields = grok.AutoFields(ICustomApplicantOnlinePayment).omit('ac')
193    form_fields['creation_date'].custom_widget = FriendlyDatetimeDisplayWidget('le')
194    form_fields['payment_date'].custom_widget = FriendlyDatetimeDisplayWidget('le')
195
196    @property
197    def note(self):
198        if self.context.p_state == 'paid':
199            return None
200        tcode = self.context.p_id
201        tcode = tcode[len(tcode)-8:len(tcode)]
202        amount = self.context.amount_auth
203        note = translate(_(
204            u"""<br /><br /><br />
205The tranzaction code is <strong>${a}</strong>.""",
206            mapping = {'a':tcode}))
207        return note
Note: See TracBrowser for help on using the repository browser.