def tomenu(): try: menuid= request.query.get('menuid') channelids = request.query.get('channelids') flag=False for cid in channelids.split('_'): if cid != '': select_sql = "select count(*) from gkgp_cms_menu where parent=%s and path=%s" res = db.query_one(select_sql,(menuid,'/channel/gotochannel?cid='+cid)) if res[0]>0: flag=True continue # delete_sql = "delete from gkgp_cms_menu where parent=%s and path=%s" # db.update(delete_sql,(menuid,'/channel/gotochannel?cid='+cid)) insert_sql = "insert into gkgp_cms_menu (menuname,path,parent) values(%s,%s,%s)" cname = getchannelnamebyid(cid) db.update(insert_sql,(cname,'/channel/gotochannel?cid='+cid,menuid)) if flag : return "exist" else: return 'ok' except Exception,data: traceback.print_exc() return 'error'
def getUserByNameAndPass(username,password): sql = "select * from gkgp_user where username=%s and password=%s"; try: return dbsetting.query_one(sql,(username,password)) except: traceback.print_exc() return None
def bury(itemcode): try: uid = get_cookie(UID) if uid is None: return 'noLogin' else: item = db.query_one('select t.id,t.itemcode,t.burytimes \ from gkgp_item t where t.itemcode=%s',itemcode) if item is not None: digOrBuryHistory = get_cookie('DigOrBury_'+itemcode) if digOrBuryHistory is not None and len(digOrBuryHistory)>0: if item[2] is not None: return beautifulDisPlay(str(item[2])) else: return '0' else: if item[2] is not None: temp = item[2]+1 db.update('update gkgp_item set burytimes=%s where id=%s',(temp,item[0])) set_cookie('DigOrBury_'+itemcode,itemcode) return beautifulDisPlay(str(temp)) else: return '0' else: return '0' except Exception: traceback.print_exc() return 'bury error'
def getnotice(): d={} sql = 'select id,column_value from HNSJ_SYS_CONFIG WHERE column_name=%s' params=('MARQUEE_NOTE') res = db.query_one(sql,params) print res d['note_id'] = res[0] d['note_value'] =res[1] return dict(note=d,domain=SITE_DOMAIN)
def gotoedit(): vid = request.query.get('id') sql = "select itemid,description,picurl,productid,status,title from HNSJ_TDCMS_CHANNEL_ITEM where itemid=%s" video = db.query_one(sql,(vid)) print video #-----get product --------- sql = "select t1.id ,t1.item_id,t1.product_id,t.sp_productid from HNSJ_VAC_PROINFO t,HNSJ_TDCMS_ITEM_PRODUCT t1 where \ t.sp_productid = t1.product_id and t1.id = %s" p = db.query_list(sql,(video[0])) #-----get support cpids---- sql = "select column_value from HNSJ_SYS_CONFIG where column_name = %s" cpids = db.query_one(sql,('SUPPORT_CP_IDS'))[0] print cpids cpidsql = ','.join(cpids.split(',')) print cpidsql #------get all product------ sql = "select sp_productid,productname from HNSJ_VAC_PROINFO where spid in (%s)" allproductlist = db.query_list(sql,(cpidsql)) return dict(v = video,domain=SITE_DOMAIN,allproductlist=allproductlist,p=p)
def play(itemcode): item = db.query_one('select t1.id,t1.itemcode,t.username,t.id,t1.title,t1.addtime,t1.description,t1.playtimes,t1.digtimes,t1.burytimes \ ,t1.pics from gkgp_user t,gkgp_item t1 ,gkgp_user_item t2 where t1.id = t2.videoid and t2.userid = t.id and \ itemcode=%s',(itemcode)) # put play history into cookie # key : playlist # value : {'itemcode1','itemcode3','itemcode4'} playlist = get_cookie('playlist') if playlist: l=json.loads(playlist) if itemcode not in l: if(len(l)>=10): del l[0] l.append(itemcode) else: l.append(itemcode) set_cookie('playlist',json.dumps(l)) else: l=[] l.append(itemcode) set_cookie('playlist',json.dumps(l)) # end if item is not None: playtime = 0 if item[7] is not None and item[7]>=0: playtime = item[7]+1 else: playtime =1 db.update('update gkgp_item set playtimes=%s where id=%s',(playtime,item[0])) #首发 firstvideo = main.changeVideo(main.findItem(8,5)) # get user other videos othervideos = db.query_list('select t.title,t.pics,t.itemcode from gkgp_item t, \ gkgp_user_item t1 where t.id=t1.videoid and t1.userid=%s order by t.addtime desc limit 0,4 ',(item[3])) item = list(item) item[7] = beautifulDisPlay(str(item[7])) item[8] = beautifulDisPlay(str(item[8])) item[9] = beautifulDisPlay(str(item[9])) return dict(domain=SITE_DOMAIN,picdomain=PIC_DOMAIN,itemcode=itemcode,item=item,firstvideo=firstvideo,othervideos=othervideos)
def delete(): id = request.query.get('id') try: if id.index(',')!=-1: id = id[0:-1] ids = id.split(',') #print ids if 0 < len(ids): for i in range(len(ids)): item = db.query_one('select id,small_pic,big_pic from gkgp_main_setting where id =%s',ids[i]) #print item if item[1] is not None and len(item[1])>0 and os.path.exists(STATIC_PATH+item[1]): os.remove(STATIC_PATH+item[1]) if item[2] is not None and len(item[2])>0 and os.path.exists(STATIC_PATH+item[2]): os.remove(STATIC_PATH+item[2]) db.delete('delete from gkgp_main_setting where id = %s',item[0]) return gotoindexsetting() except: traceback.print_exc() return "delete index setting error"
def getchannelnamebyid(id): sql = "select name from HNSJ_TDCMS_CHANNEL where id = %s" return db.query_one(sql,(id))[0]
def getchannelnamebyid(id): sql = "select channel_name from gkgp_channel where id = %s" return db.query_one(sql,(id))[0]
def gotoedit(): ids = request.query.get('id') moduleid = request.query.get('moduleid') id=ids.split('_')[0] item = db.query_one('select * from gkgp_main_setting where id = %s',(id)) return template('main/main_edit',dict(domain=SITE_DOMAIN,itemdict=itemdict,selectmodule=moduleid,moduledict=moduledict,item=item))
def getUserByUsername(username): sql = "select * from gkgp_user where username=%s" return dbsetting.query_one(sql,username)
def getUserByNameAndPass(username,password): sql = "select * from gkgp_user where username=%s and password=%s"; return dbsetting.query_one(sql,(username,password))
def getUserByNickname(nickname): sql = "select * from gkgp_user where nickname=%s" return dbsetting.query_one(sql,nickname)
def getItemCountByUid(item_type,Uid): sql="select count(*) from gkgp_channel_item_link where item_type=%s and uid=%s" return db.query_one(sql,(item_type,Uid))
def getItemCountByChannelId(item_type,chId): '''获取条件下视频的总条数''' sql = "select count(*) from gkgp_channel_item_link where item_type=%s and channel_id=%s and status=1" return db.query_one(sql,(item_type,chId))
def getUserInfoById(id): sql = "select * from gkgp_user where id=%s" return dbsetting.query_one(sql,id)