Changeset 4222 for waeup/branches/ulif-rewrite
- Timestamp:
- 8 Jun 2009, 16:58:41 (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
waeup/branches/ulif-rewrite/src/waeup/university/facultycontainer.py
r4161 r4222 6 6 from zope.exceptions import DuplicationError 7 7 from zope.interface import implementedBy 8 from waeup.csvfile import CSVFile 9 from waeup.csvfile.interfaces import ICSVFile 8 10 from waeup.interfaces import IFacultyContainer, IFaculty, IWAeUPCSVImporter 9 11 from waeup.utils.importexport import CSVImporter 10 12 from waeup.viewlets import MainArea, LeftSidebar, Index, Add, FormWrapMixin 13 11 14 12 15 class FacultyContainer(grok.Container): … … 49 52 return implementedBy(FacultyContainer) 50 53 54 55 # 56 # CSV import stuff 57 # 58 class IFacultyCSVFile(ICSVFile): 59 """A CSV file that contains faculty data. 60 """ 61 62 class FacultyCSVFile(CSVFile): 63 """An abstraction of a CSV file containing faculties. 64 """ 65 grok.implements(IFacultyCSVFile) 66 grok.provides(IFacultyCSVFile) 67 required_fields = ['code', 'title', 'title_prefix'] 68 51 69 class FacultyCSVImporter(CSVImporter): 52 """ Importer to import CSV datainto faculty containers.70 """Shuffle data from faculty CSV files into faculty containers. 53 71 """ 54 grok.context(FacultyContainer) 72 # Tell, what kinds of objects we connect... 73 grok.adapts(IFacultyCSVFile, IFacultyContainer) 74 # Tell the world, that we are an importer... 55 75 grok.implements(IWAeUPCSVImporter) 56 datatype = u'Faculty importer' 57 column_terms = ['code', 'title', 'title_prefix'] 76 grok.provides(IWAeUPCSVImporter) 58 77 59 def doImport(self, filepath, clear_old_data=True, overwrite=True): 60 headers, data = self.getData(filepath) 61 if clear_old_data: 62 self.context.clear() 63 keys = self.context.keys() 64 for item in data: 65 data_dict = dict(map(None, headers, item)) 78 datatype = u'Faculty Importer' 79 80 def doImport(self, clear_old_data=True, overwrite=True): 81 # CSVImporter instances have a `csvfile` and a `receiver` 82 # object defined which refer to the CSV file and the container. 83 for row in self.csvfile.getData(): 66 84 new_item = createObject(u'waeup.Faculty') 67 for key, val in data_dict.items():68 setattr(new_item, key, val)69 self. context.addFaculty(new_item)85 for key, val in row.items(): 86 setattr(new_item, key, val) 87 self.receiver.addFaculty(new_item) 70 88 return 89 90 71 91 72 92
Note: See TracChangeset for help on using the changeset viewer.