Пример #1
0
def shorten_material_id(old_id):
    """ Reduce length of long material IDs from 32 to 8 characters
    """
    try:
        new_id = generateMaterialId()
        Material.objects.filter(material_id=old_id).update(material_id=new_id)
        OriginalID.objects.filter(material_id=old_id).update(material_id=new_id)
        MaterialFile.objects.filter(material_id=old_id).update(material_id=new_id)
        MaterialExport.objects.filter(material_id=old_id).update(material_id=new_id)
        print '%s >> %s' % (old_id, new_id)
    except:
        print 'Error with ' + old_id
Пример #2
0
def shorten_material_id_2(old_id):
    """ Reduce length of long material IDs from 32 to 8 characters
    """
    cur = connection.cursor()
    try:
        new_id = generateMaterialId()
        tables = (
            'vpr_content_material',
            'vpr_content_originalid', 
            'vpr_content_materialexport',
            'vpr_content_materialfile'
            )
        for t in tables:
            sql = """UPDATE %s SET material_id='%s' WHERE material_id='%s';""" \
                % (t, new_id, old_id)
            res = cur.execute(sql)
        transaction.commit_unless_managed()
        print '%s >> %s' % (old_id, new_id)
    except:
        raise
        print 'Error with ' + old_id