import biz import pycomm from models.zqLeague import zqLeague as zlm class zqLeague(object): def __init__(self): self.csrc=biz.getCurrentSource() self.zqLeague=zlm() def getOutUid(self,lgid): return self.csrc+str(lgid) def update(self,data): da={} for i in data: da[i]=data[i] uid=self.getOutUid(da['league_id']) hasLeague=self.getLeague(da['league_id']) da['out_uid']=uid da['out_league_id']=da['league_id'] da.pop('league_id') if hasLeague==-1: self.zqLeague.save(da) else: self.zqLeague.update(da," out_uid='%s'" % uid) def getLeague(self,oleague_id): cond={} cond['where']="out_uid='%s'" %(self.getOutUid(oleague_id)) cond['fields']="league_id" data=self.zqLeague.select(cond) if not data: return -1 return data