Changeset 7732
- Timestamp:
- 29 Feb 2012, 18:34:38 (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
main/waeup.sirp/trunk/src/waeup/sirp/university/export.py
r7728 r7732 10 10 """ 11 11 grok.implements(ICSVExporter) 12 grok.name(' Faculty Exporter')12 grok.name('faculties') 13 13 14 14 #: Fieldnames considered by this exporter … … 66 66 return 67 67 68 def export(self, facult y, filepath=None):69 """Export single `faculty`as CSV file.68 def export(self, faculties, filepath=None): 69 """Export `faculties`, an iterable, as CSV file. 70 70 71 71 If `filepath` is ``None``, a raw string with CSV data is returned. 72 72 """ 73 73 writer, outfile = self.get_csv_writer(filepath) 74 self.write_item(faculty, writer) 74 for faculty in faculties: 75 self.write_item(faculty, writer) 75 76 return self.close_outfile(filepath, outfile) 76 77 … … 82 83 writer, outfile = self.get_csv_writer(filepath) 83 84 faculties = site.get('faculties', {}) 85 return self.export(faculties.values(), filepath) 84 86 for faculty in faculties.values(): 85 87 self.write_item(faculty, writer) 86 88 return self.close_outfile(filepath, outfile) 89 90 class DepartmentExporter(FacultyExporter, grok.GlobalUtility): 91 """Exporter for departments. 92 """ 93 grok.implements(ICSVExporter) 94 grok.name('departments') 95 96 #: Fieldnames considered by this exporter 97 fields = ('code', 'faculty', 'title', 'title_prefix') 98 99 def mangle_value(self, value, name, context=None): 100 """Hook for mangling values in derived classes 101 """ 102 if name == 'faculty': 103 value = getattr( 104 getattr(context, '__parent__', None), 105 'code', None) 106 return super(DepartmentExporter, self).mangle_value( 107 value, name, context) 108 109 def export_all(self, site, filepath=None): 110 """Export faculties in facultycontainer into filepath as CSV data. 111 112 If `filepath` is ``None``, a raw string with CSV data is returned. 113 """ 114 writer, outfile = self.get_csv_writer(filepath) 115 faculties = site.get('faculties', {}) 116 for faculty in faculties.values(): 117 for department in faculty.values(): 118 self.write_item(department, writer) 119 return self.close_outfile(filepath, outfile)
Note: See TracChangeset for help on using the changeset viewer.