Changeset 3191


Ignore:
Timestamp:
20 Feb 2008, 16:50:08 (17 years ago)
Author:
joachim
Message:

first version with import_mode per line, please copy xml files to okene.

Location:
WAeUP_SRP
Files:
22 edited

Legend:

Unmodified
Added
Removed
  • WAeUP_SRP/base/WAeUPImport.py

    r3185 r3191  
    5555    required_modes = ('create',)
    5656
    57     def __init__(self,mode,waeup_tool):
     57    def __init__(self,waeup_tool):
    5858        self.member = member = waeup_tool.portal_membership.getAuthenticatedMember()
    5959        self.import_date = DateTime.DateTime().strftime("%d/%m/%y %H:%M:%S")
     
    6868        self.courses_catalog = waeup_tool.courses_catalog
    6969        self.course_results = waeup_tool.course_results
    70         self.mode = mode
    71         self.import_method = getattr(self, '%s' % mode,None)
     70        #self.mode = mode
     71        # self.import_method = getattr(self, '%s' % mode,None)
    7272        errors = []
    73         if self.import_method is None:
    74             errors.append('No importer method %s' % mode)
     73        # if self.import_method is None:
     74        #     errors.append('No importer method %s' % mode)
    7575        self.pending_path = "%s/import/%s.pending" % (i_home,self.plural_name)
    7676        self.pending_tmp = "%s/import/%s.pending.tmp" % (i_home,self.plural_name)
     
    9696        info['imported_by'] = str(member)
    9797        info['import_date'] = self.import_date
    98         info['import_mode'] = mode
     98        #info['import_mode'] = mode #now in import_xxx schema + layout
    9999        info['error'] = ''
    100100        #info['digest'] = ''
  • WAeUP_SRP/base/WAeUPTool.py

    r3186 r3191  
    13531353        if filename == pend_str:
    13541354            pending_only = True
    1355         mode = "create"
    1356         if edit:
    1357             if filename.endswith('_toDelete'):
    1358                 mode = "delete"
    1359             else:
    1360                 mode = "edit"
     1355        # mode = "create"
     1356        # if edit:
     1357        #     if filename.endswith('_toDelete'):
     1358        #         mode = "delete"
     1359        #     else:
     1360        #         mode = "edit"
    13611361        importer_name = ''.join([part.capitalize() for part in name.split('_')])
    1362         importer = eval("%sImport" % importer_name)(mode,self)
     1362        importer = eval("%sImport" % importer_name)(self)
    13631363        logger = importer.logger
    13641364        if importer.init_errors:
    1365             logger.info(self.init_errors)
    1366             return self.init_errors
     1365            logger.info(importer.init_errors)
     1366            return importer.init_errors
    13671367        member = importer.member
    13681368        current = importer.current
     
    14231423        info['imported_from'] = import_source_fn
    14241424        attrs = csv.reader(open(import_source_path,"rb")).next()
     1425        if "import_mode" not in attrs:
     1426            msg = 'import_mode must be in heading'
     1427            return msg
     1428           
    14251429        import_keys = [k.strip() for k in attrs if not (k.strip().startswith('ignore')
    14261430                                                        or k.strip() in info.keys())]
     
    14301434            msg = 'not ignorable key(s): "%s" found in heading' % ", ".join(diff2schema)
    14311435            return msg
    1432         if mode in importer.required_modes:
    1433             required_keys = [importer.layout.getIdUnprefixed(id)
    1434                                 for id,widget in importer.layout.objectItems()
    1435                                 if widget.is_required]
    1436             if not set(required_keys).issubset(set(import_keys)):
    1437                 diff2import = set(required_keys).difference(set(import_keys))
    1438                 msg = 'required key(s): "%s" not found in heading' % ", ".join(diff2import)
    1439                 return msg
     1436        # if import_mode in importer.required_modes:
     1437        #     required_keys = [importer.layout.getIdUnprefixed(id)
     1438        #                         for id,widget in importer.layout.objectItems()
     1439        #                         if widget.is_required]
     1440        #     if not set(required_keys).issubset(set(import_keys)):
     1441        #         diff2import = set(required_keys).difference(set(import_keys))
     1442        #         msg = 'required key(s): "%s" not found in heading' % ", ".join(diff2import)
     1443        #         return msg
    14401444        #
    14411445        # start importing
     
    14671471                start = False
    14681472                adapters = [MappingStorageAdapter(importer.schema, item)]
    1469                 logger.info('%(member)s starts import from %(import_source_fn)s in %(mode)s mode' % vars())
    1470                 #logger.info('%s starts import from %s in %s mode with schema and layout %s' % (member,filename,mode,iname))
     1473                logger.info('%(member)s starts import from %(import_source_fn)s' % vars())
    14711474            dm = DataModel(item, adapters,context=self)
    14721475            ds = DataStructure(data=item,datamodel=dm)
     
    14741477            total += 1
    14751478            error_count = 0
    1476             for k in import_keys:
    1477                 if k not in item.keys() or k not in importer.validators.keys():
    1478                     continue
    1479                 if not importer.validators[k](ds,mode=mode):
    1480                     if error_count:
    1481                         error_string += ' ++ '
    1482                     error_string += "%s: %s" % (k,self.translation_service(ds.getError(k),
     1479            import_mode = item.get('import_mode','edit')
     1480            import_method = getattr(importer, '%(import_mode)s' % vars(),None )
     1481            if import_method is None:
     1482                error_string += "no %(import_mode)s " % vars()
     1483            else:
     1484                for k in import_keys:
     1485                    if k not in item.keys() or k not in importer.validators.keys():
     1486                        continue
     1487                    if not importer.validators[k](ds,mode=import_mode):
     1488                        if error_count:
     1489                            error_string += ' ++ '
     1490                            error_string += "%s: %s" % (k,self.translation_service(ds.getError(k),
    14831491                                                                           ds.getErrorMapping(k)))
    1484                     error_count += 1
     1492                            error_count += 1
    14851493            if error_string:
    14861494                error = error_string
     
    14901498                temp_item = item.copy()
    14911499                temp_item.update(dm)
    1492                 import_method = importer.import_method
    1493                 if pending_only:
    1494                     import_mode = temp_item.get('import_mode','edit')
    1495                     import_method = getattr(importer, '%(import_mode)s' % vars() )
    1496                     info['import_mode'] = import_mode
    14971500                results = import_method(temp_item)
    14981501                id = results[0]
     
    15671570        elapse = time.time() - elapse
    15681571        copy2(pending_tmp,pending_path)
    1569         msg = "finished importing in %(mode)s mode from %(import_source_fn)s in %(elapse).2f seconds, " % vars()
     1572        msg = "finished importing from %(import_source_fn)s in %(elapse).2f seconds, " % vars()
    15701573        msg += "%(count)d records totally read, %(total_added_to_imported)d added to %(imported_fn)s, " % vars()
    15711574        if pending_only:
  • WAeUP_SRP/uniben/profiles/default/layouts/import.xml

    r3188 r3191  
    3333  <property name="vocabulary">import_names</property>
    3434 </widget>
    35  <widget name="mode" meta_type="Select Widget">
    36   <property name="title">Import Mode</property>
    37   <property name="fields">
    38    <element value="mode"/>
    39   </property>
    40   <property name="is_required">False</property>
    41   <property name="label">Import Mode</property>
    42   <property name="label_edit">Import Mode</property>
    43   <property name="readonly_layout_modes"/>
    44   <property name="hidden_layout_modes"/>
    45   <property name="hidden_readonly_layout_modes"/>
    46   <property name="vocabulary">import_modes</property>
    47  </widget>
    4835 <table>
    4936  <row>
  • WAeUP_SRP/uniben/profiles/default/layouts/import_application.xml

    r2814 r3191  
    99  <property name="validate_values_expr"></property>
    1010
     11 <widget name="import_mode" meta_type="Select Widget">
     12  <property name="title">Import Mode</property>
     13  <property name="fields">
     14   <element value="import_mode"/>
     15  </property>
     16  <property name="is_required">True</property>
     17  <property name="label">Import Mode</property>
     18  <property name="label_edit">Import Mode</property>
     19  <property name="readonly_layout_modes"/>
     20  <property name="hidden_layout_modes"/>
     21  <property name="hidden_readonly_layout_modes"/>
     22  <property name="vocabulary">import_modes</property>
     23 </widget>
    1124  <widget name="student_id" meta_type="String Widget">
    1225    <property name="title">Student Id</property>
  • WAeUP_SRP/uniben/profiles/default/layouts/import_certificate.xml

    r2290 r3191  
    88 <property name="flexible_widgets"/>
    99 <property name="validate_values_expr"></property>
     10 <widget name="import_mode" meta_type="Select Widget">
     11  <property name="title">Import Mode</property>
     12  <property name="fields">
     13   <element value="import_mode"/>
     14  </property>
     15  <property name="is_required">True</property>
     16  <property name="label">Import Mode</property>
     17  <property name="label_edit">Import Mode</property>
     18  <property name="readonly_layout_modes"/>
     19  <property name="hidden_layout_modes"/>
     20  <property name="hidden_readonly_layout_modes"/>
     21  <property name="vocabulary">import_modes</property>
     22 </widget>
    1023 <widget name="title" meta_type="String Widget">
    1124  <property name="fields">
  • WAeUP_SRP/uniben/profiles/default/layouts/import_certificate_course.xml

    r2285 r3191  
    88 <property name="flexible_widgets"/>
    99 <property name="validate_values_expr"></property>
     10 <widget name="import_mode" meta_type="Select Widget">
     11  <property name="title">Import Mode</property>
     12  <property name="fields">
     13   <element value="import_mode"/>
     14  </property>
     15  <property name="is_required">True</property>
     16  <property name="label">Import Mode</property>
     17  <property name="label_edit">Import Mode</property>
     18  <property name="readonly_layout_modes"/>
     19  <property name="hidden_layout_modes"/>
     20  <property name="hidden_readonly_layout_modes"/>
     21  <property name="vocabulary">import_modes</property>
     22 </widget>
    1023 <widget name="Title" meta_type="String Widget">
    1124  <property name="title">Title</property>
  • WAeUP_SRP/uniben/profiles/default/layouts/import_course.xml

    r2290 r3191  
    88 <property name="flexible_widgets"/>
    99 <property name="validate_values_expr"></property>
     10 <widget name="import_mode" meta_type="Select Widget">
     11  <property name="title">Import Mode</property>
     12  <property name="fields">
     13   <element value="import_mode"/>
     14  </property>
     15  <property name="is_required">True</property>
     16  <property name="label">Import Mode</property>
     17  <property name="label_edit">Import Mode</property>
     18  <property name="readonly_layout_modes"/>
     19  <property name="hidden_layout_modes"/>
     20  <property name="hidden_readonly_layout_modes"/>
     21  <property name="vocabulary">import_modes</property>
     22 </widget>
    1023<widget name="code" meta_type="WAeUPId Widget">
    1124 <property name="title">Course Id</property>
  • WAeUP_SRP/uniben/profiles/default/layouts/import_course_result.xml

    r3143 r3191  
    88 <property name="flexible_widgets"/>
    99 <property name="validate_values_expr"></property>
     10 <widget name="import_mode" meta_type="Select Widget">
     11  <property name="title">Import Mode</property>
     12  <property name="fields">
     13   <element value="import_mode"/>
     14  </property>
     15  <property name="is_required">True</property>
     16  <property name="label">Import Mode</property>
     17  <property name="label_edit">Import Mode</property>
     18  <property name="readonly_layout_modes"/>
     19  <property name="hidden_layout_modes"/>
     20  <property name="hidden_readonly_layout_modes"/>
     21  <property name="vocabulary">import_modes</property>
     22 </widget>
    1023  <widget name="student_id" meta_type="String Widget">
    1124    <property name="title">Student Id</property>
  • WAeUP_SRP/uniben/profiles/default/layouts/import_department.xml

    r2267 r3191  
    88 <property name="flexible_widgets"/>
    99 <property name="validate_values_expr"></property>
     10 <widget name="import_mode" meta_type="Select Widget">
     11  <property name="title">Import Mode</property>
     12  <property name="fields">
     13   <element value="import_mode"/>
     14  </property>
     15  <property name="is_required">True</property>
     16  <property name="label">Import Mode</property>
     17  <property name="label_edit">Import Mode</property>
     18  <property name="readonly_layout_modes"/>
     19  <property name="hidden_layout_modes"/>
     20  <property name="hidden_readonly_layout_modes"/>
     21  <property name="vocabulary">import_modes</property>
     22 </widget>
    1023 <widget name="code" meta_type="WAeUPId Widget">
    1124  <property name="title">Department Code</property>
  • WAeUP_SRP/uniben/profiles/default/layouts/import_faculty.xml

    r2267 r3191  
    88 <property name="flexible_widgets"/>
    99 <property name="validate_values_expr"></property>
     10 <widget name="import_mode" meta_type="Select Widget">
     11  <property name="fields">
     12   <element value="import_mode"/>
     13  </property>
     14  <property name="is_required">True</property>
     15  <property name="label">Import Mode</property>
     16  <property name="label_edit">Import Mode</property>
     17  <property name="readonly_layout_modes"/>
     18  <property name="hidden_layout_modes"/>
     19  <property name="hidden_readonly_layout_modes"/>
     20  <property name="vocabulary">import_modes</property>
     21 </widget>
    1022 <widget name="title" meta_type="String Widget">
     23  <property name="title">Import Mode</property>
    1124  <property name="fields">
    1225   <element value="title"/>
  • WAeUP_SRP/uniben/profiles/default/layouts/import_student.xml

    r3005 r3191  
    88 <property name="flexible_widgets"/>
    99 <property name="validate_values_expr"></property>
    10 
     10 <widget name="import_mode" meta_type="Select Widget">
     11  <property name="title">Import Mode</property>
     12  <property name="fields">
     13   <element value="import_mode"/>
     14  </property>
     15  <property name="is_required">True</property>
     16  <property name="label">Import Mode</property>
     17  <property name="label_edit">Import Mode</property>
     18  <property name="readonly_layout_modes"/>
     19  <property name="hidden_layout_modes"/>
     20  <property name="hidden_readonly_layout_modes"/>
     21  <property name="vocabulary">import_modes</property>
     22 </widget>
    1123 <widget name="id" meta_type="String Widget">
    1224  <property name="title">Id</property>
  • WAeUP_SRP/uniben/profiles/default/layouts/import_verdict.xml

    r3143 r3191  
    88  <property name="flexible_widgets"/>
    99  <property name="validate_values_expr"></property>
     10 <widget name="import_mode" meta_type="Select Widget">
     11  <property name="title">Import Mode</property>
     12  <property name="fields">
     13   <element value="import_mode"/>
     14  </property>
     15  <property name="is_required">True</property>
     16  <property name="label">Import Mode</property>
     17  <property name="label_edit">Import Mode</property>
     18  <property name="readonly_layout_modes"/>
     19  <property name="hidden_layout_modes"/>
     20  <property name="hidden_readonly_layout_modes"/>
     21  <property name="vocabulary">import_modes</property>
     22 </widget>
    1023  <widget name="id" meta_type="String Widget">
    1124    <property name="title">Id</property>
  • WAeUP_SRP/uniben/profiles/default/schemas/import.xml

    r1774 r3191  
    33 <field name="filename" meta_type="CPS String Field"/>
    44 <field name="name" meta_type="CPS String Field"/>
    5  <field name="import_or_edit" meta_type="CPS Boolean Field"/>
    65</object>
  • WAeUP_SRP/uniben/profiles/default/schemas/import_application.xml

    r2788 r3191  
    22<?xml-stylesheet type="text/xsl" href="schema.xsl"?>
    33<object name="import_application" meta_type="CPS Schema">
     4 <field name="import_mode" meta_type="CPS String Field"/>
    45 <field name="course1" meta_type="CPS String Field"/>
    56 <field name="course2" meta_type="CPS String Field"/>
  • WAeUP_SRP/uniben/profiles/default/schemas/import_certificate.xml

    r2285 r3191  
    22<?xml-stylesheet type="text/xsl" href="schema.xsl"?>
    33<object name="certificate" meta_type="CPS Schema">
     4 <field name="import_mode" meta_type="CPS String Field"/>
    45 <field name="title" meta_type="CPS String Field"/>
    56 <field name="admin_status" meta_type="CPS String Field"/>
  • WAeUP_SRP/uniben/profiles/default/schemas/import_certificate_course.xml

    r2285 r3191  
    22<?xml-stylesheet type="text/xsl" href="schema.xsl"?>
    33<object name="certificate_course" meta_type="CPS Schema">
     4 <field name="import_mode" meta_type="CPS String Field"/>
    45 <field name="code" meta_type="CPS String Field" />
    56 <field name="certificate_code" meta_type="CPS String Field" />
  • WAeUP_SRP/uniben/profiles/default/schemas/import_course.xml

    r2285 r3191  
    22<?xml-stylesheet type="text/xsl" href="schema.xsl"?>
    33<object name="course" meta_type="CPS Schema">
     4 <field name="import_mode" meta_type="CPS String Field"/>
    45 <field name="title" meta_type="CPS String Field"/>
    56 <field name="department_code" meta_type="CPS String Field"/>
  • WAeUP_SRP/uniben/profiles/default/schemas/import_course_result.xml

    r2481 r3191  
    22<?xml-stylesheet type="text/xsl" href="schema.xsl"?>
    33<object name="course_result" meta_type="CPS Schema">
     4 <field name="import_mode" meta_type="CPS String Field"/>
    45 <field name="student_id" meta_type="CPS String Field"/>
    56 <field name="matric_no" meta_type="CPS String Field"/>
  • WAeUP_SRP/uniben/profiles/default/schemas/import_department.xml

    r2267 r3191  
    22<?xml-stylesheet type="text/xsl" href="schema.xsl"?>
    33<object name="import_department" meta_type="CPS Schema">
     4 <field name="import_mode" meta_type="CPS String Field"/>
    45 <field name="code" meta_type="CPS String Field"/>
    56 <field name="faculty_code" meta_type="CPS String Field"/>
  • WAeUP_SRP/uniben/profiles/default/schemas/import_faculty.xml

    r2267 r3191  
    22<?xml-stylesheet type="text/xsl" href="schema.xsl"?>
    33<object name="import_faculty" meta_type="CPS Schema">
     4 <field name="import_mode" meta_type="CPS String Field"/>
    45 <field name="code" meta_type="CPS String Field"/>
    56 <field name="title" meta_type="CPS String Field"/>
  • WAeUP_SRP/uniben/profiles/default/schemas/import_verdict.xml

    r3092 r3191  
    22<?xml-stylesheet type="text/xsl" href="schema.xsl"?>
    33<object name="import_verdict" meta_type="CPS Schema">
     4 <field name="import_mode" meta_type="CPS String Field"/>
    45 <field name="id" meta_type="CPS String Field"/>
    56 <field name="matric_no" meta_type="CPS String Field"/>
  • WAeUP_SRP/uniben/profiles/default/vocabularies/import_names.xml

    r3188 r3191  
    77 <property name="acl_write_roles">Manager</property>
    88 <item key="student" msgid="">Student Data</item>
    9  <item key="verdict" msgid="">Verdicts & Return</item>
     9 <item key="verdict" msgid="">Verdicts + Return</item>
    1010 <item key="faculty" msgid="">Faculty Data</item>
    1111 <item key="department" msgid="">Department Data</item>
Note: See TracChangeset for help on using the changeset viewer.