Changeset 1772


Ignore:
Timestamp:
11 May 2007, 12:00:10 (18 years ago)
Author:
joachim
Message:

some fixes for addStudent and importStudent

Location:
WAeUP_SRP/trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • WAeUP_SRP/trunk/WAeUPTool.py

    r1759 r1772  
    204204        self.makeStudentMember(sid,password)
    205205        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'
    206211        for pt in f2t.keys():
    207212            student_obj.invokeFactory(pt,f2t[pt]['id'])
     
    209214            sub_doc = sub_obj.getContent()
    210215            self.portal_workflow.doActionFor(sub_obj,'open',dest_container=sub_obj)
    211             d = {'Title': f2t[pt]['title']}
     216            d['Title'] = f2t[pt]['title']
    212217            for field in f2t[pt]['fields']:
    213218                d[field] = dict.get(field,'')
    214             if pt == 'StudentPersonal':
    215                 d['sex'] = dict.get('sex') == 'F'
    216219            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)
    219223        entry_session = dict.get('entry_session')
    220224        wfaction = 'return'
     
    656660                             ('jamb_reg_no',
    657661                              'entry_mode',
    658                               #'entry_level',
    659662                              'entry_session',
    660663                              'jamb_score',
     
    711714
    712715
    713     security.declareProtected(ModifyPortalContent,'import_student') ###(
    714     def import_student(self,dict):
     716    security.declareProtected(ModifyPortalContent,'importStudent') ###(
     717    def importStudent(self,dict):
    715718        "create a students data"
    716719        logger = logging.getLogger('WAeUPTool.create_student')
     
    730733        student_obj = getattr(students_folder,sid)
    731734        f2t = self.student_field2types
     735        d = {}
     736        d['jamb_sex']  = 'M'
     737        if dict.get('sex'):
     738            d['jamb_sex']  = 'F'
    732739        for pt in f2t.keys():
    733740            student_obj.invokeFactory(pt,f2t[pt]['id'])
     
    735742            sub_doc = sub_obj.getContent()
    736743            self.portal_workflow.doActionFor(sub_obj,'open',dest_container=sub_obj)
    737             d = {'Title': f2t[pt]['title']}
     744            d['Title'] = f2t[pt]['title']
    738745            for field in f2t[pt]['fields']:
    739746                d[field] = dict.get(field,'')
    740             if pt == 'StudentPersonal':
    741                 d['sex'] = dict.get('sex') == 'F'
    742747            sub_doc.edit(mapping = d)
    743748            new_state = f2t[pt]['wf_state']
     
    768773        schema = stool._getOb(iname)
    769774        if schema is None:
    770             em = 'No such schema import_%s' % iname
    771             logger.error('No such schema import_%s' % iname)
     775            em = 'No such schema %s' % iname
     776            logger.error('No such schema %s' % iname)
    772777            return em
    773778        layout = ltool._getOb(iname)
    774779        if layout is None:
    775             em = 'No such layout import_%s' % iname
     780            em = 'No such layout %s' % iname
    776781            logger.error(em)
    777782            return em
     
    779784        for widget in layout.keys():
    780785            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
    784790            logger.error(em)
    785791            return em
     
    809815                    return
    810816                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
    811819                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')
    813820                format = ','.join(['"%%(%s)s"' % fn for fn in import_keys])
    814821                format_error = format + ',"%(Error)s"'
    815                 #from pdb import set_trace; set_trace()
    816822                format = '"%(id)s",'+ format
    817823            ds = DataStructure(data=item,datamodel=dm)
     
    822828            if not error_string:
    823829                item.update(dm)
    824                 item['id'],error = creator(item)
     830                item['id'],error = importer(item)
    825831                if error:
    826832                    error_string += error
     
    840846                if len(imported) > 0:
    841847                    open("%s/import/%s_imported%s.csv" % (i_home,filename,current),"a").write(
    842                              '\n'.join(not_imported) + '\n')
     848                             '\n'.join(imported) + '\n')
    843849                    imported = []
    844850                em = '%d transactions committed\n' % (tr_count)
  • WAeUP_SRP/trunk/Widgets.py

    r1748 r1772  
    66##from Products.CPSSchemas.Widget import CPSWidgetType
    77from Products.CMFCore.utils import getToolByName
    8 from Products.CPSSchemas.BasicWidgets import CPSWidget, CPSStringWidget, CPSEmailWidget,CPSImageWidget
     8from Products.CPSSchemas.BasicWidgets import CPSBooleanWidget, CPSWidget, CPSStringWidget, CPSEmailWidget,CPSImageWidget
    99from Products.CPSSchemas.BasicWidgets import renderHtmlTag,CPSSelectWidget, CPSStringWidget
    1010from Products.CPSSchemas.ExtendedWidgets import CPSDateTimeWidget
     
    389389widgetRegistry.register(SecretWidget)
    390390###)
     391
     392class 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
     417InitializeClass(WAeUPSexWidget)
     418
     419widgetRegistry.register(WAeUPSexWidget)
    391420
    392421class MatricNoWidget(CPSStringWidget): ###(
  • WAeUP_SRP/trunk/profiles/default/layouts/import_student.xml

    r1771 r1772  
    216216  <property name="display_width">10</property>
    217217 </widget>
    218  <widget name="sex" meta_type="Boolean Widget">
     218 <widget name="sex" meta_type="WAeUP Sex Widget">
    219219  <property name="title">Sex</property>
    220220  <property name="fields">
Note: See TracChangeset for help on using the changeset viewer.