Changeset 1747 for WAeUP_SRP/trunk
- Timestamp:
- 7 May 2007, 20:56:24 (18 years ago)
- Location:
- WAeUP_SRP/trunk
- Files:
-
- 3 added
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
WAeUP_SRP/trunk/WAeUPTool.py
r1730 r1747 28 28 from OFS.SimpleItem import SimpleItem 29 29 30 from Products.CPSSchemas.DataStructure import DataStructure 31 from Products.CPSSchemas.DataModel import DataModel 32 from Products.CPSSchemas.StorageAdapter import MappingStorageAdapter 30 33 from Products.CMFCore.ActionProviderBase import ActionProviderBase 31 34 from Products.CMFCore.permissions import View … … 34 37 from Products.CMFCore.utils import UniqueObject 35 38 from Products.CMFCore.URLTool import URLTool 39 from Products.CMFCore.utils import getToolByName 36 40 from Students import makeCertificateCode 37 41 from Globals import package_home,INSTANCE_HOME … … 276 280 self.portal_workflow.doActionFor(student_obj,wfaction) 277 281 student_obj.manage_setLocalRoles(sid, ['Owner',]) 278 ## matric_no = dict.get('matric_no')279 ## email = dict.get('email')280 ## #level = dict.get('level')281 ## jamb_reg_no = dict.get('jamb_reg_no')282 ## study_course = dict.get('study_course')283 ## self.portal_workflow.doActionFor(student_obj,wfaction)284 ## student_obj.manage_setLocalRoles(sid, ['Owner',])285 ## student_obj.invokeFactory('StudentApplication','application')286 ## application = student_obj.application287 ## self.portal_workflow.doActionFor(application,'open',dest_container=application)288 ## da = {'Title': 'Application Data'}289 ## student_obj.invokeFactory('StudentPersonal','personal')290 ## da['entry_mode'] = entry_mode291 ## personal = student_obj.personal292 ## self.portal_workflow.doActionFor(personal,'open',dest_container=personal)293 ## dp = {'Title': 'Personal Data'}294 ## student_obj.invokeFactory('StudentClearance','clearance')295 ## clearance = student_obj.clearance296 ## self.portal_workflow.doActionFor(clearance,'open',dest_container=clearance)297 ## dc = {'Title': 'Clearance/Eligibility Record'}298 ## dc['matric_no'] = matric_no299 ## da['app_email'] = dp['email'] = email300 ## da['jamb_reg_no'] = jamb_reg_no301 ## dp['firstname'] = dict.get('firstname')302 ## dp['middlename'] = dict.get('middlename')303 ## dp['lastname'] = dict.get('lastname')304 ## da['jamb_lastname'] = "%(firstname)s %(middlename)s %(lastname)s" % dict305 ## sex = dict.get('sex')306 ## if sex:307 ## da['jamb_sex'] = 'F'308 ## else:309 ## da['jamb_sex'] = 'M'310 ## dp['sex'] = sex311 ## application.getContent().edit(mapping=da)312 ## self.portal_workflow.doActionFor(application,'close',dest_container=application)313 ## personal.getContent().edit(mapping=dp)314 ## clearance.getContent().edit(mapping=dc)315 ## self.portal_workflow.doActionFor(clearance,'close',dest_container=clearance)316 #### catd = {}317 #### catd['id'] = sid318 #### catd['entry_mode']= entry_mode319 #### catd['email'] = email320 #### catd['jamb_reg_no'] = jamb_reg_no321 #### catd['matric_no'] = matric_no322 #### catd['name'] = "%(firstname)s %(middlename)s %(lastname)s" % dp323 #### catd['sex'] = dp['sex']324 #### catd['level'] = level325 #### certificate_brain = self.getCertificateBrain(study_course)326 #### if certificate_brain:327 #### cpath = certificate_brain.getPath().split('/')328 #### catd['faculty'] = cpath[-4]329 #### catd['department'] = cpath[-3]330 #### catd['course'] = study_course331 #### self.students_catalog.addRecord(**catd)332 ## #333 ## # Study Course334 ## #335 ## student_obj.invokeFactory('StudentStudyCourse','study_course')336 ## sc = student_obj.study_course337 ## self.portal_workflow.doActionFor(sc,'open',dest_container=sc)338 ## dsc = {}339 ## dsc['study_course'] = study_course340 ## #dsc['current_level'] = level341 ## sc.getContent().edit(mapping=dsc)342 ##343 282 return sid,password 344 283 ###) … … 757 696 ###) 758 697 698 security.declareProtected(ModifyPortalContent,'create_student') ###( 699 def create_student(self,dict): 700 "create a students data" 701 logger = logging.getLogger('WAeUPTool.create_student') 702 students_folder = self.portal_url.getPortalObject().campus.students 703 jamb_reg_no = dict.get('jamb_reg_no',None) 704 if jamb_reg_no: 705 res = self.students_catalog(jamb_reg_no = jamb_reg_no) 706 if res: 707 return '',"jamb_reg_no exists" 708 matric_no = dict.get('matric_no',None) 709 if matric_no: 710 res = self.students_catalog(matric_no = matric_no) 711 if res: 712 return '',"matric_no exists" 713 sid = self.waeup_tool.generateStudentId('?') 714 students_folder.invokeFactory('Student', sid) 715 student_obj = getattr(students_folder,sid) 716 #password = self.generatePassword() 717 #self.makeStudentMember(sid,password) 718 f2t = self.student_field2types 719 for pt in f2t.keys(): 720 student_obj.invokeFactory(pt,f2t[pt]['id']) 721 sub_obj = getattr(student_obj,f2t[pt]['id']) 722 sub_doc = sub_obj.getContent() 723 self.portal_workflow.doActionFor(sub_obj,'open',dest_container=sub_obj) 724 d = {'Title': f2t[pt]['title']} 725 for field in f2t[pt]['fields']: 726 d[field] = dict.get(field,'') 727 if pt == 'StudentPersonal': 728 d['sex'] = dict.get('sex') == 'F' 729 sub_doc.edit(mapping = d) 730 self.portal_workflow.doActionFor(sub_obj,'close',dest_container=sub_obj) 731 ## entry_session = dict.get('entry_session') 732 ## wfaction = 'return' 733 ## if entry_session == self.getSessionId(): 734 ## wfaction = 'admit' 735 ## self.portal_workflow.doActionFor(student_obj,wfaction) 736 student_obj.manage_setLocalRoles(sid, ['Owner',]) 737 return sid,'' 738 ###) 739 759 740 security.declareProtected(ModifyPortalContent,"importData")###( 760 def importData(self, name):741 def importData(self,filename,name): 761 742 """load data from CSV values""" 762 743 import transaction 763 744 import random 745 logger = logging.getLogger('WAeUPTool.importData') 764 746 current = DateTime.DateTime().strftime("%d-%m-%y_%H_%M_%S") 765 747 students_folder = self.portal_url.getPortalObject().campus.students … … 767 749 tr_count = 1 768 750 total = 0 769 from pdb import set_trace;set_trace()770 751 iname = "import_%s" % name 771 schema = getattr(self.portal_schemas,iname ,None) 752 stool = getToolByName(self, 'portal_schemas') 753 ltool = getToolByName(self, 'portal_layouts') 754 schema = stool._getOb(iname) 772 755 if schema is None: 773 logger.error('No such schema %s' % iname)756 logger.error('No such schema import_%s' % iname) 774 757 return 775 layout = getattr(self.portal_layouts,iname,None)758 layout = ltool._getOb(iname) 776 759 if layout is None: 777 logger.error('No such layout %s' % iname)760 logger.error('No such layout import_%s' % iname) 778 761 return 779 762 validators = {} 780 763 for widget in layout.keys(): 781 764 validators[widget] = layout[widget].validate 782 no_import = [] 765 creator = getattr(self, 'create_%s' % name,None) 766 if creator is None: 767 logger.error('No creator function create_%s' % name) 768 return 769 not_imported = [] 783 770 imported = [] 784 logger = logging.getLogger('WAeUPTool.importData')785 771 try: 786 items = csv.DictReader(open("%s/import/%s.csv" % (i_home, name),"rb"))772 items = csv.DictReader(open("%s/import/%s.csv" % (i_home,filename),"rb")) 787 773 except: 788 logger.error('Error reading %s.csv' % name)774 logger.error('Error reading %s.csv' % filename) 789 775 return 790 776 for item in items: … … 792 778 if start: 793 779 start = False 780 adapters = [MappingStorageAdapter(schema, item)] 781 dm = DataModel(item, adapters,context=self) 794 782 logger.info('Start importing from %s.csv' % name) 795 783 import_keys = item.keys() … … 802 790 logger.error('%s not in layout.' % diff_set) 803 791 return 804 s = ' ,'.join(['"%s"' % fn for fn in import_keys])792 s = '"id",'+','.join(['"%s"' % fn for fn in import_keys]) 805 793 imported.append(s) 806 no _import.append('%s,"Error"' % s)794 not_imported.append('%s,"Error"' % s) 807 795 format = ','.join(['"%%(%s)s"' % fn for fn in import_keys]) 808 796 format_error = format + ',"%(Error)s"' 797 ds = DataStructure(data=item,datamodel=dm) 798 error_string = "" 809 799 for k in import_keys: 810 if validators[k](item): 811 pass 800 if not validators[k](ds): 801 error_string += " %s : %s" % (k,ds.getError(k)) 802 if not error_string: 803 item['id'],error = creator(dm) 804 if error: 805 error_string += error 806 if error_string: 807 item['Error'] = error_string 808 not_imported.append(format_error % item) 809 else: 810 imported.append(format % dm) 812 811 if tr_count > 1000: 813 if len(no_import) > 0: 814 open("%s/import/%s_not_imported%s.csv" % (i_home,name,current),"a").write( 815 '\n'.join(no_import) + '\n') 816 no_import = [] 812 if len(not_imported) > 0: 813 open("%s/import/%s_not_imported%s.csv" % (i_home,filename,current),"a").write( 814 '\n'.join(not_imported) + '\n') 815 not_imported = [] 816 if len(imported) > 0: 817 open("%s/import/%s_imported%s.csv" % (i_home,filename,current),"a").write( 818 '\n'.join(not_imported) + '\n') 819 imported = [] 817 820 em = '%d transactions committed\n' % (tr_count) 818 821 transaction.commit() … … 821 824 total += tr_count 822 825 tr_count = 0 823 open("%s/import/%s_not_imported%s.csv" % (i_home,name,current),"a").write( 824 '\n'.join(no_import)) 826 if len(imported) > 1: 827 open("%s/import/%s_imported%s.csv" % (i_home,filename,current),"a").write( 828 '\n'.join(imported)) 829 if len(not_imported) > 1: 830 open("%s/import/%s_not_imported%s.csv" % (i_home,filename,current),"a").write( 831 '\n'.join(not_imported)) 825 832 return self.REQUEST.RESPONSE.redirect("%s" % self.REQUEST.get('URL1')) 826 833 ###) -
WAeUP_SRP/trunk/Widgets.py
r1718 r1747 14 14 from AccessControl import getSecurityManager 15 15 from Products.WAeUP_SRP.Students import getStudentByRegNo 16 from Products.WAeUP_SRP.Academics import makeCertificateCode 16 17 from re import compile 17 18 import logging … … 255 256 #from Products.zdb import set_trace 256 257 #set_trace() 257 valid = CPSStringWidget.validate(self, datastructure, **kw) 258 ## valid = CPSStringWidget.validate(self, datastructure, **kw) 259 ## if not valid: 260 ## return 0 261 widget_id = self.getWidgetId() 262 value = makeCertificateCode(datastructure[widget_id]).upper() 258 263 id_pat_str = r"\S" 259 264 inv_id_pat = compile(r"^%s$" % id_pat_str) 260 if not valid: 261 return 0 262 else: 263 widget_id = self.getWidgetId() 264 value = datastructure[widget_id].upper() 265 err = 0 266 if len(value.split()) > 1: 267 err = 'Invalid Id, Id contains space(s).' 268 elif not self.portal_catalog(portal_type='Certificate',id=value): 269 err = 'No such certificate' 270 if err: 271 datastructure.setError(widget_id, err) 272 else: 273 datamodel = datastructure.getDataModel() 274 datamodel[self.fields[0]] = value 275 return not err 265 err = 0 266 if len(value.split()) > 1: 267 err = 'Invalid Id, Id contains space(s).' 268 elif not self.portal_catalog(portal_type='Certificate',id=value): 269 err = 'No such certificate' 270 if err: 271 datastructure.setError(widget_id, err) 272 else: 273 datamodel = datastructure.getDataModel() 274 datamodel[self.fields[0]] = value 275 return not err 276 276 277 277 InitializeClass(StudyCourseWidget) … … 342 342 ) 343 343 reference = "student" 344 matric_no_catalog = 'returning_import' 344 345 check_fields = ("Firstname", "Middlename","Lastname") 345 346 def validate(self, datastructure, **kw): … … 347 348 logger = logging.getLogger('Widgets.SecretWidget.validate') 348 349 valid = CPSStringWidget.validate(self, datastructure, **kw) 349 #import pdb;pdb.set_trace()350 350 widget_id = self.getWidgetId() 351 351 value = datastructure[widget_id].upper() 352 352 err = 0 353 353 record = datastructure.get(self.reference,None) 354 #import pdb;pdb.set_trace() 354 355 if not valid or len(value) < 2: 355 356 err = 'Invalid String' … … 363 364 if len(cv.split()) > 1: 364 365 for splited in cv.split(): 365 cvs.append(splited )366 cvs.append(splited.strip()) 366 367 else: 367 368 cvs.append(cv) 369 for cv in cvs: 368 370 if cv == value.upper(): 369 371 found = True … … 391 393 """ MatricNo Widget""" 392 394 meta_type = "MatricNo Widget" 395 396 _properties = CPSStringWidget._properties + ( 397 {'id': 'matric_no_catalog', 'type': 'string', 'mode': 'w', 398 'label': 'Catalog to search for MatricNo'}, 399 { 'id': 'results_catalog', 'type': 'string', 'mode': 'w', 400 'label': 'Results Catalog'}, 401 ) 402 matric_no_catalog = "" #the catalog to search for matric_no 403 results_import = "results_import" #results catalog 404 393 405 def validate(self, datastructure, **kw): 394 406 """Validate datastructure and update datamodel.""" 407 #import pdb;pdb.set_trace() 395 408 valid = CPSStringWidget.validate(self, datastructure, **kw) 396 409 logger = logging.getLogger('Widgets.MatricNoWidget.validate') 397 #import pdb;pdb.set_trace() 398 returning = self.returning_import 399 results = self.results_import 410 returning = getattr(self,self.matric_no_catalog) 411 results = getattr(self,self.results_catalog,None) 400 412 err = 0 401 413 widget_id = self.getWidgetId() … … 412 424 logger.info('matric_no %s not found' % value) 413 425 err = 'No student with matric_no %s.' % (value) 414 continue426 break 415 427 datastructure['student'] = res[0] 416 res = results(matric_no = value) 417 if len(res) < 1: 418 err = 'No results with matric_no %s.' % (value) 419 continue 420 datastructure['results'] = res 428 if results is not None: 429 res = results(matric_no = value) 430 if len(res) < 1: 431 err = 'No results with matric_no %s.' % (value) 432 continue 433 datastructure['results'] = res 421 434 break 422 435 if err: -
WAeUP_SRP/trunk/profiles/default/layouts.xml
r1728 r1747 29 29 <object name="student_course_result" meta_type="CPS Layout"/> 30 30 <object name="student_create" meta_type="CPS Layout"/> 31 <object name="student_created_login" meta_type="CPS Layout"/> 31 32 <object name="student_personal" meta_type="CPS Layout"/> 32 33 <object name="student_personal_fe" meta_type="CPS Layout"/> -
WAeUP_SRP/trunk/profiles/default/layouts/import_student.xml
r1728 r1747 32 32 <property name="display_width">15</property> 33 33 </widget> 34 <widget name=" address" meta_type="String Widget">34 <widget name="perm_address" meta_type="String Widget"> 35 35 <property name="title">Address</property> 36 36 <property name="fields"> 37 <element value=" address"/>37 <element value="perm_address"/> 38 38 </property> 39 39 <property name="label">Address</property> … … 122 122 <property name="label">Current Session</property> 123 123 <property name="label_edit">Current Session</property> 124 <property name="description">The currently paid session</property> 125 <property name="help">The last session the student has paid his schoolfee</property> 124 126 <property name="readonly_layout_modes"/> 125 127 <property name="hidden_layout_modes"/> … … 134 136 <property name="label">Current Level</property> 135 137 <property name="label_edit">Current Level</property> 138 <property name="description">The level of the last paid session</property> 139 <property name="help">The last level the student has paid his schoolfee</property> 136 140 <property name="readonly_layout_modes"/> 137 141 <property name="hidden_layout_modes"/> … … 146 150 <property name="label">Current Verdict</property> 147 151 <property name="label_edit">Current Verdict</property> 152 <property name="description">The verdict of the current level</property> 153 <property name="help">The verdict of the level the student has paid his schoolfee</property> 148 154 <property name="readonly_layout_modes"/> 149 155 <property name="hidden_layout_modes"/> -
WAeUP_SRP/trunk/profiles/default/layouts/student_session_results_search.xml
r1449 r1747 51 51 <property name="hidden_layout_modes"/> 52 52 <property name="hidden_readonly_layout_modes"/> 53 <property name="matric_no_catalog">returning_import</property> 54 <property name="results_catalog">results_import</property> 53 55 <property name="display_width">10</property> 54 56 <property name="size_max">10</property> … … 105 107 <widget name="secret" meta_type="Secret Widget"> 106 108 <property name="title">Secret Widget</property> 107 <property name="fields"> 108 <element value="secret"/> 109 <property name="check_fields"> 110 <element value="Firstname"/> 111 <element value="Middlename"/> 112 <element value="Lastname"/> 109 113 </property> 110 114 <property name="label">Firstname, Middlename or Lastname</property> -
WAeUP_SRP/trunk/skins/waeup_default/sessions_voc.py
r1736 r1747 6 6 """ 7 7 if key is None: 8 l = [(' unknown','unknown')]8 l = [('xx','unknown')] 9 9 for y in range(1998,2008): 10 10 l.append( ('%s' % str(y)[-2:],'%4d/%4d' % (y,y+1))) … … 12 12 13 13 if len(key) != 2: 14 return "invalid Session %s" % key14 return 'unknown' 15 15 try: 16 16 y = int(key) 17 17 except: 18 return "invalid Session %s" % key18 return 'unknown' 19 19 if y < 90: 20 20 cent = 2000
Note: See TracChangeset for help on using the changeset viewer.