Changeset 9844 for main/waeup.kofa/trunk


Ignore:
Timestamp:
8 Jan 2013, 13:33:14 (12 years ago)
Author:
Henrik Bettermann
Message:

Use keywords not only to filter students but also to restrict access to coursetickets which belong to the course so that lecturers (who gain access to courses) can download only coursetickets of their own course.

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

    r9843 r9844  
    28102810
    28112811    def _set_exporter_values(self):
    2812         # We provide only the students exporter.
     2812        # We provide only two exporters.
    28132813        exporters = []
    2814         for name in ('students',):
     2814        for name in ('students', 'coursetickets'):
    28152815            util = getUtility(ICSVExporter, name=name)
    28162816            exporters.append((util.title, name),)
  • main/waeup.kofa/trunk/src/waeup/kofa/students/export.py

    r9843 r9844  
    5656    return levels
    5757
    58 def get_tickets(students):
    59     """Get all course tickets of `students`.
     58def get_tickets(students, **kw):
     59    """Get course tickets of `students`.
     60
     61    If code is passed through filter course tickets
     62    which belong to this course code.
    6063    """
    6164    tickets = []
    62     for level in get_levels(students):
    63         for ticket in level.values():
    64             tickets.append(ticket)
     65    code = kw.get('code', None)
     66    if code is None:
     67        for level in get_levels(students):
     68            for ticket in level.values():
     69                tickets.append(ticket)
     70    else:
     71        for level in get_levels(students):
     72            for ticket in level.values():
     73                if ticket.code == code:
     74                    tickets.append(ticket)
    6575    return tickets
    6676
     
    92102    grok.provides(ICSVStudentExporter)
    93103
    94     def filter_func(self, x):
     104    def filter_func(self, x, **kw):
    95105        return x
    96106
     
    149159        """
    150160        data = self.get_filtered(site, **kw)
    151         return self.export(self.filter_func(data), filepath=filepath)
     161        return self.export(self.filter_func(data, **kw), filepath=filepath)
    152162
    153163
     
    189199    title = _(u'Student Study Courses')
    190200
    191     def filter_func(self, x):
     201    def filter_func(self, x, **kw):
    192202        return get_studycourses(x)
    193203
     
    219229    title = _(u'Student Study Levels')
    220230
    221     def filter_func(self, x):
     231    def filter_func(self, x, **kw):
    222232        return get_levels(x)
    223233
     
    244254    title = _(u'Course Tickets')
    245255
    246     def filter_func(self, x):
    247         return get_tickets(x)
     256    def filter_func(self, x, **kw):
     257        return get_tickets(x, **kw)
    248258
    249259    def mangle_value(self, value, name, context=None):
     
    275285    title = _(u'Student Payments')
    276286
    277     def filter_func(self, x):
     287    def filter_func(self, x, **kw):
    278288        return get_payments(x)
    279289
     
    303313    title = _(u'Bed Tickets')
    304314
    305     def filter_func(self, x):
     315    def filter_func(self, x, **kw):
    306316        return get_bedtickets(x)
    307317
  • main/waeup.kofa/trunk/src/waeup/kofa/students/tests/test_browser.py

    r9843 r9844  
    28352835            )
    28362836
    2837     def test_course_export(self):
     2837    def test_course_export_students(self):
    28382838        self.browser.addHeader('Authorization', 'Basic mgr:mgrpw')
    28392839        course1_path = 'http://localhost/app/faculties/fac1/dep1/courses/COURSE1'
     
    28802880            '- discarded: job_id=%s' % job_id in logcontent
    28812881            )
     2882
     2883    def test_course_export_coursetickets(self):
     2884        self.browser.addHeader('Authorization', 'Basic mgr:mgrpw')
     2885        course1_path = 'http://localhost/app/faculties/fac1/dep1/courses/COURSE1'
     2886        self.browser.open(course1_path)
     2887        self.browser.getLink("Export student data").click()
     2888        self.browser.getControl("Configure new export").click()
     2889        self.browser.getControl(name="exporter").value = ['coursetickets']
     2890        self.browser.getControl(name="session").value = ['2004']
     2891        self.browser.getControl(name="level").value = ['100']
     2892        self.browser.getControl("Create CSV file").click()
     2893
     2894        # When the job is finished and we reload the page...
     2895        job_id = self.wait_for_export_job_completed()
     2896        self.browser.open(course1_path + '/exports')
     2897        # ... the csv file can be downloaded ...
     2898        self.browser.getLink("Download").click()
     2899        self.assertEqual(self.browser.headers['content-type'],
     2900            'text/csv; charset=UTF-8')
     2901        self.assertTrue(
     2902            'filename="WAeUP.Kofa_coursetickets_%s.csv' % job_id in
     2903            self.browser.headers['content-disposition'])
     2904        self.assertEqual(len(self.app['datacenter'].running_exports), 1)
     2905        job_id = self.app['datacenter'].running_exports[0][0]
     2906        # ... and discarded
     2907        self.browser.open(course1_path + '/exports')
     2908        self.browser.getControl("Discard").click()
     2909        self.assertEqual(len(self.app['datacenter'].running_exports), 0)
     2910        # Creation, downloading and discarding is logged
     2911        logfile = os.path.join(
     2912            self.app['datacenter'].storage, 'logs', 'datacenter.log')
     2913        logcontent = open(logfile).read()
     2914        self.assertTrue(
     2915            'zope.mgr - students.browser.CourseExportJobContainerJobConfig '
     2916            '- exported: coursetickets (2004, 100, COURSE1), job_id=%s'
     2917            % job_id in logcontent
     2918            )
     2919        self.assertTrue(
     2920            'zope.mgr - students.browser.ExportJobContainerDownload '
     2921            '- downloaded: WAeUP.Kofa_coursetickets_%s.csv, job_id=%s'
     2922            % (job_id, job_id) in logcontent
     2923            )
     2924        self.assertTrue(
     2925            'zope.mgr - students.browser.ExportJobContainerOverview '
     2926            '- discarded: job_id=%s' % job_id in logcontent
     2927            )
  • main/waeup.kofa/trunk/src/waeup/kofa/students/tests/test_export.py

    r9832 r9844  
    554554
    555555    def test_export_filtered(self):
    556         # we can export studylevels of a filtered set of students
     556        # we can export course tickets of a filtered set of students
    557557        self.setup_student(self.student)
    558558        self.app['students'].addStudent(self.student)
     
    568568            'passmark,score,semester,title,student_id,certcode\r\n'
    569569            '1,1,CRS1,100,DEP1,FAC1,100,0,100,,2,Course 1,A111111,CERT1\r\n'
     570            )
     571        # if the coursetickets catalog is used to filter students
     572        # and (course) code is not None
     573        # only course tickets which belong to this course are exported
     574        exporter.export_filtered(
     575            self.student, self.outfile, cat='coursetickets', code='CRS1')
     576        result = open(self.outfile, 'rb').read()
     577        self.assertEqual(
     578            result,
     579            'automatic,carry_over,code,credits,dcode,fcode,level,mandatory,'
     580            'passmark,score,semester,title,student_id,certcode\r\n'
     581            '1,1,CRS1,100,DEP1,FAC1,100,0,100,,2,Course 1,A111111,CERT1\r\n'
     582            )
     583        exporter.export_filtered(
     584            self.student, self.outfile, cat='coursetickets', code='any code')
     585        result = open(self.outfile, 'rb').read()
     586        self.assertEqual(
     587            result,
     588            'automatic,carry_over,code,credits,dcode,fcode,level,mandatory,'
     589            'passmark,score,semester,title,student_id,certcode\r\n'
    570590            )
    571591        return
Note: See TracChangeset for help on using the changeset viewer.