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 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 add(): try: title = request.params.get('title') brif_desc = request.params.get('brif_desc') description = request.params.get('description') item_type = request.params.get('item_type') item_code = request.params.get('item_code') link_url = request.params.get('link_url') position = request.params.get('position') small_pic = request.files.small_pic big_pic = request.files.big_pic module = request.params.get('module') timeflag = str(time.time()) big_pic_url="" if big_pic!='' and big_pic.filename: row = big_pic.file.read() name, ext = os.path.splitext(big_pic.filename) if ext not in ('.png','.jpg','.jpeg','.gif'): return 'File extension not allowed.' # big_pic.save(STATIC_PATH+'/upload_img/'+big_pic.filename) f= open(STATIC_PATH+'upload_img/big_'+name+'_'+timeflag + ext,'wb') f.write(row) big_pic_url = "upload_img/big_"+name+'_'+timeflag + ext f.close() small_pic_url="" if small_pic !='' and small_pic.filename: row = small_pic.file.read() name, ext = os.path.splitext(small_pic.filename) if ext not in ('.png','.jpg','.jpeg','.gif'): return 'File extension not allowed.' # small_pic.save(STATIC_PATH+'/upload_img/'+small_pic.filename) f= open(STATIC_PATH+'upload_img/small_'+name +'_'+ timeflag + ext,'wb') f.write(row) small_pic_url = "upload_img/small_"+name+'_'+timeflag + ext f.close() insert_sql = 'insert into gkgp_main_setting (title,brif_desc,description,item_type,item_code,link_url,position,small_pic,big_pic,module) \ values(%s,%s,%s,%s,%s,%s,%s,%s,%s,%s)' db.update(insert_sql,(title,brif_desc,description,item_type,item_code,link_url,position,small_pic_url,big_pic_url,module)) # request.query['typeid']=module return gotoindexsetting() except: traceback.print_exc() return "error"
def tomenu(): try: menuid= request.query.get('menuid') channelids = request.query.get('channelids') for cid in channelids.split('_'): if cid != '': delete_sql = "delete from HNSJ_TDCMS_MENU where parent=%s and path=%s" db.update(delete_sql,(menuid,'/chanel/gotochannel?cid='+cid)) insert_sql = "insert into HNSJ_TDCMS_MENU (menuname,path,parent) values(%s,%s,%s)" cname = getchannelnamebyid(cid) db.update(insert_sql,(cname,'/channel/gotochannel?cid='+cid,menuid)) return 'ok' except Exception,data: traceback.print_exc() return 'error'
def updatenote(): config_id = request.params.get('config_id') config_value=request.params.get('config_value') print config_value sql = 'update HNSJ_SYS_CONFIG set column_value=%s where id=%s' params=(config_value,config_id) res = db.update(sql,params) print res return getsysconfig()
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 updatenote(): note_id = request.params.get('note_id') note_value=request.params.get('note_value') print note_value sql = 'update HNSJ_SYS_CONFIG set column_value=%s where id=%s' params=(note_value,note_id) res = db.update(sql,params) print res return getnotice()
def reg(): userdata=dict(domain=SITE_DOMAIN,uerr="",nerr="",perr="",verr="",ref="") username = request.forms.get('username') password = request.forms.get('password') nickname = request.forms.get('nickname') varifycode = request.forms.get('varifycode') ref = request.forms.get('ref') sessionCode = getValInCookie(VREYCODE) delValFromCookie(VREYCODE) if(username.strip()==""): userdata['uerr']="邮箱不能为空!" return template('reg',userdata) if(not utils.ProcessMail(username)): userdata['uerr']="邮箱格式不正确!" return template('reg',userdata) if(getUserByUsername(username)!=None): userdata['uerr']="该邮箱已经存在!" return template('reg',userdata) if(len(password)<4 or len(password)>20): userdata['perr']="密码的长度在4-20之间!" return template('reg',userdata) if(getUserByNickname(nickname)!=None): userdata['nerr']="昵称已经存在!" return template('reg',userdata) if(varifycode.strip()==""): userdata['verr']="验证码不能为空!" return template('reg',userdata) if(varifycode.upper()!=sessionCode.upper()): userdata['verr']="验证码输入不一致!" return template('reg',userdata) sql = '''insert into gkgp_user ( username, password, nickname, create_time, last_login_time ) values (%s,%s,%s,%s,%s) ''' try: uid = dbsetting.update(sql,(username,utils.dest(password),nickname,datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S"),datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S"))) print "uid is %d" % uid addUidInCookie(uid) except Exception,e: print e
def add(): try: title = request.params.get('title') tid= request.params.get('id') brif_desc = request.params.get('brif_desc') description = request.params.get('description') item_type = request.params.get('item_type') item_code = request.params.get('item_code') link_url = request.params.get('link_url') position = request.params.get('position') smallpicname = request.params.get('smallpicname') bigpicname = request.params.get('bigpicname') small_pic = request.files.small_pic big_pic = request.files.big_pic module = request.params.get('module') print title big_pic_url="" timeflag = str(time.time()) if big_pic!='' and big_pic.file: row = big_pic.file.read() name, ext = os.path.splitext(big_pic.filename) if ext not in ('.png','.jpg','.jpeg','.gif'): return 'File extension not allowed.' # big_pic.save(STATIC_PATH+'/upload_img/'+big_pic.filename) f= open(STATIC_PATH+'upload_img/big_'+name+'_'+timeflag + ext,'wb') f.write(row) big_pic_url = "upload_img/big_"+name+'_'+timeflag + ext f.close() try: os.remove(STATIC_PATH+ bigpicname) except: traceback.print_exc() else: big_pic_url = bigpicname small_pic_url="" if small_pic !='' and small_pic.file: row = small_pic.file.read() name, ext = os.path.splitext(small_pic.filename) if ext not in ('.png','.jpg','.jpeg','.gif'): return 'File extension not allowed.' # small_pic.save(STATIC_PATH+'/upload_img/'+small_pic.filename) f= open(STATIC_PATH+'upload_img/small_'+name+'_'+timeflag + ext,'wb') f.write(row) small_pic_url = "upload_img/small_"+name+'_'+timeflag + ext f.close() try: os.remove(STATIC_PATH+ smallpicname) except: traceback.print_exc() else: small_pic_url=smallpicname print tid update_sql = 'update gkgp_main_setting set title=%s, brif_desc=%s,description=%s,item_type=%s,item_code=%s,link_url=%s,\ position=%s,small_pic=%s,big_pic=%s,module=%s where id=%s' db.update(update_sql,(title,brif_desc,description,item_type,item_code,link_url,position,small_pic_url,big_pic_url,module,tid)) request.query['moduleid']=module return gotoindexsetting() except: traceback.print_exc() return "修改错误"