Ignore:
Timestamp:
7 Dec 2006, 09:29:29 (18 years ago)
Author:
joachim
Message:

pume import check for duplicate on import

File:
1 edited

Legend:

Unmodified
Added
Removed
  • WAeUP_SRP/trunk/Students.py

    r981 r1005  
    269269        update = name.endswith('update')
    270270        no_import = []
    271         s = ','.join(['"(%s)"' % fn for fn in csv_fields])
     271        s = ','.join(['"%s"' % fn for fn in csv_fields])
    272272        no_import.append('%s' % s)
    273         open("%s/import/%s_not_imported.csv" % (i_home,name),"w").write(
    274                     '\n'.join(no_import))
     273        current = DateTime.DateTime().strftime("%d-%m-%y_%H_%M_%S")
     274        no_import_name = "%s/import/%s_not_imported_%s.csv" % (i_home,name,current)
     275        open(no_import_name,"w").write('\n'.join(no_import))
    275276        no_import = []
    276277        logger = logging.getLogger('%s_import' % name)
     
    285286        format = ','.join(['"%%(%s)s"' % fn for fn in csv_fields])
    286287        eduplicate = '"dupplicate",%s' % format
     288        added = 'added ,%s' % format
    287289        for jamb in result:
    288290            dict = {}
     
    293295            if len(res) > 0:
    294296                if update:
    295                     pume.modifyRecord(**dict)
     297                    try:
     298                        pume.modifyRecord(**dict)
     299                    except ValueError:
     300                        logger.info(eduplicate % jamb)
     301                        continue
     302                    except KeyError:
     303                        pume.addRecord(**dict)
     304                        logger.info(added % jamb)
     305                        continue
    296306                else:
    297307                    data = res[0]
     
    316326        logger.info('End loading from %s.csv' % name)
    317327        if len(no_import) > 1:
    318             open("%s/import/%s_not_imported.csv" % (i_home,name),"w+").write(
    319             '\n'.join(no_import))
     328            open(no_import_name,"w+").write('\n'.join(no_import))
    320329        return self.REQUEST.RESPONSE.redirect("%s" % self.REQUEST.get('URL1'))
    321330    ###)
Note: See TracChangeset for help on using the changeset viewer.