def GET(self, id): page_info = PageInfo('Personal') ans1, temp1_user = infoDBserver.get_user(session.get_user_id()) ans2, temp2_user = infoDBserver.get_user(session.get_user_id()) if ans1 and ans2: current_user1 = transclass.user_trans(temp1_user) current_user2 = transclass.user_trans(temp2_user) return render.personal(current_user1, current_user2, page_info) else: raise web.notfound()
def GET(self, id): page_info = PageInfo('Video') ans1, temp_video = infoDBserver.get_video(id) current_video = transclass.video_trans(temp_video) ans2, temp_user = infoDBserver.get_user(session.get_user_id()) current_user = transclass.user_trans(temp_user) ans3, temp_user = infoDBserver.get_user(current_video.owner) video_owner = transclass.user_trans(temp_user) if ans1 and ans2 and ans3: return render.video(current_video,current_user,video_owner,page_info) else: raise web.nofound()
def GET(self, id): page_info = PageInfo('Video') ans1, temp_video = infoDBserver.get_video(id) current_video = transclass.video_trans(temp_video) ans2, temp_user = infoDBserver.get_user(session.get_user_id()) current_user = transclass.user_trans(temp_user) ans3, temp_user = infoDBserver.get_user(current_video.owner) video_owner = transclass.user_trans(temp_user) if ans1 and ans2 and ans3: return render.video(current_video, current_user, video_owner, page_info) else: raise web.nofound()
def GET(self): page_info = PageInfo('About us') ans, temp_user = infoDBserver.get_user(session.get_user_id()) if ans: current_user = transclass.user_trans(temp_user) return render.about(current_user, page_info) return render.about("", page_info)
def POST(self, id, encodedURL): session_id = session.get_user_id() userId = int(id) if userId != session_id: js = {} js['ok'] = False js['message'] = "web.notfound()" ans = json.dumps(js) return ans # raise web.notfound() newKey = None try: with open(tmp_img_path(id), 'rb') as f: uploadURL = base64.urlsafe_b64decode(str(encodedURL)) newKey, err = fs.putFile(f, uploadURL) if err != None: web.debug(err) js = {} js['ok'] = False js['message'] = u"头像上传失败" ans = json.dumps(js) return ans # raise web.seeother('/personal_edit/' + id) except IOError: pass x = web.input() web.debug(x.uname) web.debug(x.email) web.debug(newKey) ans, temp_user = infoDBserver.get_user(session_id) if not ans: raise web.notfound() if x.uname: temp_user.userName = x.uname if x.email: temp_user.mail = x.email if newKey: temp_user.picKey = newKey js = {} js['ok'] = True js['message'] = "Everything is OK~" ret = infoDBserver.modify_user(userId, temp_user) if not ret: web.debug(ret) js['ok'] = False js['message'] = 'update user info failed.' try: os.remove(tmp_img_path(id)) except: pass ans = json.dumps(js) return ans
def getFriends(self, userId, limit=20): friends = [] ans, temp_friends = infoDBserver.get_aFollows(userId) if ans and temp_friends != None: for element in temp_friends: success, bigfriend = infoDBserver.get_user(element.bId) if success: friend = transclass.friend_trans(bigfriend) friends.append(friend) return friends
def GET(self, id): page_info = PageInfo('Edit') ans1, temp_video = infoDBserver.get_video(id) ans2, temp_user = infoDBserver.get_user(session.get_user_id()) if ans1 and ans2: current_video = transclass.video_trans(temp_video) current_user = transclass.user_trans(temp_user) return render.edit(current_video, current_user, page_info) else: raise web.nofound() return render.edit(current_video, current_user, page_info)
def GET(self, id): page_info = PageInfo('Edit') ans1, temp_video = infoDBserver.get_video(id) ans2, temp_user = infoDBserver.get_user(session.get_user_id()) if ans1 and ans2: current_video = transclass.video_trans(temp_video) current_user = transclass.user_trans(temp_user) return render.edit(current_video,current_user,page_info) else: raise web.nofound() return render.edit(current_video, current_user, page_info)
def getVideos(self, userId, limit=20): #use 20 as default limit of videos videos = [] ans, user = infoDBserver.get_user(userId) if ans and user.videos != None: i = 0 for element in user.videos: videos.append(transclass.video_trans(element)) i += 1 if i >= limit: break return videos
def GET(self): uploadURL, err = fs.putAuth() if err != None: web.debug(err) raise web.notfound() encodedURL = base64.urlsafe_b64encode(uploadURL) page_info = PageInfo('Upload') ans, temp_user = infoDBserver.get_user(session.get_user_id()) if ans: current_user = transclass.user_trans(temp_user) return render.upload(current_user, page_info,encodedURL) else: return web.notfound()
def GET(self): uploadURL, err = fs.putAuth() if err != None: web.debug(err) raise web.notfound() encodedURL = base64.urlsafe_b64encode(uploadURL) page_info = PageInfo('Upload') ans, temp_user = infoDBserver.get_user(session.get_user_id()) if ans: current_user = transclass.user_trans(temp_user) return render.upload(current_user, page_info, encodedURL) else: return web.notfound()
def GET(self): temp = session.is_logged() if temp: page_info = PageInfo('Index') current_userid = session.get_user_id() ans, temp_user = infoDBserver.get_user(current_userid) if ans: current_user = transclass.user_trans(temp_user) else: raise web.seeother('/login') return render.index(current_user, page_info) ##current_user = default_user ##return render.index(default_user, page_info) else: raise web.seeother('/login')
def POST(self,id): ans, bigUser = infoDBserver.get_user(id) if ans: current_user = transclass.user_trans(bigUser) current_user.pwd = '' js = {} js['ok'] = True js1 = {} js1['user'] = current_user.__dict__ js['data'] = js1 return_message = json.dumps(js) else: js = {} js['ok'] = False return_message = json.dumps(js) return return_message
def POST(self,id): data = web.input() page_info = PageInfo('Edit') ##return render.edit(default_video, default_user,page_info) ans, temp_video = infoDBserver.modify_video(id, videoName = data.video_name, intro = data.video_intro) ans2, temp_user = infoDBserver.get_user(session.get_user_id()) if ans2: current_user = transclass.user_trans(temp_user) else: raise web.nofound() if ans: current_video = transclass.video_trans(temp_video) page_info = PageInfo('Edit',message = '保存成功!') raise web.seeother('/video/'+str(current_video.id)) else: page_info = PageInfo('Edit',error = '保存失败,请再试!') return render.edit(current_video,current_user,page_info)
def POST(self,id): current_userid = session.get_user_id() ans, bigFollow = infoDBserver.insert_follow(current_userid, id) if ans != False: usersFind, current_user = infoDBserver.get_user(current_userid) success, bigNotice = infoDBserver.insert_notice(current_userid, id, 1, str(current_user.userName)+' is following you. Click it to see.', '/personal/'+str(current_userid)) js = {} js['ok'] = True js['message'] = '成功添加好友!' return_message = json.dumps(js) return return_message else: js = {} js['ok'] = False js['message'] = '添加好友失败!' return_message = json.dumps(js) return return_message
def GET(self): temp = session.is_logged() if temp: page_info = PageInfo('Index') current_userid = session.get_user_id() ans, temp_videoList = infoDBserver.get_video() recommend_videoList = transclass.videoList_trans(temp_videoList) ans, temp_user = infoDBserver.get_user(current_userid) if ans: current_user = transclass.user_trans(temp_user) else: raise web.seeother('/login') funcs.getNotices(current_userid) funcs.getFriends(current_userid) return render.index(current_user, recommend_videoList , page_info) else: raise web.seeother('/login')
def GET(self, id): session_id = session.get_user_id() if int(id) != session_id: raise web.notfound() uploadURL, err = fs.putAuth() if err != None: web.debug(err) raise web.notfound() encodedURL = base64.urlsafe_b64encode(uploadURL) page_info = PageInfo('Personal Edit') ans, temp_user = infoDBserver.get_user(session_id) if ans: current_user = transclass.user_trans(temp_user) return render.personal_edit(current_user, page_info, encodedURL) else: raise web.notfound()
def POST(self,id): data = web.input() username = data.userName userpwd = data.userPwd success, bigVideo = infoDBserver.get_video(id) if success: success0, bigUser = infoDBserver.get_user(session.get_user_id()) if bigUser.userName == username and bigUser.passwd == userpwd: success1 = infoDBserver.delete_video(id) if success1: ans = delete2json(True, "successful") else: ans = delete2json(False, "郭哥挂了") else: ans = delete2json(False, "用户名密码错误") else: ans = delete2json(False, "没有此视频") return ans
def POST(self, id): data = web.input() page_info = PageInfo('Edit') ##return render.edit(default_video, default_user,page_info) ans, temp_video = infoDBserver.modify_video(id, videoName=data.video_name, intro=data.video_intro) ans2, temp_user = infoDBserver.get_user(session.get_user_id()) if ans2: current_user = transclass.user_trans(temp_user) else: raise web.nofound() if ans: current_video = transclass.video_trans(temp_video) page_info = PageInfo('Edit', message='保存成功!') raise web.seeother('/video/' + str(current_video.id)) else: page_info = PageInfo('Edit', error='保存失败,请再试!') return render.edit(current_video, current_user, page_info)
def POST(self,id): data = web.input() currentuser_id = session.get_user_id() reply_userid = data.toId content = data.content ans, bigComment = infoDBserver.insert_comment(id, currentuser_id, reply_userid, content) if ans: success, bigVideo = infoDBserver.get_video(id) success0, bigUser = infoDBserver.get_user(currentuser_id) if success: success1, bigNotice = infoDBserver.insert_notice(currentuser_id, bigVideo.ownerId, 2, str(bigUser.userName)+' replied to your video', '/video/'+str(id)) if data.toId!=None: success2, bigNotice = infoDBserver.insert_notice(currentuser_id, data.toId, 2, str(bigUser.userName)+' replied to your comments in video '+str(bigVideo.videoName),'/video/'+str(id)) comments = [] comments.append(transclass.comment_trans(bigComment)) return_message = comment2json(True,comments) else: return_message = comment2json(False, None) return return_message
def getUserInfo(self, userId): user = model.User() ans, bigUser = infoDBserver.get_user(userId) user = transclass.user_trans(bigUser) return user