使用Django来清理数据库中的数据(二)

2015-04-07 14:10:37 · 作者: · 浏览: 133
port/clean_data.html", context,
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? context_instance=RequestContext(req))
? ? ? ? for pid in projectIDs:
? ? ? ? ? ? try:
? ? ? ? ? ? ? ? cursor.execute(sql_getRecords,[lableName[0],str(pid[0])])
? ? ? ? ? ? ? ? records=cursor.fetchall()
? ? ? ? ? ? ? ? cursor.execute(sql_getLanguageSections,[str(pid[0])])
? ? ? ? ? ? ? ? languageSections=cursor.fetchall()
? ? ? ? ? ? except Exception,e:
? ? ? ? ? ? ? ? update_dcData_log.write(datetimestr()+'execute sql_getRecords or sql_getLanguageSections error '+str(e)+'\n')
? ? ? ? ? ? ? ? context=Context({'msg':'Error'})
? ? ? ? ? ? ? ? return render_to_response("report/clean_data.html", context,
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? context_instance=RequestContext(req))
? ? ? ? ? ? values,lgs=[],[]
? ? ? ? ? ? baseva lue=str(records[0][2])
? ? ? ? ? ? baseID=str(records[0][0])
? ? ? ? ? ? for item in records:
? ? ? ? ? ? ? ? lgs.append(str(item[1]))
? ? ? ? ? ? ? ? values.append(str(item[2]))
? ? ? ? ? ? ? ? if baseva lue!=str(item[2]):
? ? ? ? ? ? ? ? ? ? baseva lue='false'
? ? ? ? ? ? targetLgs=[str(item[0]) for item in languageSections]
? ? ? ? ? ? if len(lgs)<1 or len(targetLgs)<1:
? ? ? ? ? ? ? ? baseva lue=='false'
? ? ? ? ? ? if 'all' not in lgs:
? ? ? ? ? ? ? ? try:
? ? ? ? ? ? ? ? ? ? cursor.execute(sql_addRecordByID,[baseID])
? ? ? ? ? ? ? ? ? ? cursor.execute(sql_updateLgs,['all',baseID])
? ? ? ? ? ? ? ? ? ? transaction.commit_unless_managed()
? ? ? ? ? ? ? ? except Exception,e:
? ? ? ? ? ? ? ? ? ? update_dcData_log.write(datetimestr()+'execute sql_addRecordByID or sql_updateLgs error (all)'+str(e)+'\n')
? ? ? ? ? ? ? ? ? ? context=Context({'msg':'Error'})
? ? ? ? ? ? ? ? ? ? return render_to_response("report/clean_data.html", context,
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? context_instance=RequestContext(req))
? ? ? ? ? ? ? ? ? ? ? ?
? ? ? ? ? ? ? ? ? ? update_dcData_log.write(datetimestr()+"all record is add into dc_data,the lableName and projectID were "+str(lableName[0])+'-'+str(pid[0])+'\n')
? ? ? ? ? ?
? ? ? ? ? ? if baseva lue=='false':
? ? ? ? ? ? ? ? update_dcData_log.write(datetimestr()+"please update this record mutually,the lableName and projectID were "+str(lableName[0])+'-'+str(pid[0])+'\n')
? ? ? ? ? ? else:
? ? ? ? ? ? ? ? if len(lgs)>len(targetLgs):
? ? ? ? ? ? ? ? ? ? update_dcData_log.write(datetimestr()+"the lableName languageSection length is longer than target numbers lableName and projectID were "+str(lableName[0])+'-'+str(pid[0])+'\n')
? ? ? ? ? ? ? ? else:
? ? ? ? ? ? ? ? ? ? for lg in targetLgs:
? ? ? ? ? ? ? ? ? ? ? ? if lg not in lgs:
? ? ? ? ? ? ? ? ? ? ? ? ? ? try:
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? cursor.execute(sql_addRecordByID,[baseID])
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? cursor.execute(sql_updateLgs,[lg,baseID])
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? transaction.commit_unless_managed()
? ? ? ? ? ? ? ? ? ? ? ? ? ? except Exception,e:
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? update_dcData_log.write(datetimestr()+'execute sql_addRecordByID or sql_updateLgs error (lg)'+str(e)+'\n')
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? context=Context({'msg':'Error'})
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? return render_to_response("report/clean_data.html", context,
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? context_instance=RequestContext(req))
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?
? ? ? ? ? ? ? ? ? ? ? ? ? ? update_dcData_log.write(datetimestr()+lg+" record is add into dc_data,the lableName and projectID were "+str(lableName[0])+'-'+str(pid[0])+'\n')
? ? ? ? ? ? ? ? ? ? ? ?
? ? ? ? ? ? ? ? ? ?
? ? update_dcData_log.close()
? ? ? ? ? ?
? ? ? ? ? ?
? ? return? resp?


--------------------------------------分割线 --------------------------------------