Changeset 8411 for main/waeup.kofa/trunk/src/waeup/kofa/students
- Timestamp:
- 10 May 2012, 16:38:15 (13 years ago)
- Location:
- main/waeup.kofa/trunk/src/waeup/kofa/students
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
main/waeup.kofa/trunk/src/waeup/kofa/students/export.py
r8400 r8411 21 21 from zope.catalog.interfaces import ICatalog 22 22 from zope.component import queryUtility 23 from waeup.kofa.interfaces import ICSVExporter24 23 from waeup.kofa.interfaces import MessageFactory as _ 25 24 from waeup.kofa.students.interfaces import ( 26 25 IStudent, IStudentStudyCourse, IStudentStudyLevel, ICourseTicket, 27 IStudentOnlinePayment )26 IStudentOnlinePayment, ICSVStudentExporter) 28 27 from waeup.kofa.utils.batching import ExporterBase 29 28 from waeup.kofa.utils.helpers import iface_names … … 37 36 """Exporter for Students. 38 37 """ 39 grok.implements(ICSVExporter) 38 grok.implements(ICSVStudentExporter) 39 grok.provides(ICSVStudentExporter) 40 40 grok.name('students') 41 41 … … 69 69 return self.export(students, filepath) 70 70 71 def export_student(self, student, filepath=None): 72 return self.export([student], filepath=filepath) 73 71 74 class StudentStudyCourseExporter(grok.GlobalUtility, ExporterBase): 72 75 """Exporter for StudentStudyCourses. 73 76 """ 74 grok.implements(ICSVExporter) 77 grok.implements(ICSVStudentExporter) 78 grok.provides(ICSVStudentExporter) 75 79 grok.name('studentstudycourses') 76 80 … … 120 124 return self.export(study_courses, filepath) 121 125 126 def export_student(self, student, filepath=None): 127 if 'studycourse' in student.keys(): 128 return self.export([student['studycourse']], filepath=filepath) 129 return self.export([], filepath=filepath) 130 131 122 132 class StudentStudyLevelExporter(grok.GlobalUtility, ExporterBase): 123 133 """Exporter for StudentStudyLevels. 124 134 """ 125 grok.implements(ICSVExporter) 135 grok.implements(ICSVStudentExporter) 136 grok.provides(ICSVStudentExporter) 126 137 grok.name('studentstudylevels') 127 138 … … 181 192 return self.export(levels, filepath) 182 193 194 def export_student(self, student, filepath=None): 195 if 'studycourse' in student.keys(): 196 return self.export(student['studycourse'].values(), 197 filepath=filepath) 198 return self.export([], filepath=filepath) 199 183 200 class CourseTicketExporter(grok.GlobalUtility, ExporterBase): 184 201 """Exporter for CourseTickets. 185 202 """ 186 grok.implements(ICSVExporter) 203 grok.implements(ICSVStudentExporter) 204 grok.provides(ICSVStudentExporter) 187 205 grok.name('coursetickets') 188 206 … … 242 260 return self.export(tickets, filepath) 243 261 262 def export_student(self, student, filepath=None): 263 if 'studycourse' not in student.keys(): 264 return self.export([], filepath=filepath) 265 levels = student['studycourse'].values() 266 tickets = [] 267 for level in levels: 268 for ticket in level.values(): 269 tickets.append(ticket) 270 return self.export(tickets, filepath=filepath) 271 244 272 class PaymentsExporter(grok.GlobalUtility, ExporterBase): 245 273 """Exporter for OnlinePayment instances. 246 274 """ 247 grok.implements(ICSVExporter) 275 grok.implements(ICSVStudentExporter) 276 grok.provides(ICSVStudentExporter) 248 277 grok.name('studentpayments') 249 278 … … 295 324 payments.append(payment) 296 325 return self.export(payments, filepath) 326 327 def export_student(self, student, filepath=None): 328 if not 'payments' in student.keys(): 329 return self.export([], filepath=filepath) 330 return self.export(student['payments'].values(), filepath=filepath) -
main/waeup.kofa/trunk/src/waeup/kofa/students/student.py
r8403 r8411 32 32 from waeup.kofa.interfaces import ( 33 33 IObjectHistory, IUserAccount, IFileStoreNameChooser, IFileStoreHandler, 34 IKofaUtils, CLEARANCE, registration_states_vocab, IExtFileStore, 35 ICSVExporter) 34 IKofaUtils, CLEARANCE, registration_states_vocab, IExtFileStore,) 36 35 from waeup.kofa.students.accommodation import StudentAccommodation 37 36 from waeup.kofa.students.export import EXPORTER_NAMES 38 from waeup.kofa.students.interfaces import IStudent, IStudentNavigation 37 from waeup.kofa.students.interfaces import ( 38 IStudent, IStudentNavigation, ICSVStudentExporter) 39 39 from waeup.kofa.students.payments import StudentPaymentsContainer 40 40 from waeup.kofa.students.utils import generate_student_id … … 220 220 """ 221 221 for name in EXPORTER_NAMES: 222 exporter = getUtility(ICSV Exporter, name=name)223 csv_data = exporter.export ([student])222 exporter = getUtility(ICSVStudentExporter, name=name) 223 csv_data = exporter.export_student(student) 224 224 csv_data = csv_data.split('\r\n') 225 225 -
main/waeup.kofa/trunk/src/waeup/kofa/students/tests/test_batching.py
r8354 r8411 34 34 StudentStudyLevelProcessor, CourseTicketProcessor, 35 35 StudentOnlinePaymentProcessor, StudentVerdictProcessor) 36 from waeup.kofa.students.payments import StudentOnlinePayment 36 37 from waeup.kofa.students.student import Student 37 38 from waeup.kofa.students.studylevel import StudentStudyLevel, CourseTicket … … 208 209 ticket.semester = 2 209 210 study_level.addCourseTicket(ticket) 210 211 self.add_payment(student) 211 212 return student 213 214 def add_payment(self, student): 215 # get a payment with all fields set 216 payment = StudentOnlinePayment() 217 payment.creation_date = datetime.datetime(2012, 4, 1, 13, 12, 1) 218 payment.p_id = 'my-id' 219 payment.ac = u'666' 220 payment.p_item = u'p-item' 221 payment.p_level = 100 222 payment.p_session = 2012 223 payment.payment_date = datetime.datetime(2012, 4, 1, 14, 12, 1) 224 payment.r_amount_approved = 12.12 225 payment.r_code = u'r-code' 226 # XXX: there is no addPayment method to give predictable names 227 student['payments']['my-payment'] = payment 228 return payment 229 212 230 213 231 -
main/waeup.kofa/trunk/src/waeup/kofa/students/tests/test_export.py
r8402 r8411 72 72 return 73 73 74 def test_export_student(self): 75 # we can export a single student 76 self.setup_student(self.student) 77 exporter = StudentsExporter() 78 exporter.export_student(self.student, self.outfile) 79 result = open(self.outfile, 'rb').read() 80 self.assertEqual( 81 result, 82 'adm_code,clearance_locked,clr_code,date_of_birth,email,employer,' 83 'firstname,lastname,matric_number,middlename,nationality,' 84 'perm_address,phone,reg_number,sex,student_id\r\n' 85 86 'my adm code,0,my clr code,1981-02-04#,anna@sample.com,,Anna,' 87 'Tester,M123456,M.,NG,"Studentroad 21\nLagos 123456\n",' 88 '+234-123-12345,123456,f,A111111\r\n' 89 ) 90 return 91 92 74 93 class StudentStudyCourseExporterTest(StudentImportExportSetup): 75 94 … … 142 161 return 143 162 163 def test_export_student(self): 164 # we can export studycourse of a certain student 165 self.setup_student(self.student) 166 exporter = StudentStudyCourseExporter() 167 exporter.export_student(self.student, self.outfile) 168 result = open(self.outfile, 'rb').read() 169 self.assertEqual( 170 result, 171 'certificate,current_level,current_session,current_verdict,' 172 'entry_mode,entry_session,previous_verdict\r\n' 173 174 'CERT1,200,2012,0,ug_ft,2010,0\r\n' 175 ) 176 return 177 144 178 class StudentStudyLevelExporterTest(StudentImportExportSetup): 145 179 … … 207 241 return 208 242 243 def test_export_student(self): 244 # we can really export study levels of a certain student 245 self.setup_student(self.student) 246 exporter = StudentStudyLevelExporter() 247 exporter.export_student(self.student, self.outfile) 248 result = open(self.outfile, 'rb').read() 249 self.assertEqual( 250 result, 251 'level,level_session,level_verdict,matric_number,reg_number\r\n' 252 '100,2012,A,M123456,123456\r\n' 253 ) 254 return 255 209 256 class CourseTicketExporterTest(StudentImportExportSetup): 210 257 … … 276 323 return 277 324 325 def test_export_student(self): 326 # we can really export all course tickets of a certain student 327 self.setup_student(self.student) 328 exporter = CourseTicketExporter() 329 exporter.export_student(self.student, self.outfile) 330 result = open(self.outfile, 'rb').read() 331 self.assertEqual( 332 result, 333 'automatic,carry_over,code,credits,dcode,fcode,level,mandatory,' 334 'matric_number,passmark,reg_number,score,semester,title\r\n' 335 '1,1,CRS1,100,DEP1,FAC1,100,0,M123456,100,123456,0,2,Course 1\r\n' 336 ) 337 return 338 278 339 class PaymentsExporterTest(StudentImportExportSetup): 279 340 … … 284 345 self.setup_for_export() 285 346 return 286 287 def get_payment(self):288 # get a payment with all fields set289 payment = StudentOnlinePayment()290 payment.creation_date = datetime.datetime(2012, 4, 1, 13, 12, 1)291 payment.p_id = 'my-id'292 payment.ac = u'666'293 payment.p_item = u'p-item'294 payment.p_level = 100295 payment.p_session = 2012296 payment.payment_date = datetime.datetime(2012, 4, 1, 14, 12, 1)297 payment.r_amount_approved = 12.12298 payment.r_code = u'r-code'299 # XXX: there is no addPayment method to give predictable names300 self.student['payments']['my-payment'] = payment301 return payment302 347 303 348 def test_ifaces(self): … … 335 380 # set values we can expect in export file 336 381 self.setup_student(self.student) 337 payment = self. get_payment()382 payment = self.student['payments']['my-payment'] 338 383 exporter = PaymentsExporter() 339 384 exporter.export([payment], self.outfile) … … 355 400 # set values we can expect in export file 356 401 self.setup_student(self.student) 357 self.get_payment() # adds new payment to student358 402 exporter = PaymentsExporter() 359 403 exporter.export_all(self.app, self.outfile) … … 370 414 ) 371 415 return 416 417 def test_export_student(self): 418 # we can really export all payments of a certain student 419 # set values we can expect in export file 420 self.setup_student(self.student) 421 exporter = PaymentsExporter() 422 exporter.export_student(self.student, self.outfile) 423 result = open(self.outfile, 'rb').read() 424 self.assertEqual( 425 result, 426 'ac,amount_auth,creation_date,matric_number,p_category,p_id,' 427 'p_item,p_level,p_session,p_state,payment_date,r_amount_approved,' 428 'r_code,reg_number\r\n' 429 430 '666,0.0,2012-04-01 13:12:01,M123456,schoolfee,my-id,' 431 'p-item,100,2012,unpaid,2012-04-01 14:12:01,12.12,' 432 'r-code,123456\r\n' 433 ) 434 return
Note: See TracChangeset for help on using the changeset viewer.