1 | ## $Id: viewlets.py 15330 2019-02-14 15:55:27Z 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 | |
---|
19 | import grok |
---|
20 | from zope.component import getUtility |
---|
21 | from waeup.kofa.interfaces import REGISTERED |
---|
22 | from waeup.kofa.students.interfaces import ( |
---|
23 | IStudent, IStudentsUtils, IStudentStudyLevel) |
---|
24 | from waeup.kofa.students.workflow import PAID |
---|
25 | from waeup.kofa.students.viewlets import ( |
---|
26 | AddPreviousPaymentActionButton, AddBalancePaymentActionButton, |
---|
27 | ManageActionButton, StudentBaseDisplayFormPage, |
---|
28 | StudentPassportActionButton, |
---|
29 | StudyCourseTranscriptActionButton, |
---|
30 | TranscriptSlipActionButton, |
---|
31 | DownloadCSVFileActionButton, |
---|
32 | DownloadTicketOverviewActionButton) |
---|
33 | from waeup.kofa.students.browser import StudyLevelDisplayFormPage |
---|
34 | |
---|
35 | from waeup.aaue.students.interfaces import ( |
---|
36 | ICustomStudent, ICustomStudentStudyLevel) |
---|
37 | from waeup.aaue.students.browser import CustomStudentPersonalDisplayFormPage |
---|
38 | from waeup.aaue.interfaces import MessageFactory as _ |
---|
39 | |
---|
40 | #class AddPreviousPaymentActionButton(AddPreviousPaymentActionButton): |
---|
41 | |
---|
42 | # @property |
---|
43 | # def target_url(self): |
---|
44 | # return '' |
---|
45 | |
---|
46 | #class AddBalancePaymentActionButton(AddBalancePaymentActionButton): |
---|
47 | |
---|
48 | # @property |
---|
49 | # def target_url(self): |
---|
50 | # return '' |
---|
51 | |
---|
52 | class GetMatricNumberActionButton(ManageActionButton): |
---|
53 | grok.order(10) |
---|
54 | grok.context(IStudent) |
---|
55 | grok.view(StudentBaseDisplayFormPage) |
---|
56 | grok.require('waeup.viewStudent') |
---|
57 | #grok.require('waeup.manageStudent') |
---|
58 | icon = 'actionicon_count.png' |
---|
59 | text = _('Get Matriculation Number') |
---|
60 | |
---|
61 | @property |
---|
62 | def target_url(self): |
---|
63 | students_utils = getUtility(IStudentsUtils) |
---|
64 | if self.context.matric_number: |
---|
65 | return '' |
---|
66 | error, matric_number = students_utils.constructMatricNumber( |
---|
67 | self.context) |
---|
68 | if error: |
---|
69 | return '' |
---|
70 | return self.view.url(self.view.context, 'get_matric_number') |
---|
71 | |
---|
72 | class MatricNumberSlipActionButton(ManageActionButton): |
---|
73 | grok.order(10) |
---|
74 | grok.context(IStudent) |
---|
75 | grok.view(StudentBaseDisplayFormPage) |
---|
76 | grok.require('waeup.viewStudent') |
---|
77 | icon = 'actionicon_pdf.png' |
---|
78 | text = _('Download matriculation number slip') |
---|
79 | target = 'matric_number_slip.pdf' |
---|
80 | |
---|
81 | @property |
---|
82 | def target_url(self): |
---|
83 | if self.context.state not in (PAID,) or not self.context.is_fresh \ |
---|
84 | or not self.context.matric_number: |
---|
85 | return '' |
---|
86 | return self.view.url(self.view.context, self.target) |
---|
87 | |
---|
88 | class CourseRegistrationSlipActionButton(ManageActionButton): |
---|
89 | grok.order(5) |
---|
90 | grok.context(ICustomStudentStudyLevel) |
---|
91 | grok.view(StudyLevelDisplayFormPage) |
---|
92 | grok.require('waeup.viewStudent') |
---|
93 | icon = 'actionicon_pdf.png' |
---|
94 | text = _('Download course registration slip') |
---|
95 | target = 'course_registration_slip.pdf' |
---|
96 | |
---|
97 | @property |
---|
98 | def target_url(self): |
---|
99 | is_current = self.context.__parent__.is_current |
---|
100 | if not is_current: |
---|
101 | return '' |
---|
102 | if self.context.student.state != REGISTERED \ |
---|
103 | and self.context.student.current_level == self.context.level: |
---|
104 | return '' |
---|
105 | return self.view.url(self.view.context, self.target) |
---|
106 | |
---|
107 | class ExaminationScheduleSlipActionButton(ManageActionButton): |
---|
108 | grok.order(10) |
---|
109 | grok.context(ICustomStudent) |
---|
110 | grok.view(StudentBaseDisplayFormPage) |
---|
111 | grok.require('waeup.viewStudent') |
---|
112 | icon = 'actionicon_pdf.png' |
---|
113 | text = _('Download examination schedule slip') |
---|
114 | target = 'examination_schedule_slip.pdf' |
---|
115 | |
---|
116 | @property |
---|
117 | def target_url(self): |
---|
118 | if self.context.flash_notice \ |
---|
119 | and 'exam' in self.context.flash_notice.lower(): |
---|
120 | return self.view.url(self.view.context, self.target) |
---|
121 | return False |
---|
122 | |
---|
123 | class PersonalDataSlipActionButton(ManageActionButton): |
---|
124 | grok.order(3) |
---|
125 | grok.context(ICustomStudent) |
---|
126 | grok.view(CustomStudentPersonalDisplayFormPage) |
---|
127 | grok.require('waeup.viewStudent') |
---|
128 | icon = 'actionicon_pdf.png' |
---|
129 | text = _('Download personal data slip') |
---|
130 | target = 'personal_data_slip.pdf' |
---|
131 | |
---|
132 | @property |
---|
133 | def target_url(self): |
---|
134 | if not self.context.father_name: |
---|
135 | return '' |
---|
136 | return self.view.url(self.view.context, self.target) |
---|
137 | |
---|
138 | class StudentPassportActionButton(StudentPassportActionButton): |
---|
139 | """Inherit from same class in base package, not from kofacustom.nigeria |
---|
140 | which requires that no application slip exists. |
---|
141 | """ |
---|
142 | |
---|
143 | class CustomStudyCourseTranscriptActionButton(StudyCourseTranscriptActionButton): |
---|
144 | #grok.require('waeup.viewStudent') |
---|
145 | grok.name('transcript') |
---|
146 | |
---|
147 | class CustomTranscriptSlipActionButton(TranscriptSlipActionButton): |
---|
148 | #grok.require('waeup.viewStudent') |
---|
149 | grok.name('transcript_slip') |
---|
150 | |
---|
151 | class CustomDownloadCSVFileActionButton(DownloadCSVFileActionButton): |
---|
152 | """ 'Download csv file' button for courses. |
---|
153 | """ |
---|
154 | |
---|
155 | @property |
---|
156 | def target_url(self): |
---|
157 | if self.view.__name__ == 'edit_prev_scores': |
---|
158 | return self.view.url(self.view.context, 'download_prev_scores') |
---|
159 | return self.view.url(self.view.context, 'download_scores') |
---|
160 | |
---|
161 | class CustomDownloadTicketOverviewActionButton( |
---|
162 | DownloadTicketOverviewActionButton): |
---|
163 | """ 'Download ticket overview' button for courses. |
---|
164 | """ |
---|
165 | |
---|
166 | @property |
---|
167 | def target_url(self): |
---|
168 | if self.view.__name__ == 'edit_prev_scores': |
---|
169 | return '' |
---|
170 | return self.view.url(self.view.context, 'coursetickets.pdf') |
---|
171 | |
---|
172 | class StudyLevelRepairActionButton(ManageActionButton): |
---|
173 | grok.order(2) |
---|
174 | grok.context(IStudentStudyLevel) |
---|
175 | grok.view(StudyLevelDisplayFormPage) |
---|
176 | grok.require('waeup.editStudyLevel') |
---|
177 | text = _('Repair course list') |
---|
178 | target = 'repair' |
---|
179 | icon = 'actionicon_repair1.png' |
---|
180 | |
---|
181 | @property |
---|
182 | def target_url(self): |
---|
183 | try: |
---|
184 | studylevel_repair_enabled = grok.getSite()['configuration'][ |
---|
185 | str(self.context.level_session)].studylevel_repair_enabled |
---|
186 | except KeyError: |
---|
187 | return '' |
---|
188 | if not studylevel_repair_enabled: |
---|
189 | return '' |
---|
190 | return self.view.url(self.view.context, self.target) |
---|