Changeset 1772
- Timestamp:
- 11 May 2007, 12:00:10 (18 years ago)
- Location:
- WAeUP_SRP/trunk
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
WAeUP_SRP/trunk/WAeUPTool.py
r1759 r1772 204 204 self.makeStudentMember(sid,password) 205 205 f2t = self.student_field2types 206 #from pdb import set_trace; set_trace() 207 d = {} 208 d['jamb_sex'] = 'M' 209 if dict.get('sex'): 210 d['jamb_sex'] = 'F' 206 211 for pt in f2t.keys(): 207 212 student_obj.invokeFactory(pt,f2t[pt]['id']) … … 209 214 sub_doc = sub_obj.getContent() 210 215 self.portal_workflow.doActionFor(sub_obj,'open',dest_container=sub_obj) 211 d = {'Title': f2t[pt]['title']}216 d['Title'] = f2t[pt]['title'] 212 217 for field in f2t[pt]['fields']: 213 218 d[field] = dict.get(field,'') 214 if pt == 'StudentPersonal':215 d['sex'] = dict.get('sex') == 'F'216 219 sub_doc.edit(mapping = d) 217 self.portal_workflow.doActionFor(sub_obj,'close',dest_container=sub_obj) 218 220 new_state = f2t[pt]['wf_state'] 221 if new_state != "remain": 222 self.portal_workflow.doActionFor(sub_obj,new_state,dest_container=sub_obj) 219 223 entry_session = dict.get('entry_session') 220 224 wfaction = 'return' … … 656 660 ('jamb_reg_no', 657 661 'entry_mode', 658 #'entry_level',659 662 'entry_session', 660 663 'jamb_score', … … 711 714 712 715 713 security.declareProtected(ModifyPortalContent,'import _student') ###(714 def import _student(self,dict):716 security.declareProtected(ModifyPortalContent,'importStudent') ###( 717 def importStudent(self,dict): 715 718 "create a students data" 716 719 logger = logging.getLogger('WAeUPTool.create_student') … … 730 733 student_obj = getattr(students_folder,sid) 731 734 f2t = self.student_field2types 735 d = {} 736 d['jamb_sex'] = 'M' 737 if dict.get('sex'): 738 d['jamb_sex'] = 'F' 732 739 for pt in f2t.keys(): 733 740 student_obj.invokeFactory(pt,f2t[pt]['id']) … … 735 742 sub_doc = sub_obj.getContent() 736 743 self.portal_workflow.doActionFor(sub_obj,'open',dest_container=sub_obj) 737 d = {'Title': f2t[pt]['title']}744 d['Title'] = f2t[pt]['title'] 738 745 for field in f2t[pt]['fields']: 739 746 d[field] = dict.get(field,'') 740 if pt == 'StudentPersonal':741 d['sex'] = dict.get('sex') == 'F'742 747 sub_doc.edit(mapping = d) 743 748 new_state = f2t[pt]['wf_state'] … … 768 773 schema = stool._getOb(iname) 769 774 if schema is None: 770 em = 'No such schema import_%s' % iname771 logger.error('No such schema import_%s' % iname)775 em = 'No such schema %s' % iname 776 logger.error('No such schema %s' % iname) 772 777 return em 773 778 layout = ltool._getOb(iname) 774 779 if layout is None: 775 em = 'No such layout import_%s' % iname780 em = 'No such layout %s' % iname 776 781 logger.error(em) 777 782 return em … … 779 784 for widget in layout.keys(): 780 785 validators[widget] = layout[widget].validate 781 creator = getattr(self, 'import_%s' % name,None) 782 if creator is None: 783 em = 'No creator function create_%s' % name 786 importer_name = "import%s" % name.capitalize() 787 importer = getattr(self, '%s' % importer_name,None) 788 if importer is None: 789 em = 'No importer function %s' % importer_name 784 790 logger.error(em) 785 791 return em … … 809 815 return 810 816 s = ','.join(['"%s"' % fn for fn in import_keys]) 817 open("%s/import/%s_not_imported%s.csv" % (i_home,filename,current),"a").write(s + ',"Error"'+ '\n') 818 s = '"id",' + s 811 819 open("%s/import/%s_imported%s.csv" % (i_home,filename,current),"a").write(s + '\n') 812 open("%s/import/%s_not_imported%s.csv" % (i_home,filename,current),"a").write('%s,"Error"' %s + '\n')813 820 format = ','.join(['"%%(%s)s"' % fn for fn in import_keys]) 814 821 format_error = format + ',"%(Error)s"' 815 #from pdb import set_trace; set_trace()816 822 format = '"%(id)s",'+ format 817 823 ds = DataStructure(data=item,datamodel=dm) … … 822 828 if not error_string: 823 829 item.update(dm) 824 item['id'],error = creator(item)830 item['id'],error = importer(item) 825 831 if error: 826 832 error_string += error … … 840 846 if len(imported) > 0: 841 847 open("%s/import/%s_imported%s.csv" % (i_home,filename,current),"a").write( 842 '\n'.join( not_imported) + '\n')848 '\n'.join(imported) + '\n') 843 849 imported = [] 844 850 em = '%d transactions committed\n' % (tr_count) -
WAeUP_SRP/trunk/Widgets.py
r1748 r1772 6 6 ##from Products.CPSSchemas.Widget import CPSWidgetType 7 7 from Products.CMFCore.utils import getToolByName 8 from Products.CPSSchemas.BasicWidgets import CPS Widget, CPSStringWidget, CPSEmailWidget,CPSImageWidget8 from Products.CPSSchemas.BasicWidgets import CPSBooleanWidget, CPSWidget, CPSStringWidget, CPSEmailWidget,CPSImageWidget 9 9 from Products.CPSSchemas.BasicWidgets import renderHtmlTag,CPSSelectWidget, CPSStringWidget 10 10 from Products.CPSSchemas.ExtendedWidgets import CPSDateTimeWidget … … 389 389 widgetRegistry.register(SecretWidget) 390 390 ###) 391 392 class WAeUPSexWidget(CPSBooleanWidget): 393 """WAeUP sex widget.""" 394 meta_type = 'WAeUP Sex Widget' 395 396 def validate(self, datastructure, **kw): 397 """Validate datastructure and update datamodel.""" 398 value = datastructure[self.getWidgetId()] 399 400 if self.render_format not in self.render_formats: 401 self.render_format = 'select' 402 403 female = value in ('F','f','Female','female',"True",True) 404 male = value in ('M','m','Male','male','False',False) 405 if not female and not male: 406 datastructure.setError(self.getWidgetId(), 407 "invalid sex %s" % value) 408 return 0 409 elif female: 410 v = True 411 else: 412 v = False 413 datamodel = datastructure.getDataModel() 414 datamodel[self.fields[0]] = v 415 return 1 416 417 InitializeClass(WAeUPSexWidget) 418 419 widgetRegistry.register(WAeUPSexWidget) 391 420 392 421 class MatricNoWidget(CPSStringWidget): ###( -
WAeUP_SRP/trunk/profiles/default/layouts/import_student.xml
r1771 r1772 216 216 <property name="display_width">10</property> 217 217 </widget> 218 <widget name="sex" meta_type=" BooleanWidget">218 <widget name="sex" meta_type="WAeUP Sex Widget"> 219 219 <property name="title">Sex</property> 220 220 <property name="fields">
Note: See TracChangeset for help on using the changeset viewer.