Changeset 13894 for main/waeup.kofa/trunk/src/waeup/kofa/students
- Timestamp:
- 8 Jun 2016, 15:48:51 (9 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/browser.py
r13874 r13894 3081 3081 3082 3082 class EditScoresPage(KofaPage): 3083 """Page that filters and lists students.3083 """Page that allows to edit batches of scores. 3084 3084 """ 3085 3085 grok.context(ICourse) … … 3156 3156 type="danger") 3157 3157 return 3158 3159 class DownloadScoresView(UtilityView, grok.View): 3160 """View that exports scores. 3161 """ 3162 grok.context(ICourse) 3163 grok.require('waeup.editScores') 3164 grok.name('download_scores') 3165 redirect_target = '@@export' 3166 3167 def update(self): 3168 ob_class = self.__implemented__.__name__.replace('waeup.kofa.','') 3169 self.current_academic_session = grok.getSite()[ 3170 'configuration'].current_academic_session 3171 if self.context.__parent__.__parent__.score_editing_disabled: 3172 self.flash(_('Score editing disabled.'), type="warning") 3173 self.redirect(self.url(self.context)) 3174 return 3175 if not self.current_academic_session: 3176 self.flash(_('Current academic session not set.'), type="warning") 3177 self.redirect(self.url(self.context)) 3178 return 3179 site = grok.getSite() 3180 exporter = getUtility(ICSVExporter, name='lecturer') 3181 self.csv = exporter.export_filtered(site, filepath=None, 3182 catalog='coursetickets', 3183 session=self.current_academic_session, 3184 level=None, 3185 code=self.context.code) 3186 return 3187 3188 def render(self): 3189 filename = 'results_%s_%s.csv' % ( 3190 self.context.code, self.current_academic_session) 3191 self.response.setHeader( 3192 'Content-Type', 'text/csv; charset=UTF-8') 3193 self.response.setHeader( 3194 'Content-Disposition:', 'attachment; filename="%s' % filename) 3195 return self.csv 3158 3196 3159 3197 class ExportJobContainerOverview(KofaPage): … … 3430 3468 3431 3469 def _set_exporter_values(self): 3432 # We provide only the 'lecturer' exporter but can add more. 3470 # We provide only the 'coursetickets' and 'lecturer' exporter 3471 # but can add more. 3433 3472 exporters = [] 3434 for name in (' lecturer',):3473 for name in ('coursetickets', 'lecturer'): 3435 3474 util = getUtility(ICSVExporter, name=name) 3436 3475 exporters.append((util.title, name),) -
main/waeup.kofa/trunk/src/waeup/kofa/students/export.py
r13885 r13894 84 84 continue 85 85 tickets.append(ticket) 86 return tickets 87 88 def get_tickets_for_lecturer(students, **kw): 89 """Get course tickets of `students`. 90 Filter course tickets which belong to this course code and 91 which are editable by lecturers. 92 """ 93 tickets = [] 94 code = kw.get('code', None) 95 level_session = kw.get('session', None) 96 level = kw.get('level', None) 97 for level_obj in get_levels(students): 98 for ticket in level_obj.values(): 99 if ticket.code != code: 100 continue 101 if not ticket.editable_by_lecturer: 102 continue 103 if level is not None: 104 level = int(level) 105 if level_obj.level in (10, 999, None) \ 106 and int(level) != level_obj.level: 107 continue 108 if level_obj.level not in range(level, level+100, 10): 109 continue 110 if level_session is not None and \ 111 int(level_session) != level_obj.level_session: 112 continue 113 tickets.append(ticket) 86 114 return tickets 87 115 … … 349 377 value, name, context=context) 350 378 351 class DataForLecturerExporter( CourseTicketExporter):379 class DataForLecturerExporter(grok.GlobalUtility, StudentExporterBase): 352 380 """ 353 381 """ 354 382 grok.name('lecturer') 355 383 356 fields = ('matric_number', ' reg_number', 'student_id', 'display_fullname',384 fields = ('matric_number', 'student_id', 'display_fullname', 357 385 'level', 'code', 'level_session', 'score') 358 386 359 387 title = _(u'Data for Lecturer') 388 389 def filter_func(self, x, **kw): 390 return get_tickets_for_lecturer(x, **kw) 360 391 361 392 def mangle_value(self, value, name, context=None): … … 370 401 value = getattr(student, name, None) 371 402 return super( 372 CourseTicketExporter, self).mangle_value(403 DataForLecturerExporter, self).mangle_value( 373 404 value, name, context=context) 374 405 -
main/waeup.kofa/trunk/src/waeup/kofa/students/reports/level_report.py
r13879 r13894 190 190 pdf_data.append(Spacer(1, 40)) 191 191 signatures = [ 192 translate(_(' Ag.Head of Department')),192 translate(_('Head of Department')), 193 193 translate(_('Dean of Faculty'))] 194 194 signaturetables = get_signature_tables(signatures, landscape=True) -
main/waeup.kofa/trunk/src/waeup/kofa/students/tests/test_browser.py
r13885 r13894 3806 3806 studylevel.level = 100 3807 3807 studylevel.level_session = 2004 3808 IWorkflowState(self.student).setState('courses validated') 3808 3809 self.student['studycourse'].addStudentStudyLevel( 3809 3810 self.certificate,studylevel) … … 3834 3835 # ... and contains the course ticket COURSE1 3835 3836 self.assertEqual(self.browser.contents, 3836 'matric_number, reg_number,student_id,display_fullname,level,code,'3837 'level_session,score\r\n234, 123,K1000000,Anna Tester,'3837 'matric_number,student_id,display_fullname,level,code,' 3838 'level_session,score\r\n234,K1000000,Anna Tester,' 3838 3839 '100,COURSE1,2004,\r\n') 3839 3840 self.assertEqual(len(self.app['datacenter'].running_exports), 1) … … 3861 3862 '- discarded: job_id=%s' % job_id in logcontent 3862 3863 ) 3864 3865 def test_course_download_lecturer(self): 3866 # We add study level 100 to the student's studycourse 3867 studylevel = StudentStudyLevel() 3868 studylevel.level = 100 3869 studylevel.level_session = 2004 3870 IWorkflowState(self.student).setState('courses validated') 3871 self.student['studycourse'].addStudentStudyLevel( 3872 self.certificate,studylevel) 3873 course1_path = 'http://localhost/app/faculties/fac1/dep1/courses/COURSE1' 3874 # Create lecturer 3875 self.app['users'].addUser('mrlecturer', 'mrlecturersecret') 3876 self.app['users']['mrlecturer'].email = 'mrlecturer@foo.ng' 3877 self.app['users']['mrlecturer'].title = 'Carlo Intelligent' 3878 prmglobal = IPrincipalRoleManager(self.course) 3879 prmglobal.assignRoleToPrincipal('waeup.local.Lecturer', 'mrlecturer') 3880 # Login as lecturer 3881 self.browser.open(self.login_path) 3882 self.browser.getControl(name="form.login").value = 'mrlecturer' 3883 self.browser.getControl(name="form.password").value = 'mrlecturersecret' 3884 self.browser.getControl("Login").click() 3885 self.assertMatches('...You logged in...', self.browser.contents) 3886 self.browser.open(course1_path) 3887 self.assertFalse('Export' in self.browser.contents) 3888 self.browser.getLink("Update scores").click() 3889 self.assertTrue('Current academic session not set' in self.browser.contents) 3890 self.app['configuration'].current_academic_session = 2004 3891 self.browser.getLink("Update scores").click() 3892 self.browser.getLink("Download editable tickets").click() 3893 self.assertEqual(self.browser.headers['Status'], '200 Ok') 3894 self.assertEqual(self.browser.headers['Content-Type'], 3895 'text/csv; charset=UTF-8') 3896 self.assertEqual(self.browser.contents, 'matric_number,student_id,' 3897 'display_fullname,level,code,level_session,score\r\n234,' 3898 'K1000000,Anna Tester,100,COURSE1,2004,\r\n') 3863 3899 3864 3900 def test_export_departmet_officers(self):
Note: See TracChangeset for help on using the changeset viewer.