Changeset 4161
- Timestamp:
- 24 May 2009, 10:12:58 (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
waeup/branches/ulif-rewrite/src/waeup/university/facultycontainer.py
r4132 r4161 3 3 from zope.component.factory import Factory 4 4 from zope.component.interfaces import Invalid, IFactory 5 from zope.component import createObject 5 6 from zope.exceptions import DuplicationError 6 7 from zope.interface import implementedBy 7 from waeup.interfaces import IFacultyContainer, IFaculty 8 from waeup.interfaces import IFacultyContainer, IFaculty, IWAeUPCSVImporter 9 from waeup.utils.importexport import CSVImporter 8 10 from waeup.viewlets import MainArea, LeftSidebar, Index, Add, FormWrapMixin 9 11 … … 22 24 id = str(self.next_id) 23 25 self[id] = faculty 24 while s elf.next_idin self.keys():26 while str(self.next_id) in self.keys(): 25 27 # Look for next unused int... 26 28 self.next_id += 1 27 29 return id 30 31 def clear(self): 32 keys = self.keys() 33 for key in keys: 34 del self[key] 35 next_id = 0L 28 36 29 37 class FacultyContainerFactory(grok.GlobalUtility): … … 40 48 def getInterfaces(self): 41 49 return implementedBy(FacultyContainer) 50 51 class FacultyCSVImporter(CSVImporter): 52 """Importer to import CSV data into faculty containers. 53 """ 54 grok.context(FacultyContainer) 55 grok.implements(IWAeUPCSVImporter) 56 datatype = u'Faculty importer' 57 column_terms = ['code', 'title', 'title_prefix'] 58 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)) 66 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) 70 return 71 42 72 43 73 # … … 67 97 @grok.action('Add faculty') 68 98 def addFaculty(self, **data): 69 faculty = getUtility(IFaculty)99 faculty = createObject(u'waeup.Faculty') 70 100 self.applyData(faculty, **data) 71 101 try: … … 104 134 def render(self): 105 135 return u'<div class="portlet"><a href="add">Add faculty</a></div>' 136 137
Note: See TracChangeset for help on using the changeset viewer.