## $Id: viewlets.py 7693 2012-02-23 17:28:45Z henrik $ ## ## Copyright (C) 2011 Uli Fouquet & Henrik Bettermann ## This program is free software; you can redistribute it and/or modify ## it under the terms of the GNU General Public License as published by ## the Free Software Foundation; either version 2 of the License, or ## (at your option) any later version. ## ## This program is distributed in the hope that it will be useful, ## but WITHOUT ANY WARRANTY; without even the implied warranty of ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ## GNU General Public License for more details. ## ## You should have received a copy of the GNU General Public License ## along with this program; if not, write to the Free Software ## Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA ## import grok import zope.i18nmessageid from hurry.workflow.interfaces import IWorkflowState from waeup.sirp.interfaces import ISIRPObject from waeup.sirp.students.viewlets import PrimaryStudentNavTab from waeup.sirp.browser.viewlets import ManageActionButton, PrimaryNavTab from waeup.sirp.applicants.interfaces import ( IApplicant, IApplicantsRoot, IApplicantsContainer, IApplicantOnlinePayment, ) from waeup.sirp.applicants.browser import ( ApplicantsRootPage, ApplicantsContainerPage, ApplicantManageFormPage, ApplicantDisplayFormPage, OnlinePaymentDisplayFormPage ) from waeup.sirp.interfaces import MessageFactory as _ grok.context(ISIRPObject) # Make ISIRPObject the default context grok.templatedir('browser_templates') class ApplicantsAuthTab(PrimaryNavTab): """Applicants tab in primary navigation. """ grok.context(ISIRPObject) grok.order(3) grok.require('waeup.viewApplicantsTab') pnav = 3 tab_title = _(u'Applicants') @property def link_target(self): return self.view.application_url('applicants') class ApplicantsAnonTab(ApplicantsAuthTab): """Applicants tab in primary navigation. Display tab only for anonymous. Authenticated users can call the form from the user navigation bar. """ grok.require('waeup.Anonymous') tab_title = _(u'Application') # Also zope.manager has role Anonymous. # To avoid displaying this tab, we have to check the principal id too. @property def link_target(self): if self.request.principal.id == 'zope.anybody': return self.view.application_url('applicants') return class MyApplicationDataTab(PrimaryStudentNavTab): """MyData-tab in primary navigation. """ grok.order(3) grok.require('waeup.viewMyApplicationDataTab') pnav = 3 tab_title = u'My Data' @property def link_target(self): try: container, application_number = self.request.principal.id.split('_') except ValueError: return rel_link = '/applicants/%s/%s' % (container, application_number) return self.view.application_url() + rel_link class ManageApplicantsRootActionButton(ManageActionButton): grok.context(IApplicantsRoot) grok.view(ApplicantsRootPage) grok.require('waeup.manageApplication') text = 'Manage application section' class ApplicantsContainerManageActionButton(ManageActionButton): grok.order(1) grok.context(IApplicantsContainer) grok.view(ApplicantsContainerPage) grok.require('waeup.manageApplication') text = 'Manage applicants container' class ApplicantRegisterActionButton(ManageActionButton): grok.order(2) grok.context(IApplicantsContainer) grok.view(ApplicantsContainerPage) grok.require('waeup.Anonymous') icon = 'actionicon_login.png' text = 'Register for application' target = 'register' class ApplicantViewActionButton(ManageActionButton): grok.context(IApplicant) grok.view(ApplicantManageFormPage) grok.require('waeup.viewApplication') icon = 'actionicon_view.png' text = 'View application record' target = 'index' class ApplicantManageActionButton(ManageActionButton): grok.order(1) grok.context(IApplicant) grok.view(ApplicantDisplayFormPage) grok.require('waeup.manageApplication') text = 'Manage application record' target = 'manage' class ApplicantEditActionButton(ManageActionButton): grok.order(2) grok.context(IApplicant) grok.view(ApplicantDisplayFormPage) grok.require('waeup.handleApplication') text = 'Edit application record' target ='edit' @property def target_url(self): """Get a URL to the target... """ if self.context.locked: return return self.view.url(self.view.context, self.target) class PDFActionButton(ManageActionButton): grok.order(3) grok.context(IApplicant) grok.require('waeup.viewApplication') icon = 'actionicon_pdf.png' text = 'Download application slip' target = 'application_slip.pdf' class StudentCreateActionButton(ManageActionButton): grok.order(4) grok.context(IApplicant) grok.require('waeup.manageApplication') icon = 'actionicon_entrance.png' text = 'Create student record' target ='createstudent' @property def target_url(self): """Get a URL to the target... """ if IWorkflowState(self.context).getState() != 'admitted': return return self.view.url(self.view.context, self.target) class PaymentReceiptActionButton(ManageActionButton): grok.order(1) grok.context(IApplicantOnlinePayment) grok.view(OnlinePaymentDisplayFormPage) grok.require('waeup.viewApplication') icon = 'actionicon_pdf.png' text = 'Download payment receipt' target = 'payment_receipt.pdf' @property def target_url(self): if self.context.p_state != 'paid': return '' return self.view.url(self.view.context, self.target) class RequestCallbackActionButton(ManageActionButton): grok.order(2) grok.context(IApplicantOnlinePayment) grok.view(OnlinePaymentDisplayFormPage) grok.require('waeup.payApplicant') icon = 'actionicon_call.png' text = 'Request callback' target = 'callback' @property def target_url(self): if self.context.p_state != 'unpaid': return '' return self.view.url(self.view.context, self.target)