Changeset 13623 for main/kofacustom.nigeria/trunk/src
- Timestamp:
- 16 Jan 2016, 18:26:12 (9 years ago)
- Location:
- main/kofacustom.nigeria/trunk/src/kofacustom/nigeria/students
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
main/kofacustom.nigeria/trunk/src/kofacustom/nigeria/students/browser.py
r13620 r13623 22 22 from datetime import datetime 23 23 from waeup.kofa.widgets.datewidget import FriendlyDatetimeDisplayWidget 24 from waeup.kofa.interfaces import IExtFileStore, IObjectHistory 24 from waeup.kofa.interfaces import IExtFileStore, IObjectHistory, IKofaUtils 25 25 from waeup.kofa.browser.layout import action, UtilityView 26 from waeup.kofa.utils.helpers import get_current_principal 26 from waeup.kofa.utils.helpers import get_current_principal, to_timezone 27 27 from waeup.kofa.students.browser import ( 28 28 StudentPersonalDisplayFormPage, StudentPersonalManageFormPage, … … 31 31 ExportPDFClearanceSlip, StudentBaseManageFormPage, 32 32 StudentBaseDisplayFormPage, 33 StudentBasePDFFormPage, 33 34 StudentBaseEditFormPage, StudentPersonalEditFormPage, 34 35 OnlinePaymentDisplayFormPage, OnlinePaymentAddFormPage, … … 314 315 def render(self): 315 316 return 317 318 cleared_note = """ 319 <br /><br /><br /> 320 <strong>Financially cleared on %s by %s.</strong> 321 322 """ 323 324 not_cleared_note = """ 325 <br /><br /><br /> 326 <strong>Not yet financially cleared.</strong> 327 328 """ 329 330 class NigeriaExportPDFBursaryClearancePage(UtilityView, grok.View): 331 """Deliver a PDF bursary clearance slip. 332 """ 333 grok.context(INigeriaStudent) 334 grok.name('bursary_clearance_slip.pdf') 335 grok.require('waeup.viewStudent') 336 prefix = 'form' 337 338 omit_fields = ( 339 'suspended', 'phone', 340 'adm_code', 'suspended_comment', 341 'date_of_birth', 'current_level') 342 343 form_fields = None 344 345 @property 346 def label(self): 347 portal_language = getUtility(IKofaUtils).PORTAL_LANGUAGE 348 return translate(_('Bursary Clearance Slip of'), 349 'waeup.kofa', target_language=portal_language) \ 350 + ' %s' % self.context.display_fullname 351 352 def _sigsInFooter(self): 353 354 isStudent = getattr( 355 self.request.principal, 'user_type', None) == 'student' 356 if isStudent: 357 return () 358 return (_('Date, Student Signature'), 359 _('Date, Bursary Signature'), 360 ) 361 362 @property 363 def note(self): 364 if self.context.financially_cleared_by: 365 tz = getUtility(IKofaUtils).tzinfo 366 try: 367 timestamp = to_timezone( 368 self.context.financial_clearance_date, tz).strftime( 369 "%Y-%m-%d %H:%M:%S") 370 except ValueError: 371 return not_cleared_note 372 return cleared_note % ( 373 timestamp, self.context.financially_cleared_by) 374 return not_cleared_note 375 376 @property 377 def tabletitle(self): 378 portal_language = getUtility(IKofaUtils).PORTAL_LANGUAGE 379 tabletitle = [] 380 tabletitle.append(translate(_('Successful Payments'), 'waeup.kofa', 381 target_language=portal_language)) 382 return tabletitle 383 384 def render(self): 385 portal_language = getUtility(IKofaUtils).PORTAL_LANGUAGE 386 P_ID = translate(_('Payment Id'), 'waeup.kofa', target_language=portal_language) 387 #CD = translate(_('Creation Date'), 'waeup.kofa', target_language=portal_language) 388 PD = translate(_('Payment Date'), 'waeup.kofa', target_language=portal_language) 389 CAT = translate(_('Payment Category'), 'waeup.kofa', target_language=portal_language) 390 ITEM = translate(_('Payment Item'), 'waeup.kofa', target_language=portal_language) 391 AMT = translate(_('Amount (Naira)'), 'waeup.kofa', target_language=portal_language) 392 SSS = translate(_('Payment Session'), 'waeup.kofa', target_language=portal_language) 393 studentview = StudentBasePDFFormPage(self.context.student, 394 self.request, self.omit_fields) 395 students_utils = getUtility(IStudentsUtils) 396 397 tabledata = [] 398 tableheader = [] 399 tabledata.append(sorted( 400 [value for value in self.context['payments'].values() 401 if value.p_state == 'paid'], key=lambda value: value.p_id)) 402 tableheader.append([(P_ID,'p_id', 3), 403 #(CD,'creation_date', 3), 404 (PD,'formatted_p_date', 3), 405 (CAT,'category', 3), 406 (ITEM, 'p_item', 3), 407 (AMT, 'amount_auth', 2), 408 (SSS, 'p_session', 2), 409 ]) 410 return students_utils.renderPDF( 411 self, 'bursary_clearance_slip.pdf', 412 self.context.student, studentview, 413 tableheader=tableheader, 414 tabledata=tabledata, 415 signatures=None, 416 sigs_in_footer=self._sigsInFooter(), 417 omit_fields=self.omit_fields, 418 note=self.note 419 ) -
main/kofacustom.nigeria/trunk/src/kofacustom/nigeria/students/export.py
r12875 r13623 85 85 sorted(iface_names( 86 86 INigeriaStudentOnlinePayment, exclude_attribs=False, 87 omit=['display_item' ]))) + (87 omit=['display_item','formatted_p_date']))) + ( 88 88 'student_id','state','current_session') 89 89 -
main/kofacustom.nigeria/trunk/src/kofacustom/nigeria/students/interfaces.py
r13620 r13623 519 519 """ 520 520 521 formatted_p_date = Attribute("Formatted pyment date") 522 521 523 p_current = schema.Bool( 522 524 title = _(u'Current Session Payment'), -
main/kofacustom.nigeria/trunk/src/kofacustom/nigeria/students/payments.py
r11639 r13623 20 20 """ 21 21 import grok 22 from datetime import datetime 23 from zope.component import getUtility 22 24 from zope.component.interfaces import IFactory 23 25 from zope.interface import implementedBy 26 from waeup.kofa.interfaces import IKofaUtils 24 27 from waeup.kofa.students.interfaces import IStudentNavigation 25 28 from waeup.kofa.students.payments import ( 26 29 StudentOnlinePayment, StudentOnlinePaymentFactory) 27 from waeup.kofa.utils.helpers import attrs_to_fields 30 from waeup.kofa.utils.helpers import attrs_to_fields, to_timezone 28 31 from kofacustom.nigeria.students.interfaces import INigeriaStudentOnlinePayment 29 32 … … 47 50 return self.__parent__.__parent__ 48 51 52 53 @property 54 def formatted_p_date(self): 55 if isinstance(self.payment_date, datetime): 56 tz = getUtility(IKofaUtils).tzinfo 57 try: 58 timestamp = to_timezone( 59 self.payment_date, tz).strftime("%Y-%m-%d %H:%M:%S") 60 except ValueError: 61 return None 62 return timestamp 63 else: 64 return None 65 49 66 NigeriaStudentOnlinePayment = attrs_to_fields(NigeriaStudentOnlinePayment, 50 67 omit=['display_item']) -
main/kofacustom.nigeria/trunk/src/kofacustom/nigeria/students/tests/test_browser.py
r13620 r13623 19 19 import shutil 20 20 import tempfile 21 from time import time 21 22 from datetime import datetime, timedelta 22 23 from StringIO import StringIO … … 35 36 from waeup.kofa.students.batching import StudentProcessor 36 37 from waeup.kofa.students.interfaces import IStudentsUtils 38 from waeup.kofa.browser.tests.test_pdf import samples_dir 37 39 from kofacustom.nigeria.students.batching import NigeriaStudentProcessor 38 40 from kofacustom.nigeria.testing import FunctionalLayer … … 417 419 '...2016-01-16 15:50:48 WAT - Financial clearance withdrawn by Carlo Pitter...', 418 420 self.browser.contents) 421 422 def test_bursary_pdf_slip(self): 423 payment1 = createObject(u'waeup.StudentOnlinePayment') 424 timestamp = ("%d" % int(time()*10000))[1:] 425 payment1.p_id = "p%s" % timestamp 426 payment1.p_category = 'schoolfee' 427 payment1.p_item = u'My School Fee' 428 payment1.p_session = 2015 429 payment1.p_level = 100 430 payment1.p_current = True 431 payment1.amount_auth = 23456.9 432 payment1.approve() 433 payment2 = createObject(u'waeup.StudentOnlinePayment') 434 timestamp = ("%d" % int(time()*10000))[1:] 435 payment2.p_id = "p%s" % timestamp 436 payment2.p_category = 'clearance' 437 payment2.p_item = u'My Clearance Fee' 438 payment2.p_session = 2015 439 payment2.p_level = 100 440 payment2.p_current = True 441 payment2.amount_auth = 5678.6 442 payment2.approve() 443 self.student['payments'][payment1.p_id] = payment1 444 self.student['payments'][payment2.p_id] = payment2 445 self.browser.addHeader('Authorization', 'Basic mgr:mgrpw') 446 self.browser.open(self.student_path + '/clear_financially') 447 self.browser.getLink("Download bursary clearance slip").click() 448 self.assertEqual(self.browser.headers['Status'], '200 Ok') 449 self.assertEqual(self.browser.headers['Content-Type'], 450 'application/pdf') 451 path = os.path.join(samples_dir(), 'bursary_clearance_slip.pdf') 452 open(path, 'wb').write(self.browser.contents) 453 print "Sample PDF bursary_clearance_slip.pdf written to %s" % path 454 return -
main/kofacustom.nigeria/trunk/src/kofacustom/nigeria/students/viewlets.py
r13620 r13623 70 70 return self.view.url(self.view.context, self.target) 71 71 72 class BursaryClearanceSlipActionButton(ManageActionButton): 73 grok.order(12) 74 grok.context(INigeriaStudent) 75 grok.view(NigeriaStudentBaseDisplayFormPage) 76 grok.require('waeup.viewStudent') 77 text = _('Download bursary clearance slip') 78 target = 'bursary_clearance_slip.pdf' 79 icon = 'actionicon_pdf.png' 72 80 73 81 # Acceptance Letter
Note: See TracChangeset for help on using the changeset viewer.