source: main/waeup.sirp/trunk/src/waeup/sirp/applicants/viewlets.py @ 7693

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

Import message factory from interfaces

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