Changeset 1820
- Timestamp:
- 24 May 2007, 15:44:59 (18 years ago)
- Location:
- WAeUP_SRP/trunk
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
WAeUP_SRP/trunk/Students.py
r1816 r1820 17 17 from Products.WAeUP_SRP.Academics import makeCertificateCode 18 18 from Products.AdvancedQuery import Eq, Between, Le,In 19 import DateTime 19 20 import logging 20 21 import csv,re,os … … 420 421 ###) 421 422 423 security.declareProtected(ModifyPortalContent,"transferStudents")###( 424 def transferStudents(self,filename): 425 """ 426 load Interfaculty transferStudents Studentdata from CSV values. 427 """ 428 import transaction 429 import random 430 current = DateTime.DateTime().strftime("%d-%m-%y_%H_%M_%S") 431 pm = self.portal_membership 432 member = pm.getAuthenticatedMember() 433 logger = logging.getLogger('Students.StudentsFolder.transferStudents') 434 #students_folder = self.portal_catalog({'meta_type': 'StudentsFolder'})[-1].getObject() 435 students_folder = self.portal_url.getPortalObject().campus.students 436 csv_fields = ('old_matric_no', 437 'matric_no', 438 'study_course', 439 'current_mode', 440 'current_level', 441 ) 442 tr_count = 0 443 total = 0 444 total_imported = 0 445 total_not_imported = 0 446 imported = [] 447 not_imported = [] 448 certs = {} 449 try: 450 results = csv.DictReader(open("%s/import/%s.csv" % (i_home,filename),"rb")) 451 except: 452 logger.error('Error reading %s.csv' % filename) 453 return 454 start = True 455 for result in results: 456 total += 1 457 if start: 458 start = False 459 logger.info('%s starts import from %s.csv' % (member,filename)) 460 import_keys = [k for k in result.keys() if not k.startswith('ignore')] 461 diff2schema = set(import_keys).difference(set(csv_fields)) 462 if diff2schema: 463 em = "not ignorable key(s) %s found in heading" % diff2schema 464 return em 465 s = ','.join(['"%s"' % fn for fn in import_keys]) 466 open("%s/import/%s_not_imported%s.csv" % (i_home,filename,current),"a").write(s + ',"Error"'+ '\n') 467 s = '"id",' + s 468 open("%s/import/%s_imported%s.csv" % (i_home,filename,current),"a").write(s + '\n') 469 format = ','.join(['"%%(%s)s"' % fn for fn in import_keys]) 470 format_error = format + ',"%(Error)s"' 471 format = '"%(id)s",'+ format 472 old_matric_no = result.get('old_matric_no') 473 res = self.students_catalog(matric_no = old_matric_no) 474 result['id'] = "None" 475 if not res: 476 em = 'Student with Matric_no %s not found' % old_matric_no 477 logger.info(em) 478 result['Error'] = "Student not exists" 479 not_imported.append(format_error % result) 480 total_not_imported += 1 481 continue 482 student_brain = res[0] 483 student_object = getattr(students_folder,student_brain.id) 484 result['id'] = student_brain.id 485 cert_id = makeCertificateCode(result.get('study_course')) 486 if cert_id not in certs.keys(): 487 res = self.portal_catalog(meta_type = "Certificate",id = cert_id) 488 if not res: 489 em = 'No Certificate with ID %s \n' % cert_id 490 logger.info(em) 491 result['Error'] = "No Certificate %s" % cert_id 492 not_imported.append( format_error % result) 493 total_not_imported += 1 494 continue 495 cert = res[0] 496 cert_path = cert.getPath().split('/') 497 certificate = certs[cert_id] = {'faculty': cert_path[-4], 498 'department': cert_path[-3]} 499 cert_doc = certs[cert_id] 500 clearance = getattr(student_object,'clearance',None) 501 if clearance is None: 502 em = 'Student has no clearance object' 503 logger.info(em) 504 result['Error'] = em 505 not_imported.append( format_error % result) 506 total_not_imported += 1 507 continue 508 clearance_doc = clearance.getContent() 509 study_course = student_object.study_course 510 study_course_doc = study_course.getContent() 511 old_study_course = study_course_doc.study_course 512 old_current_level = study_course_doc.current_level 513 current_level = result.get('current_level',None) 514 try: 515 icl = int(current_level) 516 except: 517 em = 'Invalid new level %s' % current_level 518 logger.info(em) 519 result['Error'] = em 520 not_imported.append( format_error % result) 521 total_not_imported += 1 522 continue 523 if icl <= int(old_current_level) and study_course.objectIds(): 524 em = 'Already registered level %s new %s' % (old_current_level,current_level) 525 logger.info(em) 526 result['Error'] = em 527 not_imported.append( format_error % result) 528 total_not_imported += 1 529 continue 530 #from pdb import set_trace; set_trace() 531 cd = {} 532 matric_no_history = getattr(clearance_doc,'matric_no_history',[]) 533 if not matric_no_history: 534 matric_no_history = [] 535 matric_no_history.append(old_matric_no) 536 cd['matric_no_history'] = matric_no_history 537 cd['matric_no'] = result.get('matric_no') 538 clearance_doc.edit(mapping = cd) 539 dsc = {} 540 study_course_history = getattr(study_course_doc,'study_course_history',[]) 541 if not study_course_history: 542 study_course_history = [] 543 study_course_history.append(old_study_course) 544 dsc['study_course_history'] = study_course_history 545 dsc['study_course'] = result.get('study_course') 546 dsc['current_level'] = current_level 547 dsc['current_mode'] = result.get('current_mode') 548 study_course_doc.edit(mapping=dsc) 549 imported.append( format % result) 550 tr_count += 1 551 total_imported += 1 552 if tr_count > 1000: 553 if len(not_imported) > 0: 554 open("%s/import/%s_not_imported%s.csv" % (i_home,filename,current),"a").write( 555 '\n'.join(not_imported) + '\n') 556 not_imported = [] 557 if len(imported) > 0: 558 open("%s/import/%s_imported%s.csv" % (i_home,filename,current),"a").write( 559 '\n'.join(imported) + '\n') 560 imported = [] 561 em = '%d transactions committed\n' % (tr_count) 562 transaction.commit() 563 regs = [] 564 logger.info(em) 565 tr_count = 0 566 if len(imported) > 0: 567 open("%s/import/%s_imported%s.csv" % (i_home,filename,current),"a").write( 568 '\n'.join(imported)) 569 if len(not_imported) > 0: 570 open("%s/import/%s_not_imported%s.csv" % (i_home,filename,current),"a").write( 571 '\n'.join(not_imported)) 572 em = "Imported: %d, not imported: %d of total %d" % (total_imported,total_not_imported,total) 573 logger.info(em) 574 return self.REQUEST.RESPONSE.redirect("%s" % self.REQUEST.get('URL1')) 575 ###) 576 422 577 security.declareProtected(ModifyPortalContent,"importReturningStudents")###( 423 578 def importReturningStudents(self): … … 1134 1289 d['core_or_elective'] = getattr(c.getObject().getContent(),'core_or_elective') 1135 1290 course_result.getContent().edit(mapping=d) 1136 transaction.commit()1291 #transaction.commit() 1137 1292 ###) 1138 1293 -
WAeUP_SRP/trunk/Widgets.py
r1814 r1820 175 175 ###) 176 176 177 class WAeUPStudyModeWidget(CPSSelectWidget): ###( 178 """WAeUP StudyMode widget.""" 179 meta_type = 'WAeUP StudyMode Widget' 180 vocabulary = 'entry_modes' 181 182 def _getStudyModes(self): 183 voc = getattr(self.portal_vocabularies,self.vocabulary) 184 d = {} 185 for k,v in voc.items(): 186 d[k] = v 187 return d 188 189 def validate(self, datastructure, **kw): 190 """Validate datastructure and update datamodel.""" 191 widget_id = self.getWidgetId() 192 value = datastructure[widget_id] 193 try: 194 v = str(value) 195 except ValueError: 196 datastructure.setError(widget_id, "'%s' not a valid session key" % value) 197 return 0 198 studymodes = self._getStudyModes() 199 if not value: 200 v = value = 'ume_ft' 201 #import pdb;pdb.set_trace() 202 if not studymodes.has_key(value): 203 datastructure.setError(widget_id, "'%s' not a valid session key" % v) 204 return 0 205 if self.is_required and not len(v): 206 datastructure.setError(widget_id, "session key required") 207 return 0 208 209 datamodel = datastructure.getDataModel() 210 datamodel[self.fields[0]] = v 211 return 1 212 213 def render(self, mode, datastructure, **kw): 214 """Render in mode from datastructure.""" 215 value = datastructure[self.getWidgetId()] 216 studymodes = self._getStudyModes() 217 if mode == 'view': 218 return escape(studymodes.get(value, value)) 219 elif mode == 'edit': 220 html_widget_id = self.getHtmlWidgetId() 221 res = renderHtmlTag('select', name=html_widget_id, id=html_widget_id) 222 in_selection = 0 223 vocabulary_items = studymodes.items() 224 if self.sorted: 225 vocabulary_items.sort(key=operator.itemgetter(1)) 226 for k, v in vocabulary_items: 227 kw = {'value': k, 'contents': v} 228 if value == k: 229 kw['selected'] = 'selected' 230 in_selection = 1 231 res += renderHtmlTag('option', **kw) 232 if value and not in_selection: 233 kw = {'value': value, 'contents': 'invalid: '+ str(value), 234 'selected': 'selected'} 235 res += renderHtmlTag('option', **kw) 236 res += '</select>' 237 return res 238 raise RuntimeError('unknown mode %s' % mode) 239 240 InitializeClass(WAeUPStudyModeWidget) 241 242 widgetRegistry.register(WAeUPStudyModeWidget) 243 244 ###) 245 177 246 class WAeUPSessionWidget(CPSSelectWidget): ###( 178 247 """WAeUP Session widget.""" … … 320 389 # XXX make a menu for the vocabulary. 321 390 vocabulary = 'verdicts' 322 translated = False323 sorted = False324 391 325 392 # Associating the widget label with an input area to improve the widget -
WAeUP_SRP/trunk/profiles/default/layouts/student_clearance.xml
r1735 r1820 305 305 <property name="hidden_readonly_layout_modes"/> 306 306 </widget> 307 <widget name="fst_sit_date" meta_type="Date Widget"> 307 <widget name="matric_no_history" meta_type="String Widget"> 308 <property name="title">Previous Matric No(s)</property> 309 <property name="fields"> 310 <element value="matric_no_history"/> 311 </property> 312 <property name="label">Previous Matric No(s)</property> 313 <property name="label_edit">Previous Matric No(s)</property> 314 <property name="readonly_layout_modes"/> 315 <property name="hidden_layout_modes"> 316 <element value="create"/> 317 </property> 318 <property name="hidden_readonly_layout_modes"/> 319 </widget> 320 <widget name="fst_sit_date" meta_type="Date Widget"> 308 321 <property name="title">Exam Date</property> 309 322 <property name="fields"> … … 742 755 </row> 743 756 <row> 757 <cell name="matric_no_history"/> 758 </row> 759 <row> 744 760 <cell name="clr_ac_pin"/> 745 761 </row> -
WAeUP_SRP/trunk/profiles/default/layouts/student_clearance_fe.xml
r1735 r1820 293 293 <property name="allow_resize">True</property> 294 294 </widget> 295 <widget name="form_matric_no" meta_type="String Widget"> 296 <property name="title">Former Matric/RegNo </property> 297 <property name="fields"> 298 <element value="form_matric_no"/> 299 </property> 300 <property name="label">Former Matric/RegNo</property> 301 <property name="label_edit">Former Matric/RegNo</property> 302 <property name="readonly_layout_modes"/> 303 <property name="hidden_layout_modes"> 304 <element value="create"/> 305 </property> 306 <property name="hidden_readonly_layout_modes"/> 307 </widget> 295 <widget name="matric_no_history" meta_type="Lines Widget"> 296 <property name="title">Previous Matric No(s)</property> 297 <property name="fields"> 298 <element value="matric_no_history"/> 299 </property> 300 <property name="label">Previous Matric No(s)</property> 301 <property name="label_edit">Previous Matric No(s)</property> 302 <property name="readonly_layout_modes"/> 303 <property name="hidden_layout_modes"> 304 <element value="create"/> 305 </property> 306 <property name="hidden_readonly_layout_modes"/> 307 <property name="width">50</property> 308 <property name="height">2</property> 309 </widget> 308 310 <widget name="fst_sit_date" meta_type="Date Widget"> 309 311 <property name="title">Exam Date</property> … … 746 748 </row> 747 749 <row> 750 <cell name="matric_no_history"/> 751 </row> 752 <row> 748 753 <cell name="clr_ac_pin"/> 749 754 </row> -
WAeUP_SRP/trunk/profiles/default/layouts/student_study_course.xml
r1752 r1820 20 20 <property name="hidden_readonly_layout_modes"/> 21 21 </widget> 22 <widget name="current_session" meta_type="Select Widget"> 22 <widget name="study_course_history" meta_type="Lines Widget"> 23 <property name="title">Previous Studies</property> 24 <property name="fields"> 25 <element value="study_course_history"/> 26 </property> 27 <property name="label">Previous Studies</property> 28 <property name="label_edit">Previous Studies</property> 29 <property name="readonly_layout_modes"/> 30 <property name="hidden_layout_modes"/> 31 <property name="hidden_readonly_layout_modes"/> 32 <property name="width">50</property> 33 <property name="height">2</property> 34 </widget> 35 <widget name="current_session" meta_type="Select Widget"> 23 36 <property name="title">Current Study session</property> 24 37 <property name="fields"> … … 77 90 </row> 78 91 <row> 92 <cell name="study_course_history"/> 93 </row> 94 <row> 79 95 <cell name="current_session"/> 80 96 </row> -
WAeUP_SRP/trunk/profiles/default/schemas/student_clearance.xml
r1735 r1820 9 9 <field name="matric_no" meta_type="CPS String Field"> 10 10 <property name="is_searchabletext">True</property> 11 </field> 12 13 <field name="matric_no_history" meta_type="CPS String List Field"> 11 14 </field> 12 15 -
WAeUP_SRP/trunk/profiles/default/schemas/student_study_course.xml
r1705 r1820 6 6 <property name="is_searchabletext">True</property> 7 7 </field> 8 <field name="study_course_history" meta_type="CPS String List Field"> 9 </field> 8 10 <field name="current_session" meta_type="CPS String Field"/> 9 11 <field name="current_mode" meta_type="CPS String Field"/>
Note: See TracChangeset for help on using the changeset viewer.