Changeset 3143
- Timestamp:
- 11 Feb 2008, 23:05:17 (17 years ago)
- Location:
- WAeUP_SRP
- Files:
-
- 2 added
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
WAeUP_SRP/base/WAeUPTool.py
r3141 r3143 711 711 "do it" 712 712 files = [file for file in os.listdir("%s/import/" % (i_home)) 713 if file.endswith('.csv') and file.find('imported') == -1] 713 if file.endswith('.csv') and (file.find('imported') == -1 and 714 file.find('pending') == -1)] 714 715 return files 715 716 ###) … … 1596 1597 security.declareProtected(ModifyPortalContent,'mass_edit_course_result') ###( 1597 1598 def mass_edit_course_result(self,mapping): 1599 #import pdb;pdb.set_trace() 1598 1600 while True: 1599 1601 result_id = mapping.get('id',None) … … 1610 1612 if not res: 1611 1613 return '', "No student with %(id_key)s %(id_field)s" % vars() 1612 if id_field != "student_id":1614 if id_field == "matric_no": 1613 1615 mapping['student_id'] = res[0].id 1616 elif id_field == "student_id": 1617 mapping['matric_no'] = res[0].matric_no 1614 1618 if not res: 1615 1619 return '', "No student with %(id_key)s %(id_field)s" % vars() … … 1623 1627 self.course_results.modifyRecord(**mapping) 1624 1628 except KeyError: 1625 return key, "No course result to edit: %s" % key 1629 return key, "No course result to edit: %s" % key,mapping 1626 1630 return key,'' 1627 1631 ###) … … 1965 1969 student_record.matric_no, 1966 1970 matric_no) 1971 mapping['matric_no'] = student_record.matric_no 1967 1972 elif matric_no: 1968 1973 res = self.students_catalog(matric_no = matric_no) … … 1980 1985 current_session = d['session'] = mapping.get('current_session','') 1981 1986 if current_session and student_record.session != current_session: 1982 return student_id,'student %s: imported session %s does not match current_session %s' % (student_id,1987 msg = 'student %s: imported session %s does not match current_session %s' % (student_id, 1983 1988 current_session, 1984 1989 student_record.session) 1990 return student_id,msg,mapping 1985 1991 current_level = mapping.get('current_level','') 1986 1992 if not current_level.isdigit(): 1987 1993 return '','student %s: imported level is empty' % (student_id,) 1988 1994 if current_level and student_record.level != current_level: 1989 return student_id,'student %s: imported level %s does not match current_level %s' % (student_id,1995 msg = 'student %s: imported level %s does not match current_level %s' % (student_id, 1990 1996 current_level, 1991 1997 student_record.level) 1998 return student_id,msg,mapping 1992 1999 student_review_state = student_record.review_state 1993 2000 if student_review_state == 'deactivated': 1994 2001 return '',"student %s in review_state %s" % (student_id, student_review_state) 1995 2002 if student_review_state not in ('courses_validated','returning'): 1996 return student_id,"student %s in wrong review_state %s" % (student_id, student_review_state) 2003 msg = "student %s in wrong review_state %s" % (student_id, student_review_state) 2004 return student_id,msg,mapping 1997 2005 student_obj = getattr(students_folder,student_id) 1998 2006 f2t = self.field2types_student … … 2035 2043 logger = logging.getLogger('WAeUPTool.importData') 2036 2044 current = DateTime.DateTime().strftime("%d-%m-%y_%H_%M_%S") 2045 import_date = DateTime.DateTime().strftime("%d/%m/%y %H:%M:%S") 2037 2046 students_folder = self.portal_url.getPortalObject().campus.students 2038 2047 start = True … … 2079 2088 return em 2080 2089 pending_fn = "%s/import/%ss_pending.csv" % (i_home,name) 2090 pending_imported_fn = "%s/import/%ss_pending_imported%s.csv" % (i_home,name,current) 2081 2091 if pending_only: 2082 2092 import_source_fn = pending_fn … … 2097 2107 diff2layout = set(import_keys).difference(set(layout.keys())) 2098 2108 if diff2schema and diff2schema != set(['id',]): 2099 #import pdb;pdb.set_trace()2100 2109 msg = 'not ignorable key(s): "%s" found in heading' % ", ".join(diff2schema) 2101 2110 return msg 2102 if mode == "create":2111 if mode in ("create","edit"): 2103 2112 required_keys = [layout.getIdUnprefixed(id) 2104 2113 for id,widget in layout.objectItems() … … 2137 2146 pending_records = {} 2138 2147 imports_pending = 0 2148 total_pending_imported = 0 2139 2149 total_pending = 0 2140 2150 format = ','.join(['"%%(%s)s"' % fn for fn in import_keys]) … … 2143 2153 imported = [] 2144 2154 if name in ('verdict','course_result',): 2145 #global pending_records 2146 pending_keys = imported_keys[:] 2155 #pending_keys = imported_keys[:] 2156 sname = "%s_pending" % iname 2157 pending_schema = stool._getOb(sname) 2158 if schema is None: 2159 em = 'No such pending_schema %s' % sname 2160 logger.error('No such schema %s' % sname) 2161 return em 2162 pending_keys = pending_schema.keys() 2147 2163 pending_keys += "Error", 2164 if 'id' not in pending_keys: 2165 pending_keys.insert(0,'id') 2148 2166 pending_records = {} 2149 2167 if os.path.exists(pending_fn): … … 2157 2175 new_imports_pending = 0 2158 2176 pending_imported = [] 2159 for item in pending_records.values(): 2160 id,error = importer(item) 2161 if error: 2162 continue 2163 else: 2164 if item.has_key('Error'): 2165 del item['Error'] 2166 imported.append(item) 2177 if pending_only: 2178 pending_imported_ids = [] 2179 pending_imported = [] 2180 for item in pending_records.values(): 2181 results = importer(item) 2182 id = results[0] 2183 error = results[1] 2184 is_pending = len(results) == 3 2185 if is_pending: 2186 continue 2167 2187 msg = format % item 2168 2188 logger.info("imported from %(pending_fn)s %(msg)s" % vars()) 2169 pending_imported += id,2170 continue2171 total_imported = len(pending_imported)2172 logger.info("imported %d pending imports" % len(pending_imported))2173 for id in pending_imported:2174 del pending_records[id]2189 pending_imported.append(item) 2190 pending_imported_ids += id, 2191 total_pending_imported = len(pending_imported_ids) 2192 logger.info("imported %d pending imports" % len(pending_imported_ids)) 2193 for id in pending_imported_ids: 2194 del pending_records[id] 2175 2195 pending_imports_file = open(pending_fn,'w') 2176 2196 pending_csv_writer = csv.DictWriter(pending_imports_file, … … 2179 2199 mapping = dict((k,k) for k in pending_keys) 2180 2200 pending_csv_writer.writerow(mapping) 2201 if len(pending_imported) > 0: 2202 pending_imported_file = open(pending_imported_fn,'w') 2203 pending_imported_csv_writer = csv.DictWriter(pending_imported_file, 2204 pending_keys, 2205 extrasaction='ignore') 2206 pending_imported_csv_writer.writerow(dict((k,k) for k in imported_keys)) 2207 pending_imported_csv_writer.writerows(pending_imported) 2181 2208 # 2182 2209 if pending_only: … … 2215 2242 temp_item = item.copy() 2216 2243 temp_item.update(dm) 2217 id,error = importer(temp_item) 2218 if error: 2244 #id,error = importer(temp_item) 2245 results = importer(temp_item) 2246 id = results[0] 2247 error = results[1] 2248 is_pending = len(results) == 3 2249 if is_pending: 2250 temp_item = results[2] 2251 temp_item['Error'] = error 2252 msg = format_error % temp_item 2253 if id not in pending_records.keys(): 2254 temp_item['id'] = id 2255 pending_records[id] = temp_item 2256 logger.info("%(id)s added to pending %(msg)s" % vars()) 2257 new_imports_pending += 1 2258 else: 2259 logger.info("%(id)s already in pending %(msg)s" % vars()) 2260 continue 2261 elif error: 2219 2262 item['Error'] = error 2220 if id: 2221 if id not in pending_records.keys(): 2222 item['id'] = id 2223 pending_records[id] = item 2224 msg = format_error % item 2225 logger.info("%(id)s added to pending %(msg)s" % vars()) 2226 new_imports_pending += 1 2227 else: 2228 logger.info("%(id)s already in pending %(msg)s" % vars()) 2229 continue 2230 else: 2231 not_imported.append(item) 2232 total_not_imported += 1 2233 continue 2263 not_imported.append(item) 2264 total_not_imported += 1 2265 continue 2234 2266 item = temp_item 2235 2267 item['id'] = id … … 2267 2299 msg += "%(total_imported)d imported, %(total_not_imported)d not imported " % vars() 2268 2300 if total_pending: 2269 msg += "%(new_imports_pending)d pending added, %(total_pending)d total pending in %(pending_fn)s " % vars() 2301 msg += "%(new_imports_pending)d pending added, %(total_pending_imported)d pending imported " % vars() 2302 msg += "%(total_pending)d total pending in %(pending_fn)s " % vars() 2270 2303 msg += "(of total %(total)d)" % vars() 2271 2304 logger.info(msg) -
WAeUP_SRP/uniben/profiles/default/layouts/import_course_result.xml
r2778 r3143 75 75 <element value="session_id"/> 76 76 </property> 77 <property name="is_required"> True</property>77 <property name="is_required">False</property> 78 78 <property name="label">session</property> 79 79 <property name="label_edit">session</property> … … 129 129 <element value="score"/> 130 130 </property> 131 <property name="is_required">True</property> 131 132 <property name="label">Score</property> 132 133 <property name="label_edit">Score</property> … … 135 136 <property name="hidden_layout_modes"/> 136 137 <property name="hidden_readonly_layout_modes"/> 138 <property name="min_value">1</property> 139 <property name="max_value">100</property> 137 140 </widget> 138 141 -
WAeUP_SRP/uniben/profiles/default/layouts/import_verdict.xml
r3055 r3143 11 11 <property name="title">Id</property> 12 12 <property name="fields"> 13 <element value=" student_id"/>13 <element value="id"/> 14 14 </property> 15 15 <property name="is_required">False</property> -
WAeUP_SRP/uniben/profiles/default/schemas.xml
r3139 r3143 15 15 <object name="import_course" meta_type="CPS Schema"/> 16 16 <object name="import_course_result" meta_type="CPS Schema"/> 17 <object name="import_course_result_pending" meta_type="CPS Schema"/> 17 18 <object name="import_department" meta_type="CPS Schema"/> 18 19 <object name="import_faculty" meta_type="CPS Schema"/> … … 20 21 <object name="import_student" meta_type="CPS Schema"/> 21 22 <object name="import_verdict" meta_type="CPS Schema"/> 23 <object name="import_verdict_pending" meta_type="CPS Schema"/> 22 24 23 25 <object name="course" meta_type="CPS Schema"/>
Note: See TracChangeset for help on using the changeset viewer.