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