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

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

Merged with waeup.uniben 8838:8839.

  • Property svn:keywords set to Id
File size: 7.2 KB
RevLine 
[8012]1## $Id: browser.py 8841 2012-06-27 12:47:32Z 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
[8259]21from zope.component import getUtility
22from zope.i18n import translate
[8247]23from waeup.kofa.widgets.datewidget import FriendlyDatetimeDisplayWidget
[8259]24from waeup.kofa.students.interfaces import IStudentsUtils
[8090]25from waeup.kofa.applicants.interfaces import (
26    IApplicantRegisterUpdate, IApplicant, IApplicantEdit)
[8012]27from waeup.kofa.applicants.browser import (ApplicantDisplayFormPage,
[8421]28    ExportPDFPage,
[8090]29    ApplicantManageFormPage, ApplicantEditFormPage,
[8247]30    ApplicantRegistrationPage, ApplicantAddFormPage,
[8263]31    OnlinePaymentDisplayFormPage, ApplicationFeePaymentAddPage,
[8259]32    OnlinePaymentBreadcrumb, ExportPDFPaymentSlipPage,
33    ApplicantBaseDisplayFormPage)
34from waeup.kofa.applicants.viewlets import (
[8806]35    PaymentReceiptActionButton, PDFActionButton)
[8017]36from waeup.kofa.applicants.pdf import PDFApplicationSlip
[8619]37from waeup.futminna.applicants.interfaces import (
[8247]38    IPGApplicant, IUGApplicant, IPGApplicantEdit, IUGApplicantEdit,
[8530]39    ICustomApplicantOnlinePayment, IPUTMEApplicantEdit,
[8519]40    UG_OMIT_DISPLAY_FIELDS, PG_OMIT_DISPLAY_FIELDS,
[8551]41    UG_OMIT_PDF_FIELDS, PG_OMIT_PDF_FIELDS,
[8519]42    UG_OMIT_MANAGE_FIELDS, PG_OMIT_MANAGE_FIELDS,
[8806]43    UG_OMIT_EDIT_FIELDS, PG_OMIT_EDIT_FIELDS, PUTME_OMIT_EDIT_FIELDS,
44    UG_OMIT_RESULT_SLIP_FIELDS)
[8619]45from waeup.futminna.interfaces import MessageFactory as _
[8012]46
[8247]47class CustomOnlinePaymentBreadcrumb(OnlinePaymentBreadcrumb):
48    """A breadcrumb for payments.
[8012]49    """
[8247]50    grok.context(ICustomApplicantOnlinePayment)
[8012]51
[8259]52class PaymentReceiptActionButton(PaymentReceiptActionButton):
53    grok.order(4)
54    grok.context(ICustomApplicantOnlinePayment)
55
[8806]56class PDFActionButton(PDFActionButton):
57
58    @property
59    def text(self):
60        if getattr(self.context, 'result_uploaded', False):
61            return _('Download result slip')
62        return _('Download application slip')
63
64
[8196]65class CustomPDFApplicationSlip(PDFApplicationSlip):
[8012]66
[8806]67    def _reduced_slip(self):
68        return getattr(self.context, 'result_uploaded', False)
69
[8569]70    @property
71    def note(self):
72        target = getattr(self.context.__parent__, 'prefix', None)
[8806]73        if target is not None and not target.startswith('pg') \
74            and not self._reduced_slip():
[8569]75            return _(u'<br /><br /><br />'
76                      'Comfirm your exam venue 72 hours to the exam.')
77        return
[8551]78
[8017]79    @property
80    def form_fields(self):
81        target = getattr(self.context.__parent__, 'prefix', None)
82        if target is not None and target.startswith('pg'):
[8519]83            form_fields = grok.AutoFields(IPGApplicant)
[8551]84            for field in PG_OMIT_PDF_FIELDS:
[8519]85                form_fields = form_fields.omit(field)
[8017]86        else:
[8519]87            form_fields = grok.AutoFields(IUGApplicant)
[8806]88            if self._reduced_slip():
89                for field in UG_OMIT_RESULT_SLIP_FIELDS:
90                    form_fields = form_fields.omit(field)
91            else:
92                for field in UG_OMIT_PDF_FIELDS:
93                    form_fields = form_fields.omit(field)
94        if not getattr(self.context, 'student_id'):
95            form_fields = form_fields.omit('student_id')
[8017]96        return form_fields
[8012]97
[8196]98class CustomApplicantDisplayFormPage(ApplicantDisplayFormPage):
[8017]99    """A display view for applicant data.
100    """
[8012]101
102    @property
103    def form_fields(self):
104        target = getattr(self.context.__parent__, 'prefix', None)
105        if target is not None and target.startswith('pg'):
[8519]106            form_fields = grok.AutoFields(IPGApplicant)
107            for field in PG_OMIT_DISPLAY_FIELDS:
108                form_fields = form_fields.omit(field)
[8012]109        else:
[8519]110            form_fields = grok.AutoFields(IUGApplicant)
111            for field in UG_OMIT_DISPLAY_FIELDS:
112                form_fields = form_fields.omit(field)
[8012]113        return form_fields
114
[8196]115class CustomApplicantManageFormPage(ApplicantManageFormPage):
[8012]116    """A full edit view for applicant data.
117    """
[8017]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(IPGApplicant)
[8519]124            for field in PG_OMIT_MANAGE_FIELDS:
125                form_fields = form_fields.omit(field)
[8017]126        else:
127            form_fields = grok.AutoFields(IUGApplicant)
[8519]128            for field in UG_OMIT_MANAGE_FIELDS:
129                form_fields = form_fields.omit(field)
[8017]130        form_fields['student_id'].for_display = True
131        form_fields['applicant_id'].for_display = True
132        return form_fields
[8012]133
[8196]134class CustomApplicantEditFormPage(ApplicantEditFormPage):
[8012]135    """An applicant-centered edit view for applicant data.
136    """
[8017]137
138    @property
139    def form_fields(self):
140        target = getattr(self.context.__parent__, 'prefix', None)
141        if target is not None and target.startswith('pg'):
[8519]142            form_fields = grok.AutoFields(IPGApplicantEdit)
143            for field in PG_OMIT_EDIT_FIELDS:
144                form_fields = form_fields.omit(field)
[8530]145        elif target is not None and target.startswith('putme'):
146            form_fields = grok.AutoFields(IPUTMEApplicantEdit)
147            for field in PUTME_OMIT_EDIT_FIELDS:
148                form_fields = form_fields.omit(field)
[8017]149        else:
[8519]150            form_fields = grok.AutoFields(IUGApplicantEdit)
151            for field in UG_OMIT_EDIT_FIELDS:
152                form_fields = form_fields.omit(field)
[8017]153        form_fields['applicant_id'].for_display = True
[8051]154        form_fields['reg_number'].for_display = True
[8017]155        return form_fields
[8247]156
157class CustomOnlinePaymentDisplayFormPage(OnlinePaymentDisplayFormPage):
158    """ Page to view an online payment ticket
159    """
160    grok.context(ICustomApplicantOnlinePayment)
[8263]161    form_fields = grok.AutoFields(ICustomApplicantOnlinePayment).omit('ac')
[8247]162    form_fields[
163        'creation_date'].custom_widget = FriendlyDatetimeDisplayWidget('le')
164    form_fields[
165        'payment_date'].custom_widget = FriendlyDatetimeDisplayWidget('le')
166
[8263]167class CustomApplicationFeePaymentAddPage(ApplicationFeePaymentAddPage):
[8247]168    """ Page to add an online payment ticket
169    """
170    factory = u'waeup.CustomApplicantOnlinePayment'
171
[8259]172class CustomExportPDFPaymentSlipPage(ExportPDFPaymentSlipPage):
173    """Deliver a PDF slip of the context.
174    """
175    grok.context(ICustomApplicantOnlinePayment)
[8292]176    form_fields = grok.AutoFields(ICustomApplicantOnlinePayment).omit('ac')
[8259]177    form_fields['creation_date'].custom_widget = FriendlyDatetimeDisplayWidget('le')
178    form_fields['payment_date'].custom_widget = FriendlyDatetimeDisplayWidget('le')
Note: See TracBrowser for help on using the repository browser.