- Timestamp:
- 28 Jan 2008, 15:53:22 (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
WAeUP_SRP/base/WAeUPTool.py
r3053 r3057 1595 1595 security.declareProtected(ModifyPortalContent,'mass_edit_course_result') ###( 1596 1596 def mass_edit_course_result(self,mapping): 1597 #import pdb;pdb.set_trace()1598 # if getattr(self,'_v_courses',None) is None:1599 # res = self.courses_catalog()1600 # self._v_courses = {}1601 # for brain in res:1602 # self._v_courses[brain.code] = brain1603 # course_id = mapping.get('code')1604 # if course_id not in self._v_courses.keys():1605 # return '', "No course with ID: %s" % did1606 1597 id_key = '' 1607 1598 for id_key in ('student_id','matric_no'): … … 1623 1614 code = mapping['code'] 1624 1615 mapping['key'] = key = "%(student_id)s|%(level_id)s|%(code)s" % vars() 1625 # for k in ('semester',):1626 # mapping[k] = getattr(self._v_courses[course_id],k)1627 1616 try: 1628 1617 self.course_results.modifyRecord(**mapping) 1629 1618 except KeyError: 1630 1619 return '', "No course result to edit: %s" % key 1620 return key,'' 1621 ###) 1622 1623 security.declareProtected(ModifyPortalContent,'mass_delete_course_result') ###( 1624 def mass_delete_course_result(self,mapping): 1625 id_key = '' 1626 for id_key in ('student_id','matric_no'): 1627 id_field = mapping.get(id_key,None) 1628 if id_field is not None: 1629 student_id = id_field 1630 break 1631 query = Eq(id_key,id_field) 1632 res = self.students_catalog.evalAdvancedQuery(query) 1633 if not res: 1634 return '', "No student with %(id_field)s: %(id_key)s" % vars() 1635 if id_field != "student_id": 1636 mapping['student_id'] = res[0].id 1637 if not res: 1638 return '', "no student with %(id_key)s %(id_field)s" % vars() 1639 student_rec = res[0] 1640 student_id = student_rec.id 1641 level_id = mapping['level_id'] 1642 code = mapping['code'] 1643 key = "%(student_id)s|%(level_id)s|%(code)s" % vars() 1644 # for k in ('semester',): 1645 # mapping[k] = getattr(self._v_courses[course_id],k) 1646 if self.course_results.getRecordByKey(key) is None: 1647 return '', "no course-result with %(key)s" % vars() 1648 self.course_results.deleteRecord(key) 1631 1649 return key,'' 1632 1650 ###) … … 2036 2054 mode = "create" 2037 2055 if edit: 2038 mode = "edit" 2056 if filename.endswith('_toDelete'): 2057 mode = "delete" 2058 else: 2059 mode = "edit" 2039 2060 importer_name = "mass_%(mode)s_%(name)s" % vars() 2040 2061 importer = getattr(self, '%s' % importer_name,None) … … 2111 2132 tr_count += 1 2112 2133 total_imported += 1 2113 logger.info("%(total_imported)d of %(total)d %(em)s" % vars())2134 logger.info("%(total_imported)d %(mode)sed of %(total)d %(em)s" % vars()) 2114 2135 2115 2136 if total and not total % commit_after: … … 2135 2156 open("%s/import/%s_not_imported%s.csv" % (i_home,filename,current),"a").write( 2136 2157 '\n'.join(not_imported)) 2137 em = "Finished import from %s.csv: %d imported, %d not imported (of total %d)" % (filename,total_imported,total_not_imported,total) 2158 if mode == 'delete': 2159 mode = 'delet' 2160 em = "Finished %(mode)sing from %(filename)s.csv: %(total_imported)d %(mode)sed, %(total_not_imported)d not %(mode)sed (of total %(total)d)" % vars() 2138 2161 logger.info(em) 2139 2162 return em
Note: See TracChangeset for help on using the changeset viewer.