Ignore:
Timestamp:
7 Dec 2012, 10:57:21 (12 years ago)
Author:
uli
Message:

Make use of new students query (replacing the old filter) and simplify level list creation for studylevelsoverview exporter.

File:
1 edited

Legend:

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

    r9763 r9787  
    2020import grok
    2121from datetime import datetime
    22 from zope.catalog.interfaces import ICatalog
    23 from zope.component import queryUtility
    2422from waeup.kofa.interfaces import MessageFactory as _
     23from waeup.kofa.students.catalog import StudentsQuery
    2524from waeup.kofa.students.interfaces import (
    2625    IStudent, IStudentStudyCourse, IStudentStudyLevel, ICourseTicket,
    2726    IStudentOnlinePayment, ICSVStudentExporter, IBedTicket)
     27from waeup.kofa.students.vocabularies import study_levels
    2828from waeup.kofa.utils.batching import ExporterBase
    2929from waeup.kofa.utils.helpers import iface_names
     
    3434                  'coursetickets', 'studentpayments')
    3535
    36 class StudentsExportFilter(object):
    37     """A filter to find students that match certain criteria.
    38 
    39     The filter is meant as a component to aggregate search parameters
    40     for students. This way we can tell some exporter to use 'this
    41     filter' instead of passing in all (probably different) parameters.
    42 
    43     Just an idea right now. There might be better ways.
    44     """
    45     cat_name = 'students_catalog'
    46     default_params = dict(student_id=None)
    47 
    48     def __init__(self, **kw):
    49         self._kw = dict(self.default_params)
    50         self._kw.update(kw)
    51         return
    52 
    53     def query_catalog(self, catalog):
    54         query = dict([(idx_name, (value, value))
    55                      for idx_name, value in self._kw.items()])
    56         result = catalog.searchResults(**query)
    57         return result
    58 
    59     def query(self, context=None):
    60         catalog = queryUtility(
    61             ICatalog, context=context, name=self.cat_name, default=None)
    62         if catalog is None:
    63             return []
    64         return self.query_catalog(catalog)
    65 
    66 def get_students(site, stud_filter=StudentsExportFilter()):
     36def get_students(site, stud_filter=StudentsQuery()):
    6737    """Get all students registered in catalog in `site`.
    6838    """
    69     return stud_filter.query(context=site)
     39    return stud_filter.query()
    7040
    7141def get_studycourses(students):
     
    134104        """Export all students denoted by the given parameters.
    135105        """
    136         filter_inst = StudentsExportFilter(
     106        filter_inst = StudentsQuery(
    137107            current_session=session, current_level=level,
    138108            faccode=faccode, depcode=depcode)
     
    393363    grok.name('studylevelsoverview')
    394364
    395     levels = ['10',]
    396     levels += [str(level) for level in range(100,1000,10) if level % 100 < 30]
    397     levels.append('999')
    398     level_range_tuple = tuple(levels)
     365    avail_levels = tuple([str(x) for x in study_levels(None)])
    399366
    400367    #: Fieldnames considered by this exporter
     
    402369        'state', 'certcode', 'faccode', 'depcode', 'is_postgrad',
    403370        'entry_session', 'current_level', 'current_session',
    404         ) + level_range_tuple
     371        ) + avail_levels
    405372
    406373    #: The title under which this exporter will be displayed
     
    408375
    409376    def mangle_value(self, value, name, context=None):
    410         if name in self.level_range_tuple and context is not None:
     377        if name in self.avail_levels and context is not None:
    411378            value = ''
    412379            for level in context['studycourse'].values():
Note: See TracChangeset for help on using the changeset viewer.