Changeset 9734


Ignore:
Timestamp:
28 Nov 2012, 01:14:33 (12 years ago)
Author:
uli
Message:

Try to make clearer where we head to regarding filtered exports.

Location:
main/waeup.kofa/trunk/src/waeup/kofa
Files:
5 edited

Legend:

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

    r9574 r9734  
    3434                  'coursetickets', 'studentpayments')
    3535
    36 def get_students(site):
     36class 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
     46    def __init__(self, session=None, level=None,
     47                 faculty_code=None, department_code=None):
     48        self.session = session
     49        self.level = level
     50        self.faculty_code = faculty_code
     51        self.department_code = department_code
     52        return
     53
     54    def get_students(self, catalog):
     55        students = catalog.searchResults(
     56            student_id=(None, None),
     57            current_session=(self.session, self.session),
     58            #level=(self.level, self.level), # would be nice
     59            faccode=(self.faculty_code, self.faculty_code),
     60            depcode=(self.department_code, self.department_code)
     61            )
     62        # filter out by level
     63        if self.level is not None:
     64            return [x for x in students
     65                    if x['studycourse'].current_level == self.level]
     66        return students
     67
     68def get_students(site, stud_filter=None):
    3769    """Get all students registered in catalog in `site`.
    3870    """
     
    4173    if catalog is None:
    4274        return []
    43     students = catalog.searchResults(student_id=(None, None))
     75    if stud_filter is None:
     76        students = catalog.searchResults(student_id=(None, None))
     77    else:
     78        students = stud_filter.get_students(catalog)
    4479    return students
    4580
     
    104139            self.write_item(value, writer)
    105140        return self.close_outfile(filepath, outfile)
     141
     142    def export_filtered(self, site, session, level, faculty_code=None,
     143                        department_code=None, filepath=None):
     144        pass
    106145
    107146
  • main/waeup.kofa/trunk/src/waeup/kofa/students/interfaces.py

    r9702 r9734  
    751751        """Export data for a given student.
    752752        """
     753
     754    def export_filtered(site, session, level, faculty_code=None,
     755                        department_code=None, filepath=None):
     756        """Export filtered set of students.
     757        """
  • main/waeup.kofa/trunk/src/waeup/kofa/students/tests/test_export.py

    r9702 r9734  
     1import grok
    12import datetime
    23from zope.component import queryUtility
     4from zope.event import notify
    35from zope.interface.verify import verifyObject, verifyClass
    46from waeup.kofa.interfaces import ICSVExporter
     
    68    StudentsExporter, StudentStudyCourseExporter, StudentStudyLevelExporter,
    79    CourseTicketExporter, PaymentsExporter, BedTicketsExporter,
    8     StudentPaymentsOverviewExporter)
     10    StudentPaymentsOverviewExporter, get_students, StudentsExportFilter)
     11from waeup.kofa.students.accommodation import BedTicket
     12from waeup.kofa.students.interfaces import ICSVStudentExporter
    913from waeup.kofa.students.payments import StudentOnlinePayment
    10 from waeup.kofa.students.accommodation import BedTicket
     14from waeup.kofa.students.student import Student
    1115from waeup.kofa.students.studycourse import StudentStudyCourse
    1216from waeup.kofa.students.studylevel import StudentStudyLevel, CourseTicket
     
    1822year_range_str = ','.join([str(i) for i in year_range])
    1923
     24class ExportHelperTests(StudentImportExportSetup):
     25    layer = FunctionalLayer
     26    def setUp(self):
     27        super(ExportHelperTests, self).setUp()
     28        student = Student()
     29        self.app['students'].addStudent(student)
     30        student = self.setup_student(student)
     31        notify(grok.ObjectModifiedEvent(student))
     32        self.student = self.app['students'][student.student_id]
     33        return
     34
     35    def test_get_students_plain(self):
     36        # without a filter we get all students
     37        result = get_students(self.app)
     38        self.assertEqual(len(list(result)), 1)
     39        return
     40
     41    def test_get_students_by_session(self):
     42        # we can filter out students of a certain session
     43        my_filter1 = StudentsExportFilter(session=2012)
     44        result = get_students(self.app, stud_filter=my_filter1)
     45        self.assertEqual(len(list(result)), 1)
     46
     47        my_filter2 = StudentsExportFilter(session=1964)
     48        result = get_students(self.app, stud_filter=my_filter2)
     49        self.assertEqual(len(list(result)), 0)
     50        return
     51
     52    def test_get_students_by_level(self):
     53        # we can filter out students of a certain level
     54        my_filter1 = StudentsExportFilter(level=200)
     55        result = get_students(self.app, stud_filter=my_filter1)
     56        self.assertEqual(len(list(result)), 1)
     57
     58        my_filter2 = StudentsExportFilter(level=300)
     59        result = get_students(self.app, stud_filter=my_filter2)
     60        self.assertEqual(len(list(result)), 0)
     61        return
    2062
    2163class StudentsExporterTest(StudentImportExportSetup):
     
    3173        # make sure we fullfill interface contracts
    3274        obj = StudentsExporter()
    33         verifyObject(ICSVExporter, obj)
    34         verifyClass(ICSVExporter, StudentsExporter)
     75        verifyObject(ICSVStudentExporter, obj)
     76        verifyClass(ICSVStudentExporter, StudentsExporter)
    3577        return
    3678
  • main/waeup.kofa/trunk/src/waeup/kofa/university/department.py

    r9234 r9734  
    1919"""
    2020import grok
     21import zope.location.location
    2122from zope.component.interfaces import IFactory
    2223from zope.interface import implementedBy
     
    2425from waeup.kofa.university.coursescontainer import CoursesContainer
    2526from waeup.kofa.university.certificatescontainer import CertificatesContainer
     27from waeup.kofa.utils.batching import VirtualExportJobContainer
    2628from waeup.kofa.interfaces import IKofaUtils
    2729from waeup.kofa.university.interfaces import IDepartment, IDepartmentAdd
     
    6870        elif name == 'certificates':
    6971            return self.certificates
     72        elif name == 'exports':
     73            # create a virtual exports container and return it
     74            container = VirtualExportJobContainer()
     75            zope.location.location.located(container, self, 'exports')
     76            return container
    7077        return None
    7178
     
    7582            insttypes_dict[self.title_prefix],
    7683            self.title, self.code)
    77 
    7884
    7985class DepartmentFactory(grok.GlobalUtility):
  • main/waeup.kofa/trunk/src/waeup/kofa/utils/batching.py

    r9726 r9734  
    410410        outfile = StringIO()
    411411        writer = csv.DictWriter(outfile, self.available_fields)
    412         writer.writerow(dict(zip(self.available_fields, self.available_fields))) # header
     412        writer.writerow(
     413            dict(zip(self.available_fields, self.available_fields))) # header
    413414        outfile.seek(0)
    414415        return outfile.read()
Note: See TracChangeset for help on using the changeset viewer.