source: main/kofacustom.lpng/trunk/src/kofacustom/lpng/applicants/browser.py @ 17086

Last change on this file since 17086 was 17073, checked in by Henrik Bettermann, 2 years ago

Update form.

  • Property svn:keywords set to Id
File size: 6.7 KB
Line 
1## $Id: browser.py 17073 2022-08-22 09:59:29Z 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.formlib.textwidgets import BytesDisplayWidget
22from zope.component import getUtility
23from hurry.workflow.interfaces import IWorkflowState
24from waeup.kofa.widgets.datewidget import (
25    FriendlyDateDisplayWidget,
26    FriendlyDatetimeDisplayWidget)
27from waeup.kofa.applicants.pdf import PDFApplicationSlip
28from waeup.kofa.applicants.browser import (
29    ApplicantRegistrationPage, ApplicantsContainerPage,
30    ApplicantDisplayFormPage,
31    ApplicantManageFormPage,
32    ApplicantEditFormPage,
33    BalancePaymentAddFormPage,
34    ExportPDFPaymentSlipPage,
35    ApplicantBaseDisplayFormPage)
36from waeup.kofa.applicants.workflow import (
37    INITIALIZED, STARTED, PAID, SUBMITTED,
38    ADMITTED, NOT_ADMITTED, CREATED, PROCESSED)
39from waeup.kofa.students.interfaces import IStudentsUtils
40from waeup.kofa.applicants.interfaces import (
41    IApplicantOnlinePayment, IApplicantsUtils)
42from kofacustom.nigeria.applicants.interfaces import INigeriaApplicantOnlinePayment
43from kofacustom.nigeria.applicants.browser import NigeriaExportPDFPaymentSlipPage
44from kofacustom.lpng.applicants.interfaces import (
45    ICustomApplicant,
46    ICustomApplicantOnlinePayment,
47    ICustomApplicantEdit,
48    )
49from kofacustom.lpng.interfaces import MessageFactory as _
50
51       
52class CustomApplicantDisplayFormPage(ApplicantDisplayFormPage):
53    """A display view for applicant data.
54    """
55
56    @property
57    def form_fields(self):
58        form_fields = grok.AutoFields(ICustomApplicant)
59        form_fields['perm_address'].custom_widget = BytesDisplayWidget
60        form_fields['notice'].custom_widget = BytesDisplayWidget
61        if not getattr(self.context, 'student_id'):
62            form_fields = form_fields.omit('student_id')
63        return form_fields
64
65class CustomPDFApplicationSlip(PDFApplicationSlip):
66
67    @property
68    def form_fields(self):
69        form_fields = grok.AutoFields(ICustomApplicant)
70        if not getattr(self.context, 'student_id'):
71            form_fields = form_fields.omit('student_id')
72        return form_fields
73
74class CustomApplicantManageFormPage(ApplicantManageFormPage):
75    """A full edit view for applicant data.
76    """
77
78    @property
79    def display_actions(self):
80        actions = [[_('Save'), _('Finally Submit')],
81                   [
82                    #_('Add online payment ticket'),
83                    _('Add balance payment ticket'),
84                    _('Remove selected tickets')
85                   ]]
86        applicants_utils = getUtility(IApplicantsUtils)
87        if self.context.state not in applicants_utils.BALANCE_PAYMENT_STATES:
88            actions[1].pop(1)
89        return actions
90
91    @property
92    def form_fields(self):
93        form_fields = grok.AutoFields(ICustomApplicant)
94        if not getattr(self.context, 'student_id'):
95            form_fields = form_fields.omit('student_id')
96        form_fields['applicant_id'].for_display = True
97        return form_fields
98
99class CustomApplicantEditFormPage(ApplicantEditFormPage):
100    """An applicant-centered edit view for applicant data.
101    """
102
103    def unremovable(self, ticket):
104        return True
105
106    @property
107    def display_actions(self):
108        state = IWorkflowState(self.context).getState()
109        actions = [[_('Save')],
110                   [
111                    #_('Remove selected tickets')
112                   ]]
113        if state == STARTED:
114            actions = [[_('Save')],
115                [
116                 #_('Add online payment ticket'),
117                 #_('Remove selected tickets')
118                ]]
119        elif self.context.special and state == PAID:
120            actions = [[_('Save'), _('Finally Submit')],
121                [
122                 #_('Add online payment ticket'),
123                 #_('Remove selected tickets')
124                ]]
125        elif state == PAID:
126            actions = [[_('Save'), _('Finally Submit')],
127                [
128                 #_('Remove selected tickets')
129                ]]
130        applicants_utils = getUtility(IApplicantsUtils)
131        if self.context.state in applicants_utils.BALANCE_PAYMENT_STATES:
132            actions[1].append(_('Add balance payment ticket'))
133        return actions
134
135    @property
136    def form_fields(self):
137        form_fields = grok.AutoFields(ICustomApplicantEdit)
138        form_fields = form_fields.omit('notice', 'locked', 'suspended')
139        if not getattr(self.context, 'student_id'):
140            form_fields = form_fields.omit('student_id')
141        form_fields['applicant_id'].for_display = True
142        form_fields['reg_number'].for_display = True
143        return form_fields
144       
145class CustomBalancePaymentAddFormPage(BalancePaymentAddFormPage):
146    """ Page to add an online payment which can balance s previous session
147    payment.
148    """
149    grok.require('waeup.payApplicant')
150   
151class CustomApplicantBaseDisplayFormPage(ApplicantBaseDisplayFormPage):
152
153    @property
154    def form_fields(self):
155        form_fields = grok.AutoFields(ICustomApplicant).select(
156            'applicant_id', 'reg_number', 'email')
157        return form_fields
158
159class CustomExportPDFPaymentSlipPage(NigeriaExportPDFPaymentSlipPage):
160    """Deliver a PDF slip of the context.
161    """
162    # use IApplicantOnlinePayment alternativly
163    form_fields = grok.AutoFields(INigeriaApplicantOnlinePayment).omit(
164        'p_item').omit('p_option').omit('p_combi')
165    form_fields['creation_date'].custom_widget = FriendlyDatetimeDisplayWidget('le')
166    form_fields['payment_date'].custom_widget = FriendlyDatetimeDisplayWidget('le')
167
168    def render(self):
169        if self.payment_slip_download_warning:
170            self.flash(self.payment_slip_download_warning, type='danger')
171            self.redirect(self.url(self.context))
172            return
173        applicantview = CustomApplicantBaseDisplayFormPage(self.context.__parent__,
174            self.request)
175        students_utils = getUtility(IStudentsUtils)
176        return students_utils.renderPDF(self,'payment_slip.pdf',
177            self.context.__parent__, applicantview, note=self.note,
178            omit_fields=())
Note: See TracBrowser for help on using the repository browser.