Changeset 3143


Ignore:
Timestamp:
11 Feb 2008, 23:05:17 (17 years ago)
Author:
joachim
Message:

new version, now only in import pending xxx only pending records are imported.

Location:
WAeUP_SRP
Files:
2 added
4 edited

Legend:

Unmodified
Added
Removed
  • WAeUP_SRP/base/WAeUPTool.py

    r3141 r3143  
    711711        "do it"
    712712        files = [file for file in os.listdir("%s/import/" % (i_home))
    713                  if file.endswith('.csv') and file.find('imported') == -1]
     713                 if file.endswith('.csv') and (file.find('imported') == -1 and
     714                                               file.find('pending') == -1)]
    714715        return files
    715716    ###)
     
    15961597    security.declareProtected(ModifyPortalContent,'mass_edit_course_result') ###(
    15971598    def mass_edit_course_result(self,mapping):
     1599        #import pdb;pdb.set_trace()
    15981600        while True:
    15991601            result_id = mapping.get('id',None)
     
    16101612            if not res:
    16111613                return '', "No student with %(id_key)s %(id_field)s" % vars()
    1612             if id_field != "student_id":
     1614            if id_field == "matric_no":
    16131615                mapping['student_id'] = res[0].id
     1616            elif id_field == "student_id":
     1617                mapping['matric_no'] = res[0].matric_no
    16141618            if not res:
    16151619                return '', "No student with %(id_key)s %(id_field)s" % vars()
     
    16231627            self.course_results.modifyRecord(**mapping)
    16241628        except KeyError:
    1625             return key, "No course result to edit: %s" % key
     1629            return key, "No course result to edit: %s" % key,mapping
    16261630        return key,''
    16271631    ###)
     
    19651969                                                                          student_record.matric_no,
    19661970                                                                          matric_no)
     1971            mapping['matric_no'] = student_record.matric_no
    19671972        elif matric_no:
    19681973            res = self.students_catalog(matric_no = matric_no)
     
    19801985        current_session = d['session'] = mapping.get('current_session','')
    19811986        if current_session and student_record.session != current_session:
    1982             return student_id,'student %s: imported session %s does not match current_session %s' % (student_id,
     1987            msg = 'student %s: imported session %s does not match current_session %s' % (student_id,
    19831988                                                                                        current_session,
    19841989                                                                                        student_record.session)
     1990            return student_id,msg,mapping
    19851991        current_level = mapping.get('current_level','')
    19861992        if not current_level.isdigit():
    19871993            return '','student %s: imported level is empty' % (student_id,)
    19881994        if current_level and student_record.level != current_level:
    1989             return student_id,'student %s: imported level %s does not match current_level %s' % (student_id,
     1995            msg = 'student %s: imported level %s does not match current_level %s' % (student_id,
    19901996                                                                                    current_level,
    19911997                                                                                    student_record.level)
     1998            return student_id,msg,mapping
    19921999        student_review_state =  student_record.review_state
    19932000        if student_review_state == 'deactivated':
    19942001            return '',"student %s in review_state %s" % (student_id, student_review_state)
    19952002        if student_review_state not in ('courses_validated','returning'):
    1996             return student_id,"student %s in wrong review_state %s" % (student_id, student_review_state)
     2003            msg = "student %s in wrong review_state %s" % (student_id, student_review_state)
     2004            return student_id,msg,mapping
    19972005        student_obj = getattr(students_folder,student_id)
    19982006        f2t = self.field2types_student
     
    20352043        logger = logging.getLogger('WAeUPTool.importData')
    20362044        current = DateTime.DateTime().strftime("%d-%m-%y_%H_%M_%S")
     2045        import_date = DateTime.DateTime().strftime("%d/%m/%y %H:%M:%S")
    20372046        students_folder = self.portal_url.getPortalObject().campus.students
    20382047        start = True
     
    20792088            return em
    20802089        pending_fn = "%s/import/%ss_pending.csv" % (i_home,name)
     2090        pending_imported_fn = "%s/import/%ss_pending_imported%s.csv" % (i_home,name,current)
    20812091        if pending_only:
    20822092            import_source_fn = pending_fn
     
    20972107        diff2layout = set(import_keys).difference(set(layout.keys()))
    20982108        if diff2schema and diff2schema != set(['id',]):
    2099             #import pdb;pdb.set_trace()
    21002109            msg = 'not ignorable key(s): "%s" found in heading' % ", ".join(diff2schema)
    21012110            return msg
    2102         if mode == "create":
     2111        if mode in ("create","edit"):
    21032112            required_keys = [layout.getIdUnprefixed(id)
    21042113                                for id,widget in layout.objectItems()
     
    21372146        pending_records = {}
    21382147        imports_pending = 0
     2148        total_pending_imported = 0
    21392149        total_pending = 0
    21402150        format = ','.join(['"%%(%s)s"' % fn for fn in import_keys])
     
    21432153        imported = []
    21442154        if name in ('verdict','course_result',):
    2145             #global pending_records
    2146             pending_keys = imported_keys[:]
     2155            #pending_keys = imported_keys[:]
     2156            sname = "%s_pending" % iname
     2157            pending_schema = stool._getOb(sname)
     2158            if schema is None:
     2159                em = 'No such pending_schema %s' % sname
     2160                logger.error('No such schema %s' % sname)
     2161                return em
     2162            pending_keys = pending_schema.keys()
    21472163            pending_keys += "Error",
     2164            if 'id' not in pending_keys:
     2165                pending_keys.insert(0,'id')
    21482166            pending_records = {}
    21492167            if os.path.exists(pending_fn):
     
    21572175            new_imports_pending = 0
    21582176            pending_imported = []
    2159             for item in pending_records.values():
    2160                 id,error = importer(item)
    2161                 if error:
    2162                     continue
    2163                 else:
    2164                     if item.has_key('Error'):
    2165                         del item['Error']
    2166                     imported.append(item)
     2177            if pending_only:
     2178                pending_imported_ids = []
     2179                pending_imported = []
     2180                for item in pending_records.values():
     2181                    results = importer(item)
     2182                    id = results[0]
     2183                    error = results[1]
     2184                    is_pending = len(results) == 3
     2185                    if is_pending:
     2186                        continue
    21672187                    msg = format % item
    21682188                    logger.info("imported from %(pending_fn)s %(msg)s" % vars())
    2169                     pending_imported += id,
    2170                     continue
    2171             total_imported = len(pending_imported)
    2172             logger.info("imported %d pending imports" % len(pending_imported))
    2173             for id in pending_imported:
    2174                 del pending_records[id]
     2189                    pending_imported.append(item)
     2190                    pending_imported_ids += id,
     2191                    total_pending_imported = len(pending_imported_ids)
     2192                    logger.info("imported %d pending imports" % len(pending_imported_ids))
     2193                for id in pending_imported_ids:
     2194                    del pending_records[id]
    21752195            pending_imports_file = open(pending_fn,'w')
    21762196            pending_csv_writer = csv.DictWriter(pending_imports_file,
     
    21792199            mapping = dict((k,k) for k in pending_keys)
    21802200            pending_csv_writer.writerow(mapping)
     2201            if len(pending_imported) > 0:
     2202                pending_imported_file = open(pending_imported_fn,'w')
     2203                pending_imported_csv_writer = csv.DictWriter(pending_imported_file,
     2204                                                             pending_keys,
     2205                                                             extrasaction='ignore')
     2206                pending_imported_csv_writer.writerow(dict((k,k) for k in imported_keys))
     2207                pending_imported_csv_writer.writerows(pending_imported)
    21812208        #
    21822209        if pending_only:
     
    22152242            temp_item = item.copy()
    22162243            temp_item.update(dm)
    2217             id,error = importer(temp_item)
    2218             if error:
     2244            #id,error = importer(temp_item)
     2245            results = importer(temp_item)
     2246            id = results[0]
     2247            error = results[1]
     2248            is_pending = len(results) == 3
     2249            if is_pending:
     2250                temp_item = results[2]
     2251                temp_item['Error'] = error
     2252                msg = format_error % temp_item
     2253                if id not in pending_records.keys():
     2254                    temp_item['id'] = id
     2255                    pending_records[id] = temp_item
     2256                    logger.info("%(id)s added to pending %(msg)s" % vars())
     2257                    new_imports_pending += 1
     2258                else:
     2259                    logger.info("%(id)s already in pending %(msg)s" % vars())
     2260                continue
     2261            elif error:
    22192262                item['Error'] = error
    2220                 if id:
    2221                     if id not in pending_records.keys():
    2222                         item['id'] = id
    2223                         pending_records[id] = item
    2224                         msg = format_error % item
    2225                         logger.info("%(id)s added to pending %(msg)s" % vars())
    2226                         new_imports_pending += 1
    2227                     else:
    2228                         logger.info("%(id)s already in pending %(msg)s" % vars())
    2229                     continue
    2230                 else:
    2231                     not_imported.append(item)
    2232                     total_not_imported += 1
    2233                     continue
     2263                not_imported.append(item)
     2264                total_not_imported += 1
     2265                continue
    22342266            item = temp_item
    22352267            item['id'] = id
     
    22672299        msg += "%(total_imported)d imported, %(total_not_imported)d not imported " % vars()
    22682300        if total_pending:
    2269             msg += "%(new_imports_pending)d pending added, %(total_pending)d total pending in %(pending_fn)s " % vars()
     2301            msg += "%(new_imports_pending)d pending added, %(total_pending_imported)d pending imported " % vars()
     2302            msg += "%(total_pending)d total pending in %(pending_fn)s " % vars()
    22702303        msg += "(of total %(total)d)" % vars()
    22712304        logger.info(msg)
  • WAeUP_SRP/uniben/profiles/default/layouts/import_course_result.xml

    r2778 r3143  
    7575      <element value="session_id"/>
    7676    </property>
    77     <property name="is_required">True</property>
     77    <property name="is_required">False</property>
    7878    <property name="label">session</property>
    7979    <property name="label_edit">session</property>
     
    129129      <element value="score"/>
    130130    </property>
     131    <property name="is_required">True</property>
    131132    <property name="label">Score</property>
    132133    <property name="label_edit">Score</property>
     
    135136    <property name="hidden_layout_modes"/>
    136137    <property name="hidden_readonly_layout_modes"/>
     138    <property name="min_value">1</property>
     139    <property name="max_value">100</property>
    137140  </widget>
    138141
  • WAeUP_SRP/uniben/profiles/default/layouts/import_verdict.xml

    r3055 r3143  
    1111    <property name="title">Id</property>
    1212    <property name="fields">
    13       <element value="student_id"/>
     13      <element value="id"/>
    1414    </property>
    1515    <property name="is_required">False</property>
  • WAeUP_SRP/uniben/profiles/default/schemas.xml

    r3139 r3143  
    1515 <object name="import_course" meta_type="CPS Schema"/>
    1616 <object name="import_course_result" meta_type="CPS Schema"/>
     17 <object name="import_course_result_pending" meta_type="CPS Schema"/>
    1718 <object name="import_department" meta_type="CPS Schema"/>
    1819 <object name="import_faculty" meta_type="CPS Schema"/>
     
    2021 <object name="import_student" meta_type="CPS Schema"/>
    2122 <object name="import_verdict" meta_type="CPS Schema"/>
     23 <object name="import_verdict_pending" meta_type="CPS Schema"/>
    2224
    2325 <object name="course" meta_type="CPS Schema"/>
Note: See TracChangeset for help on using the changeset viewer.