Changeset 10692 for main/waeup.kwarapoly/trunk/src/waeup
- Timestamp:
- 4 Nov 2013, 10:57:34 (11 years ago)
- Location:
- main/waeup.kwarapoly/trunk/src/waeup/kwarapoly/students
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
main/waeup.kwarapoly/trunk/src/waeup/kwarapoly/students/browser.py
r10691 r10692 20 20 from zope.component import getUtility 21 21 from hurry.workflow.interfaces import IWorkflowInfo 22 from waeup.kofa.interfaces import ADMITTED 22 from waeup.kofa.interfaces import ADMITTED, IKofaUtils 23 23 from waeup.kofa.browser.layout import UtilityView 24 24 from waeup.kofa.students.interfaces import IStudentsUtils 25 25 from waeup.kofa.widgets.datewidget import FriendlyDatetimeDisplayWidget 26 26 from waeup.kofa.students.browser import ( 27 StartClearancePage, BedTicketAddPage, ExportPDFAdmissionSlipPage) 27 StartClearancePage, BedTicketAddPage, ExportPDFAdmissionSlipPage, 28 StudentBasePDFFormPage) 28 29 from waeup.kwarapoly.students.interfaces import ( 29 ICustomStudent, ICustomStudentBase )30 ICustomStudent, ICustomStudentBase, ICustomStudentStudyLevel) 30 31 from waeup.kwarapoly.interfaces import MessageFactory as _ 31 32 from waeup.kofa.students.workflow import ( … … 37 38 NigeriaExportPDFPaymentSlipPage, 38 39 NigeriaStudentClearanceEditFormPage, 40 NigeriaExportPDFCourseRegistrationSlipPage, 39 41 ) 40 42 … … 129 131 self.context.student, omit_fields=self.omit_fields, 130 132 pre_text=pre_text, post_text=post_text) 133 134 # copied from waeup.aaue 135 class CustomExportPDFCourseRegistrationSlipPage( 136 NigeriaExportPDFCourseRegistrationSlipPage): 137 """Deliver a PDF slip of the context. 138 """ 139 grok.context(ICustomStudentStudyLevel) 140 form_fields = grok.AutoFields(ICustomStudentStudyLevel).omit( 141 'level_session', 'level_verdict', 142 'validated_by', 'validation_date', 'gpa') 143 144 omit_fields = ('password', 'suspended', 'suspended_comment', 145 'phone', 'adm_code', 'sex', 'email', 'date_of_birth', 146 'department', 'current_mode') 147 148 @property 149 def title(self): 150 portal_language = getUtility(IKofaUtils).PORTAL_LANGUAGE 151 return translate(_('Credits Registered'), 'waeup.kofa', 152 target_language=portal_language) 153 154 def _signatures(self): 155 return ( 156 [('I have selected the course on the advise of my Head of ' 157 'Department. <br>', _('Student\'s Signature'), '<br>')], 158 [('This student has satisfied the department\'s requirements. ' 159 'I recommend to approve the course registration. <br>', 160 _('Head of Department\'s Signature'), '<br>')], 161 [('' , _('Principal Assistant Registrar\'s Signature'), '<br>')], 162 [('', _('Director\'s Signature'))] 163 ) 164 165 def render(self): 166 portal_language = getUtility(IKofaUtils).PORTAL_LANGUAGE 167 Sem = translate('Sem.', 'waeup.kofa', target_language=portal_language) 168 Code = translate('Code', 'waeup.kofa', target_language=portal_language) 169 Title = translate('Title', 'waeup.kofa', target_language=portal_language) 170 Cred = translate('Cred.', 'waeup.kofa', target_language=portal_language) 171 Score = translate('Score', 'waeup.kofa', target_language=portal_language) 172 Grade = translate('Grade', 'waeup.kofa', target_language=portal_language) 173 Signature = translate(_('HOD\'s Signature'), 'waeup.kwarapoly', 174 target_language=portal_language) 175 studentview = StudentBasePDFFormPage(self.context.student, 176 self.request, self.omit_fields) 177 students_utils = getUtility(IStudentsUtils) 178 179 tabledata = [] 180 tableheader = [] 181 contenttitle = [] 182 for i in range(1,7): 183 tabledata.append(sorted( 184 [value for value in self.context.values() if value.semester == i], 185 key=lambda value: str(value.semester) + value.code)) 186 tableheader.append([(Code,'code', 2.0), 187 (Title,'title', 7), 188 (Cred, 'credits', 1.5), 189 (Score, 'score', 1.4), 190 (Grade, 'grade', 1.4), 191 (Signature, 'dummy', 3), 192 ]) 193 if len(self.label.split('\n')) == 3: 194 topMargin = 1.9 195 elif len(self.label.split('\n')) == 2: 196 topMargin = 1.7 197 else: 198 topMargin = 1.5 199 return students_utils.renderPDF( 200 self, 'course_registration_slip.pdf', 201 self.context.student, studentview, 202 tableheader=tableheader, 203 tabledata=tabledata, 204 signatures=self._signatures(), 205 topMargin=topMargin, 206 omit_fields=self.omit_fields 207 ) -
main/waeup.kwarapoly/trunk/src/waeup/kwarapoly/students/tests/test_browser.py
r10691 r10692 32 32 from waeup.kofa.interfaces import ( 33 33 IExtFileStore, IFileStoreNameChooser) 34 from waeup.kofa.browser.tests.test_pdf import samples_dir 34 35 from waeup.kofa.students.interfaces import IStudentsUtils 35 36 from waeup.kwarapoly.testing import FunctionalLayer … … 348 349 349 350 def test_pdf_slips(self): 350 IWorkflowState(self.student).setState('school fee paid')351 351 # Login 352 352 self.browser.open(self.login_path) … … 354 354 self.browser.getControl(name="form.password").value = 'spwd' 355 355 self.browser.getControl("Login").click() 356 # admission slip 357 IWorkflowState(self.student).setState('school fee paid') 356 358 self.browser.open(self.student_path) 357 359 self.browser.getLink("Download admission letter").click() … … 359 361 self.assertEqual(self.browser.headers['Content-Type'], 360 362 'application/pdf') 363 path = os.path.join(samples_dir(), 'admission_slip.pdf') 364 open(path, 'wb').write(self.browser.contents) 365 print "Sample PDF admission_slip_slip.pdf written to %s" % path 361 366 self.browser.open(self.student_path) 362 367 self.assertRaises( … … 364 369 self.browser.open(self.student_path, 'admission_notification.pdf') 365 370 self.assertFalse('Not allowed' in self.browser.contents) 366 371 # admission notification 367 372 IWorkflowState(self.student).setState('cleared') 368 373 self.browser.open(self.student_path) … … 371 376 self.assertEqual(self.browser.headers['Content-Type'], 372 377 'application/pdf') 378 path = os.path.join(samples_dir(), 'admission_notification.pdf') 379 open(path, 'wb').write(self.browser.contents) 380 print "Sample PDF admission_notification.pdf written to %s" % path 373 381 self.browser.open(self.student_path) 374 382 self.assertRaises( … … 377 385 self.assertFalse('Not allowed' in self.browser.contents) 378 386 return 387 388 def test_course_registration_pdf_slip(self): 389 # Student cant login if their password is not set 390 IWorkflowState(self.student).setState('school fee paid') 391 self.browser.open(self.login_path) 392 self.browser.getControl(name="form.login").value = self.student_id 393 self.browser.getControl(name="form.password").value = 'spwd' 394 self.browser.getControl("Login").click() 395 self.browser.getLink("Study Course").click() 396 self.browser.getLink("Add course list").click() 397 self.assertMatches('...Add current level 100 (Year 1)...', 398 self.browser.contents) 399 self.browser.getControl("Create course list now").click() 400 # A level with one course ticket was created 401 self.browser.getLink("100").click() 402 self.browser.getLink("Download course registration slip").click() 403 self.assertEqual(self.browser.headers['Status'], '200 Ok') 404 self.assertEqual(self.browser.headers['Content-Type'], 405 'application/pdf') 406 path = os.path.join(samples_dir(), 'course_registration_slip.pdf') 407 open(path, 'wb').write(self.browser.contents) 408 print "Sample PDF course_registration_slip.pdf written to %s" % path 409 return
Note: See TracChangeset for help on using the changeset viewer.