source: main/waeup.fceokene/trunk/src/waeup/fceokene/applicants/browser.py @ 8520

Last change on this file since 8520 was 8520, checked in by Henrik Bettermann, 12 years ago

See previous revision.

  • Property svn:keywords set to Id
File size: 6.9 KB
Line 
1## $Id: browser.py 8520 2012-05-25 10:33:15Z 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)
36from waeup.kofa.applicants.pdf import PDFApplicationSlip
37from waeup.fceokene.applicants.interfaces import (
38    IPGApplicant, IUGApplicant, IPGApplicantEdit, IUGApplicantEdit,
39    ICustomApplicantOnlinePayment,
40    UG_OMIT_DISPLAY_FIELDS, PG_OMIT_DISPLAY_FIELDS,
41    UG_OMIT_MANAGE_FIELDS, PG_OMIT_MANAGE_FIELDS,
42    UG_OMIT_EDIT_FIELDS, PG_OMIT_EDIT_FIELDS)
43from waeup.fceokene.interfaces import MessageFactory as _
44
45#class RequestCallbackActionButton(RequestCallbackActionButton):
46#    """ Display the base package callback button in custom pages.
47#    """
48#    grok.context(ICustomApplicantOnlinePayment)
49
50#class CustomOnlinePaymentCallbackPage(OnlinePaymentCallbackPage):
51#    """ Activate callback simulation view
52#    """
53#    grok.context(ICustomApplicantOnlinePayment)
54
55class CustomOnlinePaymentBreadcrumb(OnlinePaymentBreadcrumb):
56    """A breadcrumb for payments.
57    """
58    grok.context(ICustomApplicantOnlinePayment)
59
60class PaymentReceiptActionButton(PaymentReceiptActionButton):
61    grok.order(4)
62    grok.context(ICustomApplicantOnlinePayment)
63
64class CustomPDFApplicationSlip(PDFApplicationSlip):
65
66    @property
67    def form_fields(self):
68        target = getattr(self.context.__parent__, 'prefix', None)
69        if target is not None and target.startswith('pg'):
70            form_fields = grok.AutoFields(IPGApplicant)
71            for field in PG_OMIT_DISPLAY_FIELDS:
72                form_fields = form_fields.omit(field)
73        else:
74            form_fields = grok.AutoFields(IUGApplicant)
75            for field in UG_OMIT_DISPLAY_FIELDS:
76                form_fields = form_fields.omit(field)
77        return form_fields
78
79class CustomApplicantDisplayFormPage(ApplicantDisplayFormPage):
80    """A display view for applicant data.
81    """
82
83    @property
84    def form_fields(self):
85        target = getattr(self.context.__parent__, 'prefix', None)
86        if target is not None and target.startswith('pg'):
87            form_fields = grok.AutoFields(IPGApplicant)
88            for field in PG_OMIT_DISPLAY_FIELDS:
89                form_fields = form_fields.omit(field)
90        else:
91            form_fields = grok.AutoFields(IUGApplicant)
92            for field in UG_OMIT_DISPLAY_FIELDS:
93                form_fields = form_fields.omit(field)
94        return form_fields
95
96class CustomApplicantManageFormPage(ApplicantManageFormPage):
97    """A full edit view for applicant data.
98    """
99   
100    @property
101    def form_fields(self):
102        target = getattr(self.context.__parent__, 'prefix', None)
103        if target is not None and target.startswith('pg'):
104            form_fields = grok.AutoFields(IPGApplicant)
105            for field in PG_OMIT_MANAGE_FIELDS:
106                form_fields = form_fields.omit(field)
107        else:
108            form_fields = grok.AutoFields(IUGApplicant)
109            for field in UG_OMIT_MANAGE_FIELDS:
110                form_fields = form_fields.omit(field)
111        form_fields['student_id'].for_display = True
112        form_fields['applicant_id'].for_display = True
113        return form_fields
114
115class CustomApplicantEditFormPage(ApplicantEditFormPage):
116    """An applicant-centered edit view for applicant data.
117    """
118
119    @property
120    def form_fields(self):
121        target = getattr(self.context.__parent__, 'prefix', None)
122        if target is not None and target.startswith('pg'):
123            form_fields = grok.AutoFields(IPGApplicantEdit)
124            for field in PG_OMIT_EDIT_FIELDS:
125                form_fields = form_fields.omit(field)
126        else:
127            form_fields = grok.AutoFields(IUGApplicantEdit)
128            for field in UG_OMIT_EDIT_FIELDS:
129                form_fields = form_fields.omit(field)
130        form_fields['applicant_id'].for_display = True
131        form_fields['reg_number'].for_display = True
132        return form_fields
133
134class CustomOnlinePaymentDisplayFormPage(OnlinePaymentDisplayFormPage):
135    """ Page to view an online payment ticket
136    """
137    grok.context(ICustomApplicantOnlinePayment)
138    form_fields = grok.AutoFields(ICustomApplicantOnlinePayment).omit('ac')
139    form_fields[
140        'creation_date'].custom_widget = FriendlyDatetimeDisplayWidget('le')
141    form_fields[
142        'payment_date'].custom_widget = FriendlyDatetimeDisplayWidget('le')
143    grok.template('payment_view')
144
145    @property
146    def transaction_code(self):
147        tcode = self.context.p_id
148        return tcode[len(tcode)-8:len(tcode)]
149
150class CustomApplicationFeePaymentAddPage(ApplicationFeePaymentAddPage):
151    """ Page to add an online payment ticket
152    """
153    factory = u'waeup.CustomApplicantOnlinePayment'
154
155    def _fillCustomFields(self, payment, session_config):
156        # No custom fields at the moment
157        return payment
158
159class CustomExportPDFPaymentSlipPage(ExportPDFPaymentSlipPage):
160    """Deliver a PDF slip of the context.
161    """
162    grok.context(ICustomApplicantOnlinePayment)
163    form_fields = grok.AutoFields(ICustomApplicantOnlinePayment).omit('ac')
164    form_fields['creation_date'].custom_widget = FriendlyDatetimeDisplayWidget('le')
165    form_fields['payment_date'].custom_widget = FriendlyDatetimeDisplayWidget('le')
166
167    @property
168    def note(self):
169        if self.context.p_state == 'paid':
170            return None
171        tcode = self.context.p_id
172        tcode = tcode[len(tcode)-8:len(tcode)]
173        amount = self.context.amount_auth
174        note = translate(_(
175            u"""<br /><br /><br />
176The tranzaction code is <strong>${a}</strong>.""",
177            mapping = {'a':tcode}))
178        return note
Note: See TracBrowser for help on using the repository browser.