[7438] | 1 | ## $Id: viewlets.py 8420 2012-05-11 14:18:47Z 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 | import grok |
---|
| 19 | from hurry.workflow.interfaces import IWorkflowState |
---|
[7819] | 20 | from waeup.kofa.interfaces import IKofaObject |
---|
[7811] | 21 | from waeup.kofa.students.viewlets import PrimaryStudentNavTab |
---|
| 22 | from waeup.kofa.browser.viewlets import ManageActionButton, PrimaryNavTab |
---|
| 23 | from waeup.kofa.applicants.interfaces import ( |
---|
[7438] | 24 | IApplicant, IApplicantsRoot, IApplicantsContainer, |
---|
| 25 | IApplicantOnlinePayment, |
---|
| 26 | ) |
---|
[7811] | 27 | from waeup.kofa.applicants.browser import ( |
---|
[7438] | 28 | ApplicantsRootPage, ApplicantsContainerPage, ApplicantManageFormPage, |
---|
| 29 | ApplicantDisplayFormPage, OnlinePaymentDisplayFormPage |
---|
| 30 | ) |
---|
| 31 | |
---|
[7811] | 32 | from waeup.kofa.interfaces import MessageFactory as _ |
---|
[7674] | 33 | |
---|
[7819] | 34 | grok.context(IKofaObject) # Make IKofaObject the default context |
---|
[7438] | 35 | grok.templatedir('browser_templates') |
---|
| 36 | |
---|
| 37 | class ApplicantsAuthTab(PrimaryNavTab): |
---|
| 38 | """Applicants tab in primary navigation. |
---|
| 39 | """ |
---|
[7819] | 40 | grok.context(IKofaObject) |
---|
[7438] | 41 | grok.order(3) |
---|
| 42 | grok.require('waeup.viewApplicantsTab') |
---|
| 43 | pnav = 3 |
---|
[7674] | 44 | tab_title = _(u'Applicants') |
---|
[7438] | 45 | |
---|
| 46 | @property |
---|
| 47 | def link_target(self): |
---|
| 48 | return self.view.application_url('applicants') |
---|
| 49 | |
---|
| 50 | class ApplicantsAnonTab(ApplicantsAuthTab): |
---|
| 51 | """Applicants tab in primary navigation. |
---|
| 52 | |
---|
| 53 | Display tab only for anonymous. Authenticated users can call the |
---|
| 54 | form from the user navigation bar. |
---|
| 55 | """ |
---|
| 56 | grok.require('waeup.Anonymous') |
---|
[7674] | 57 | tab_title = _(u'Application') |
---|
[7438] | 58 | |
---|
| 59 | # Also zope.manager has role Anonymous. |
---|
| 60 | # To avoid displaying this tab, we have to check the principal id too. |
---|
| 61 | @property |
---|
| 62 | def link_target(self): |
---|
| 63 | if self.request.principal.id == 'zope.anybody': |
---|
| 64 | return self.view.application_url('applicants') |
---|
| 65 | return |
---|
| 66 | |
---|
| 67 | class MyApplicationDataTab(PrimaryStudentNavTab): |
---|
| 68 | """MyData-tab in primary navigation. |
---|
| 69 | """ |
---|
| 70 | grok.order(3) |
---|
| 71 | grok.require('waeup.viewMyApplicationDataTab') |
---|
| 72 | pnav = 3 |
---|
[7714] | 73 | tab_title = _(u'My Data') |
---|
[7438] | 74 | |
---|
| 75 | @property |
---|
| 76 | def link_target(self): |
---|
| 77 | try: |
---|
| 78 | container, application_number = self.request.principal.id.split('_') |
---|
| 79 | except ValueError: |
---|
| 80 | return |
---|
| 81 | rel_link = '/applicants/%s/%s' % (container, application_number) |
---|
| 82 | return self.view.application_url() + rel_link |
---|
| 83 | |
---|
[8406] | 84 | class ApplicantsRootSearchActionButton(ManageActionButton): |
---|
[8404] | 85 | grok.order(1) |
---|
| 86 | grok.context(IApplicantsRoot) |
---|
| 87 | grok.view(ApplicantsRootPage) |
---|
| 88 | grok.require('waeup.viewApplication') |
---|
| 89 | text = _('Search applicants') |
---|
| 90 | icon = 'actionicon_search.png' |
---|
| 91 | target = '@@search' |
---|
| 92 | |
---|
[8406] | 93 | class ApplicantsRootManageActionButton(ManageActionButton): |
---|
[8404] | 94 | grok.order(2) |
---|
[7438] | 95 | grok.context(IApplicantsRoot) |
---|
| 96 | grok.view(ApplicantsRootPage) |
---|
| 97 | grok.require('waeup.manageApplication') |
---|
[7714] | 98 | text = _('Manage application section') |
---|
[7438] | 99 | |
---|
[8406] | 100 | #class ApplicantsContainerManageActionButton(ManageActionButton): |
---|
| 101 | # grok.order(1) |
---|
| 102 | # grok.context(IApplicantsContainer) |
---|
| 103 | # grok.view(ApplicantsContainerPage) |
---|
| 104 | # grok.require('waeup.manageApplication') |
---|
| 105 | # text = _('Manage application records') |
---|
[7438] | 106 | |
---|
| 107 | class ApplicantRegisterActionButton(ManageActionButton): |
---|
| 108 | grok.order(2) |
---|
| 109 | grok.context(IApplicantsContainer) |
---|
| 110 | grok.view(ApplicantsContainerPage) |
---|
| 111 | grok.require('waeup.Anonymous') |
---|
| 112 | icon = 'actionicon_login.png' |
---|
[7714] | 113 | text = _('Register for application') |
---|
[7438] | 114 | target = 'register' |
---|
| 115 | |
---|
| 116 | class ApplicantViewActionButton(ManageActionButton): |
---|
| 117 | grok.context(IApplicant) |
---|
| 118 | grok.view(ApplicantManageFormPage) |
---|
| 119 | grok.require('waeup.viewApplication') |
---|
| 120 | icon = 'actionicon_view.png' |
---|
[7714] | 121 | text = _('View application record') |
---|
[7438] | 122 | target = 'index' |
---|
| 123 | |
---|
| 124 | class ApplicantManageActionButton(ManageActionButton): |
---|
| 125 | grok.order(1) |
---|
| 126 | grok.context(IApplicant) |
---|
| 127 | grok.view(ApplicantDisplayFormPage) |
---|
| 128 | grok.require('waeup.manageApplication') |
---|
[7714] | 129 | text = _('Manage application record') |
---|
[7438] | 130 | target = 'manage' |
---|
| 131 | |
---|
| 132 | class ApplicantEditActionButton(ManageActionButton): |
---|
| 133 | grok.order(2) |
---|
| 134 | grok.context(IApplicant) |
---|
| 135 | grok.view(ApplicantDisplayFormPage) |
---|
| 136 | grok.require('waeup.handleApplication') |
---|
[7714] | 137 | text = _('Edit application record') |
---|
[7438] | 138 | target ='edit' |
---|
| 139 | |
---|
| 140 | @property |
---|
| 141 | def target_url(self): |
---|
| 142 | """Get a URL to the target... |
---|
| 143 | """ |
---|
| 144 | if self.context.locked: |
---|
| 145 | return |
---|
| 146 | return self.view.url(self.view.context, self.target) |
---|
| 147 | |
---|
| 148 | class PDFActionButton(ManageActionButton): |
---|
| 149 | grok.order(3) |
---|
| 150 | grok.context(IApplicant) |
---|
| 151 | grok.require('waeup.viewApplication') |
---|
| 152 | icon = 'actionicon_pdf.png' |
---|
[7714] | 153 | text = _('Download application slip') |
---|
[7438] | 154 | target = 'application_slip.pdf' |
---|
| 155 | |
---|
| 156 | class StudentCreateActionButton(ManageActionButton): |
---|
| 157 | grok.order(4) |
---|
| 158 | grok.context(IApplicant) |
---|
| 159 | grok.require('waeup.manageApplication') |
---|
| 160 | icon = 'actionicon_entrance.png' |
---|
[7714] | 161 | text = _('Create student record') |
---|
[7438] | 162 | target ='createstudent' |
---|
| 163 | |
---|
| 164 | @property |
---|
| 165 | def target_url(self): |
---|
| 166 | """Get a URL to the target... |
---|
| 167 | """ |
---|
| 168 | if IWorkflowState(self.context).getState() != 'admitted': |
---|
| 169 | return |
---|
| 170 | return self.view.url(self.view.context, self.target) |
---|
| 171 | |
---|
| 172 | class PaymentReceiptActionButton(ManageActionButton): |
---|
| 173 | grok.order(1) |
---|
| 174 | grok.context(IApplicantOnlinePayment) |
---|
| 175 | grok.view(OnlinePaymentDisplayFormPage) |
---|
| 176 | grok.require('waeup.viewApplication') |
---|
| 177 | icon = 'actionicon_pdf.png' |
---|
[8262] | 178 | text = _('Download payment slip') |
---|
| 179 | target = 'payment_slip.pdf' |
---|
[7438] | 180 | |
---|
| 181 | @property |
---|
| 182 | def target_url(self): |
---|
[8262] | 183 | #if self.context.p_state != 'paid': |
---|
| 184 | # return '' |
---|
[7438] | 185 | return self.view.url(self.view.context, self.target) |
---|
| 186 | |
---|
[8420] | 187 | class ApprovePaymentActionButton(ManageActionButton): |
---|
[7438] | 188 | grok.order(2) |
---|
| 189 | grok.context(IApplicantOnlinePayment) |
---|
| 190 | grok.view(OnlinePaymentDisplayFormPage) |
---|
[8420] | 191 | grok.require('waeup.managePortal') |
---|
[7438] | 192 | icon = 'actionicon_call.png' |
---|
[8420] | 193 | text = _('Approve payment') |
---|
| 194 | target = 'approve' |
---|
[7438] | 195 | |
---|
| 196 | @property |
---|
| 197 | def target_url(self): |
---|
[8243] | 198 | if self.context.p_state == 'paid': |
---|
[7438] | 199 | return '' |
---|
[7811] | 200 | return self.view.url(self.view.context, self.target) |
---|