Changeset 9802


Ignore:
Timestamp:
15 Dec 2012, 11:16:25 (12 years ago)
Author:
uli
Message:

Avoid repetition.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • main/waeup.kofa/trunk/src/waeup/kofa/students/export.py

    r9801 r9802  
    3434                  'coursetickets', 'studentpayments')
    3535
    36 def ident(x):
    37     return x
    38     #for item in x:
    39     #    yield item
    40 
    4136def get_students(site, stud_filter=StudentsQuery()):
    4237    """Get all students registered in catalog in `site`.
     
    9691
    9792    def filter_func(self, x):
    98         return get_students(x)
     93        return x
    9994
    10095    def get_filtered(self, site, **kw):
     
    131126        If `filepath` is ``None``, a raw string with CSV data is returned.
    132127        """
    133         return self.export(self.filter_func(site), filepath)
     128        return self.export(self.filter_func(get_students(site)), filepath)
    134129
    135130    def export_student(self, student, filepath=None):
    136131        return self.export(self.filter_func([student]), filepath=filepath)
     132
     133    def export_filtered(self, site, filepath=None, **kw):
     134        """Export items denoted by `kw`.
     135
     136        If `filepath` is ``None``, a raw string with CSV data should
     137        be returned.
     138        """
     139        data = self.get_filtered(site, **kw)
     140        return self.export(self.filter_func(data), filepath=filepath)
    137141
    138142
     
    162166            value, name, context=context)
    163167
    164     def export_all(self, site, filepath=None):
    165         """Export students into filepath as CSV data.
    166 
    167         If `filepath` is ``None``, a raw string with CSV data is returned.
    168         """
    169         return self.export(get_students(site), filepath)
    170 
    171     def export_student(self, student, filepath=None):
    172         return self.export([student], filepath=filepath)
    173168
    174169class StudentStudyCourseExporter(grok.GlobalUtility, StudentExporterBase):
     
    199194            value, name, context=context)
    200195
    201     def export_all(self, site, filepath=None):
    202         """Export study courses into filepath as CSV data.
    203 
    204         If `filepath` is ``None``, a raw string with CSV data is returned.
    205         """
    206         return self.export(get_studycourses(get_students(site)), filepath)
    207 
    208     def export_student(self, student, filepath=None):
    209         """Export studycourse of a single student object.
    210         """
    211         return self.export(get_studycourses([student]), filepath)
    212 
    213     def export_filtered(self, site, filepath=None, **kw):
    214         """Export items denoted by `args` and `kw`.
    215 
    216         If `filepath` is ``None``, a raw string with CSV data should
    217         be returned.
    218         """
    219         data = self.get_filtered(site, **kw)
    220         return self.export(get_studycourses(data), filepath=filepath)
    221 
    222196
    223197class StudentStudyLevelExporter(grok.GlobalUtility, StudentExporterBase):
     
    234208    title = _(u'Student Study Levels')
    235209
     210    def filter_func(self, x):
     211        return get_levels(x)
     212
    236213    def mangle_value(self, value, name, context=None):
    237214        """Treat location values special.
     
    243220            StudentStudyLevelExporter, self).mangle_value(
    244221            value, name, context=context)
    245 
    246     def export_all(self, site, filepath=None):
    247         """Export study levels into filepath as CSV data.
    248 
    249         If `filepath` is ``None``, a raw string with CSV data is returned.
    250         """
    251         return self.export(get_levels(get_students(site)), filepath)
    252 
    253     def export_student(self, student, filepath=None):
    254         return self.export(get_levels([student]), filepath)
    255 
    256     def export_filtered(self, site, filepath=None, **kw):
    257         """Export items denoted by `args` and `kw`.
    258 
    259         If `filepath` is ``None``, a raw string with CSV data should
    260         be returned.
    261         """
    262         data = self.get_filtered(site, **kw)
    263         return self.export(get_levels(data), filepath=filepath)
    264222
    265223class CourseTicketExporter(grok.GlobalUtility, StudentExporterBase):
     
    274232    #: The title under which this exporter will be displayed
    275233    title = _(u'Course Tickets')
     234
     235    def filter_func(self, x):
     236        return get_tickets(x)
    276237
    277238    def mangle_value(self, value, name, context=None):
     
    288249            value, name, context=context)
    289250
    290     def export_all(self, site, filepath=None):
    291         """Export course tickets into filepath as CSV data.
    292 
    293         If `filepath` is ``None``, a raw string with CSV data is returned.
    294         """
    295         return self.export(get_tickets(get_students(site)), filepath)
    296 
    297     def export_student(self, student, filepath=None):
    298         return self.export(get_tickets([student]), filepath)
    299 
    300     def export_filtered(self, site, filepath=None, **kw):
    301         """Export items denoted by `args` and `kw`.
    302 
    303         If `filepath` is ``None``, a raw string with CSV data should
    304         be returned.
    305         """
    306         data = self.get_filtered(site, **kw)
    307         return self.export(get_tickets(data), filepath=filepath)
    308 
    309251
    310252class PaymentsExporter(grok.GlobalUtility, StudentExporterBase):
     
    322264    title = _(u'Student Payments')
    323265
     266    def filter_func(self, x):
     267        return get_payments(x)
     268
    324269    def mangle_value(self, value, name, context=None):
    325270        """Treat location values special.
     
    332277            PaymentsExporter, self).mangle_value(
    333278            value, name, context=context)
    334 
    335     def export_all(self, site, filepath=None):
    336         """Export payments into filepath as CSV data.
    337 
    338         If `filepath` is ``None``, a raw string with CSV data is returned.
    339         """
    340         return self.export(get_payments(get_students(site)), filepath)
    341 
    342     def export_student(self, student, filepath=None):
    343         return self.export(get_payments([student]), filepath)
    344 
    345     def export_filtered(self, site, filepath=None, **kw):
    346         """Export items denoted by `args` and `kw`.
    347 
    348         If `filepath` is ``None``, a raw string with CSV data should
    349         be returned.
    350         """
    351         data = self.get_filtered(site, **kw)
    352         return self.export(get_payments(data), filepath=filepath)
    353279
    354280class BedTicketsExporter(grok.GlobalUtility, StudentExporterBase):
     
    365291    #: The title under which this exporter will be displayed
    366292    title = _(u'Bed Tickets')
     293
     294    def filter_func(self, x):
     295        return get_bedtickets(x)
    367296
    368297    def mangle_value(self, value, name, context=None):
     
    380309            BedTicketsExporter, self).mangle_value(
    381310            value, name, context=context)
    382 
    383     def export_all(self, site, filepath=None):
    384         """Export payments into filepath as CSV data.
    385 
    386         If `filepath` is ``None``, a raw string with CSV data is returned.
    387         """
    388         return self.export(get_bedtickets(get_students(site)), filepath)
    389 
    390     def export_student(self, student, filepath=None):
    391         return self.export(get_bedtickets([student]), filepath)
    392 
    393     def export_filtered(self, site, filepath=None, **kw):
    394         """Export items denoted by `args` and `kw`.
    395 
    396         If `filepath` is ``None``, a raw string with CSV data should
    397         be returned.
    398         """
    399         data = self.get_filtered(site, **kw)
    400         return self.export(get_bedtickets(data), filepath=filepath)
    401311
    402312class StudentPaymentsOverviewExporter(StudentsExporter):
Note: See TracChangeset for help on using the changeset viewer.