Changeset 9787 for main/waeup.kofa/trunk/src/waeup
- Timestamp:
- 7 Dec 2012, 10:57:21 (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
main/waeup.kofa/trunk/src/waeup/kofa/students/export.py
r9763 r9787 20 20 import grok 21 21 from datetime import datetime 22 from zope.catalog.interfaces import ICatalog23 from zope.component import queryUtility24 22 from waeup.kofa.interfaces import MessageFactory as _ 23 from waeup.kofa.students.catalog import StudentsQuery 25 24 from waeup.kofa.students.interfaces import ( 26 25 IStudent, IStudentStudyCourse, IStudentStudyLevel, ICourseTicket, 27 26 IStudentOnlinePayment, ICSVStudentExporter, IBedTicket) 27 from waeup.kofa.students.vocabularies import study_levels 28 28 from waeup.kofa.utils.batching import ExporterBase 29 29 from waeup.kofa.utils.helpers import iface_names … … 34 34 'coursetickets', 'studentpayments') 35 35 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()): 36 def get_students(site, stud_filter=StudentsQuery()): 67 37 """Get all students registered in catalog in `site`. 68 38 """ 69 return stud_filter.query( context=site)39 return stud_filter.query() 70 40 71 41 def get_studycourses(students): … … 134 104 """Export all students denoted by the given parameters. 135 105 """ 136 filter_inst = Students ExportFilter(106 filter_inst = StudentsQuery( 137 107 current_session=session, current_level=level, 138 108 faccode=faccode, depcode=depcode) … … 393 363 grok.name('studylevelsoverview') 394 364 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)]) 399 366 400 367 #: Fieldnames considered by this exporter … … 402 369 'state', 'certcode', 'faccode', 'depcode', 'is_postgrad', 403 370 'entry_session', 'current_level', 'current_session', 404 ) + level_range_tuple371 ) + avail_levels 405 372 406 373 #: The title under which this exporter will be displayed … … 408 375 409 376 def mangle_value(self, value, name, context=None): 410 if name in self. level_range_tupleand context is not None:377 if name in self.avail_levels and context is not None: 411 378 value = '' 412 379 for level in context['studycourse'].values():
Note: See TracChangeset for help on using the changeset viewer.