Changeset 9734 for main/waeup.kofa/trunk/src/waeup
- Timestamp:
- 28 Nov 2012, 01:14:33 (12 years ago)
- 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 34 34 'coursetickets', 'studentpayments') 35 35 36 def get_students(site): 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 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 68 def get_students(site, stud_filter=None): 37 69 """Get all students registered in catalog in `site`. 38 70 """ … … 41 73 if catalog is None: 42 74 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) 44 79 return students 45 80 … … 104 139 self.write_item(value, writer) 105 140 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 106 145 107 146 -
main/waeup.kofa/trunk/src/waeup/kofa/students/interfaces.py
r9702 r9734 751 751 """Export data for a given student. 752 752 """ 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 1 import grok 1 2 import datetime 2 3 from zope.component import queryUtility 4 from zope.event import notify 3 5 from zope.interface.verify import verifyObject, verifyClass 4 6 from waeup.kofa.interfaces import ICSVExporter … … 6 8 StudentsExporter, StudentStudyCourseExporter, StudentStudyLevelExporter, 7 9 CourseTicketExporter, PaymentsExporter, BedTicketsExporter, 8 StudentPaymentsOverviewExporter) 10 StudentPaymentsOverviewExporter, get_students, StudentsExportFilter) 11 from waeup.kofa.students.accommodation import BedTicket 12 from waeup.kofa.students.interfaces import ICSVStudentExporter 9 13 from waeup.kofa.students.payments import StudentOnlinePayment 10 from waeup.kofa.students. accommodation import BedTicket14 from waeup.kofa.students.student import Student 11 15 from waeup.kofa.students.studycourse import StudentStudyCourse 12 16 from waeup.kofa.students.studylevel import StudentStudyLevel, CourseTicket … … 18 22 year_range_str = ','.join([str(i) for i in year_range]) 19 23 24 class 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 20 62 21 63 class StudentsExporterTest(StudentImportExportSetup): … … 31 73 # make sure we fullfill interface contracts 32 74 obj = StudentsExporter() 33 verifyObject(ICSV Exporter, obj)34 verifyClass(ICSV Exporter, StudentsExporter)75 verifyObject(ICSVStudentExporter, obj) 76 verifyClass(ICSVStudentExporter, StudentsExporter) 35 77 return 36 78 -
main/waeup.kofa/trunk/src/waeup/kofa/university/department.py
r9234 r9734 19 19 """ 20 20 import grok 21 import zope.location.location 21 22 from zope.component.interfaces import IFactory 22 23 from zope.interface import implementedBy … … 24 25 from waeup.kofa.university.coursescontainer import CoursesContainer 25 26 from waeup.kofa.university.certificatescontainer import CertificatesContainer 27 from waeup.kofa.utils.batching import VirtualExportJobContainer 26 28 from waeup.kofa.interfaces import IKofaUtils 27 29 from waeup.kofa.university.interfaces import IDepartment, IDepartmentAdd … … 68 70 elif name == 'certificates': 69 71 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 70 77 return None 71 78 … … 75 82 insttypes_dict[self.title_prefix], 76 83 self.title, self.code) 77 78 84 79 85 class DepartmentFactory(grok.GlobalUtility): -
main/waeup.kofa/trunk/src/waeup/kofa/utils/batching.py
r9726 r9734 410 410 outfile = StringIO() 411 411 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 413 414 outfile.seek(0) 414 415 return outfile.read()
Note: See TracChangeset for help on using the changeset viewer.