Changeset 12518


Ignore:
Timestamp:
27 Jan 2015, 14:48:22 (10 years ago)
Author:
Henrik Bettermann
Message:

Add exporter methods and export page to filter student data exports by entering a list of student ids.

Location:
main/waeup.kofa/trunk
Files:
1 added
8 edited

Legend:

Unmodified
Added
Removed
  • main/waeup.kofa/trunk/CHANGES.txt

    r12515 r12518  
    55=======================
    66
     7* Add exporter methods and export page to filter student data exports
     8  by entering a list of student ids.
     9
     10* Student statistic can now be broken down by faculties or by departments.
     11
    712* Check if p_id exists in payments_catalog when importing payment tickets in
    813  create mode.
    9 
    10 * Student statistic can now be broken down by faculties or by departments.
    1114
    1215
  • main/waeup.kofa/trunk/src/waeup/kofa/browser/templates/datacenterexportpage.pt

    r11826 r12518  
    3838
    3939<p i18n:translate="">
    40   Student data exports have to be further configured. You can create CSV files
    41   on the <a href="@@exportconfig">student data export configuration page</a>.
     40  Student data exports have to be further configured. You can either refine
     41  the results by <a href="@@exportconfig">selecting certain export paramers</a>
     42  or by <a href="@@exportselected">entering a set of student ids</a>.
    4243</p>
    4344
  • main/waeup.kofa/trunk/src/waeup/kofa/browser/tests/test_browser.py

    r11730 r12518  
    318318        self.assertEqual(self.browser.url, self.datacenter_path)
    319319        self.browser.getLink("Export data").click()
    320         self.browser.getLink("configuration page").click()
     320        self.browser.getLink("selecting certain export paramers").click()
    321321        self.browser.getControl(name="exporter").value = ['students']
    322322        self.browser.getControl(name="session").value = ['all']
  • main/waeup.kofa/trunk/src/waeup/kofa/students/browser.py

    r12474 r12518  
    32823282    redirect_target = '@@export'
    32833283
     3284class DatacenterExportJobContainerSelectStudents(ExportJobContainerJobConfig):
     3285    """Page that configures a students export job in datacenter.
     3286
     3287    """
     3288    grok.name('exportselected')
     3289    grok.context(IDataCenter)
     3290    redirect_target = '@@export'
     3291    grok.template('exportselected')
     3292    label = _('Configure student data export')
     3293
     3294    def update(self, START=None, students=None, exporter=None):
     3295        self._set_exporter_values()
     3296        if START is None:
     3297            return
     3298        try:
     3299            ids = students.replace(',', ' ').split()
     3300        except:
     3301            self.flash(sys.exc_info()[1])
     3302            self.redirect(self.url(self.redirect_target))
     3303            return
     3304        job_id = self.context.start_export_job(
     3305            exporter, self.request.principal.id, selected=ids)
     3306        ob_class = self.__implemented__.__name__.replace('waeup.kofa.','')
     3307        self.context.logger.info(
     3308            '%s - selected students exported: %s, job_id=%s' %
     3309            (ob_class, exporter, job_id))
     3310        self.flash(_('Export of selected students started.'))
     3311        self.redirect(self.url(self.redirect_target))
     3312        return
     3313
    32843314class FacultiesExportJobContainerJobConfig(ExportJobContainerJobConfig):
    32853315    """Page that configures a students export job in facultiescontainer.
  • main/waeup.kofa/trunk/src/waeup/kofa/students/export.py

    r12104 r12518  
    190190        return query.query()
    191191
     192    def get_selected(self, site, selected):
     193        """Get set of selected students.
     194
     195        Returns a simple empty list or a list with `Student`
     196        objects.
     197        """
     198        students = []
     199        students_container = site.get('students', {})
     200        for id in selected:
     201            student = students_container.get(id, None)
     202            if student:
     203                students.append(student)
     204        return students
     205
    192206    def export(self, values, filepath=None):
    193207        """Export `values`, an iterable, as CSV file.
     
    217231        """
    218232        data = self.get_filtered(site, **kw)
     233        return self.export(self.filter_func(data, **kw), filepath=filepath)
     234
     235    def export_selected(self,site, filepath=None, **kw):
     236        """Export data for selected set of students.
     237        """
     238        selected = kw.get('selected', [])
     239        data = self.get_selected(site, selected)
    219240        return self.export(self.filter_func(data, **kw), filepath=filepath)
    220241
  • main/waeup.kofa/trunk/src/waeup/kofa/students/interfaces.py

    r11589 r12518  
    872872        """
    873873
     874    def get_selected(site, selected):
     875        """Get set of selected students.
     876        """
     877
    874878    def export_student(student, filepath=None):
    875879        """Export data for a given student.
     
    877881
    878882    def export_filtered(site, filepath=None, **kw):
    879         """Export filtered set of students.
    880         """
     883        """Export data for filtered set of students.
     884        """
     885
     886    def export_selected(site, filepath=None, **kw):
     887        """Export data for selected set of students.
     888        """
  • main/waeup.kofa/trunk/src/waeup/kofa/students/tests/test_browser.py

    r12393 r12518  
    33133313            )
    33143314
     3315    def test_datacenter_export_selected(self):
     3316        self.browser.addHeader('Authorization', 'Basic mgr:mgrpw')
     3317        self.browser.open('http://localhost/app/datacenter/@@exportselected')
     3318        self.browser.getControl(name="exporter").value = ['students']
     3319        self.browser.getControl(name="students").value = 'K1000000'
     3320        self.browser.getControl("Create CSV file").click()
     3321        # When the job is finished and we reload the page...
     3322        job_id = self.wait_for_export_job_completed()
     3323        # ... the csv file can be downloaded ...
     3324        self.browser.open('http://localhost/app/datacenter/@@export')
     3325        self.browser.getLink("Download").click()
     3326        self.assertEqual(self.browser.headers['content-type'],
     3327            'text/csv; charset=UTF-8')
     3328        self.assertTrue(
     3329            'filename="WAeUP.Kofa_students_%s.csv' % job_id in
     3330            self.browser.headers['content-disposition'])
     3331        self.assertTrue(
     3332            'adm_code,clearance_locked,clr_code,date_of_birth,email,employer,'
     3333            'firstname,lastname,matric_number,middlename,nationality,'
     3334            'officer_comment,perm_address,personal_updated,phone,reg_number,'
     3335            'sex,student_id,suspended,suspended_comment,transcript_comment,'
     3336            'password,state,history,certcode,is_postgrad,current_level,'
     3337            'current_session\r\n'
     3338            ',1,,1981-02-04#,aa@aa.ng,,Anna,Tester,234,,,,,,'
     3339            '1234#,123,m,K1000000,0,,,{SSHA}' in self.browser.contents)
     3340
    33153341    def test_payment_dates(self):
    33163342        self.browser.addHeader('Authorization', 'Basic mgr:mgrpw')
  • main/waeup.kofa/trunk/src/waeup/kofa/students/tests/test_export.py

    r12393 r12518  
    262262        return
    263263
     264    def test_export_selected(self):
     265        # we can export a filtered set of students (filtered by session/level)
     266        self.setup_student(self.student)
     267        self.app['students'].addStudent(self.student)
     268        notify(grok.ObjectModifiedEvent(self.student))
     269        exporter = StudentExporter()
     270        exporter.export_selected(
     271            self.app, self.outfile, selected=['A111111'])
     272        result1 = open(self.outfile, 'rb').read()
     273        exporter.export_selected(
     274            self.app, self.outfile, selected=[])
     275        result2 = open(self.outfile, 'rb').read()
     276        self.assertTrue(self.std_csv_entry in result1)
     277        self.assertFalse(self.std_csv_entry in result2)
     278        return
     279
    264280    def test_export_filtered_by_dept(self):
    265281        # we can export a set of students filtered by department
     
    405421        return
    406422
     423    def test_export_selected(self):
     424        # we can export a filtered set of students (filtered by session/level)
     425        self.setup_student(self.student)
     426        self.app['students'].addStudent(self.student)
     427        notify(grok.ObjectModifiedEvent(self.student))
     428        exporter = StudentStudyCourseExporter()
     429        exporter.export_selected(
     430            self.app, self.outfile, selected=['A111111'])
     431        result = open(self.outfile, 'rb').read()
     432        self.assertEqual(
     433            result,
     434            'certificate,current_level,current_session,current_verdict,'
     435            'entry_mode,entry_session,previous_verdict,student_id\r\n'
     436
     437            'CERT1,200,2012,0,ug_ft,2010,0,A111111\r\n'
     438            )
     439        return
    407440
    408441
     
    502535        exporter.export_filtered(
    503536            self.student, self.outfile)
     537        result = open(self.outfile, 'rb').read()
     538        self.assertEqual(
     539            result,
     540            'gpa,level,level_session,level_verdict,total_credits,'
     541            'validated_by,validation_date,'
     542            'student_id,number_of_tickets,certcode\r\n'
     543            '0.0,100,2012,A,100,,,A111111,1,CERT1\r\n'
     544            )
     545        return
     546
     547    def test_export_selected(self):
     548        # we can export studylevels of a filtered set of students
     549        self.setup_student(self.student)
     550        self.app['students'].addStudent(self.student)
     551        notify(grok.ObjectModifiedEvent(self.student))
     552
     553        exporter = StudentStudyLevelExporter()
     554        exporter.export_selected(
     555            self.app, self.outfile, selected=['A111111'])
    504556        result = open(self.outfile, 'rb').read()
    505557        self.assertEqual(
Note: See TracChangeset for help on using the changeset viewer.