def GET(self, token): newTime = time.mktime(time.localtime())#得到访问reset页面的时间 #s_newTime = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(newTime)) timestamp = users.get_timestamp(token)#将 token 传到 model ,寻找对应的timestamp #s_timestamp = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(timestamp)) noExist = users.passwordReset(token)#将 token 传到 model 中进行比对,看是否正确 if noExist : return view.base( view.token_not_found(error_message = '<span class="alert alert-error">sorry,token不存在,你访问的地址无效,请检查你的url是否写错。</span>'), user, site_name ) elif newTime - timestamp > 604800 : #users.delete_SesetLog(token)#删除此过期的记录 return view.base( view.token_not_found(error_message = '<span class="alert alert-error">时间过去一周多,地址已经失效了。</span>'), user, site_name ) elif users.get_valid(token) == 1: return view.base( view.token_not_found(error_message = '<span class="alert alert-error">地址已经失效了。</span>'), user, site_name ) else: return render_account( show = 'reset_password_only', token = token )
def GET(self, token): newTime = time.mktime(time.localtime()) #得到访问reset页面的时间 #s_newTime = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(newTime)) timestamp = users.get_timestamp( token) #将 token 传到 model ,寻找对应的timestamp #s_timestamp = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(timestamp)) noExist = users.passwordReset(token) #将 token 传到 model 中进行比对,看是否正确 if noExist: return view.base( view.token_not_found( error_message= '<span class="alert alert-error">sorry,token不存在,你访问的地址无效,请检查你的url是否写错。</span>' ), user, site_name) elif newTime - timestamp > 604800: #users.delete_SesetLog(token)#删除此过期的记录 return view.base( view.token_not_found( error_message= '<span class="alert alert-error">时间过去一周多,地址已经失效了。</span>'), user, site_name) elif users.get_valid(token) == 1: return view.base( view.token_not_found( error_message= '<span class="alert alert-error">地址已经失效了。</span>'), user, site_name) else: return render_account(show='reset_password_only', token=token)
def GET(self, token): CE = users.get_confirm_email(token) if CE : new = time.time() #得到访问当前页面时的时间 old = time.mktime(CE.get('timestamp').timetuple()) if new - old > 86400: #24小时 return view.base(view.confirm_email(msg="out-time"), user, site_name) else: users.update_confirm_email(token) return view.base(view.confirm_email(msg="succes"), user, site_name) else: raise web.notfound()
def GET(self, token): CE = users.get_confirm_email(token) if CE: new = time.time() #得到访问当前页面时的时间 old = time.mktime(CE.get('timestamp').timetuple()) if new - old > 86400: #24小时 return view.base(view.confirm_email(msg="out-time"), user, site_name) else: users.update_confirm_email(token) return view.base(view.confirm_email(msg="succes"), user, site_name) else: raise web.notfound()
def render_settings(nickname_form=nickname_form(), email_form=email_form(), password_form=password_form(), on_success_message=''): counts = applicants.get_counts() user = session.get_session() return view.base( view.settings(user, nickname_form, email_form, password_form, on_success_message) )
def GET(self): last_users = users.last_users().list() last_image = image.get_last_image().list() #得到最新图片的上传者ID authorsID = [] for u in last_image: authorsID += str(u.userID).split() #根据ID去用户表查找 authors = [] for i in xrange(len(authorsID)): authors += users.get_users_by_id(authorsID[i]) #得到最新图片ID # img_ids = [] # for i in last_image: # img_ids += str(i.id).split() #得到最新图片的被喜欢数 # count = [] # for i in xrange(len(img_ids)): # count += str(image.GetFavUserCount(img_ids[i])) rights = None notification_results = None notification_num = None ntf_list = None ntf_posts = None ntf_users = None apply_log = {} return view.base(view.explore(last_users, last_image, authors), user, siteName, rights, ntf_list, notification_num, ntf_posts, ntf_users )
def GET(self, id): img = image.get_img_by_imgid(id) if img: i = web.input(start=0, order=default_order, desc='desc', query='') start = int(i.start) user_id = session.is_logged() and session.get_user_id() author_id = img.userID results, num_results = image.query(author_id) pager = web.storage(paging.get_paging_results(start, num_results, int(id), results, results_per_page)) #tm = time.strftime('%Y年%m月%d日', time.localtime(img.creationTime)) author = users.get_user_by_id(img.userID) results = list(results) is_favorite = image.IsFavorite(user_id, img.id) #得到被多少人喜欢 #count = image.GetFavUserCount(img_id) #浏览人数加1 if user_id and image.user_not_viewed_image(user_id, id): image.add_img_hit(id) image.add_user_to_img_viewed(user_id, id) #得到评论 comments = image.get_comment_by_image_id(id).list() #得到评论者信息 comments_authors_ids = [] for i in xrange(len(comments)): #comments_authors_ids += str(comments[i].user_id).split() comments_authors_ids += users.get_users_by_id(comments[i].user_id).list() return view.base(view.photo_single(img, pager, user_id, user, author, is_favorite, comments, comments_authors_ids), user, siteName) else: raise web.notfound()
def GET(self): last_users = users.last_users().list() last_image = image.get_last_image().list() #得到最新图片的上传者ID authorsID = [] for u in last_image: authorsID += str(u.userID).split() #根据ID去用户表查找 authors = [] for i in xrange(len(authorsID)): authors += users.get_users_by_id(authorsID[i]) #得到最新图片ID # img_ids = [] # for i in last_image: # img_ids += str(i.id).split() #得到最新图片的被喜欢数 # count = [] # for i in xrange(len(img_ids)): # count += str(image.GetFavUserCount(img_ids[i])) return view.base(view.explore(last_users, last_image, authors), user, siteName)
def GET(self, username, p=1): u = users.get_user_by_username(username) profile = users.get_profile_by_user_id(u.id) page = int(p) perpage = 10 offset = (page - 1) * perpage posts = postModel.groupGetCreatedPostsByUserId(u.id, offset, perpage).list() nodeids = [] for i in xrange(len(posts)): nodeids += str(posts[i].nodeId).split() nodeList = [] for i in xrange(len(nodeids)): nodeList += nodeModel.getNodesByNodeId(nodeids[i]) authors = [] for i in xrange(len(nodeList)): authors += users.get_users_by_id(nodeList[i].node_author) #是否登录, if user.is_logged: per = users.get_permission_by_douid(user.douban_id) rights = per[0].rights #得到提醒 notification_results, notification_num = notification.get_unread_notification(user.id) #得到@提醒 notification_mention_results, mention_num= notification.get_unread_metion_notifition(user.id) #链表 得到提醒的详细id\名称等 ntf_posts = [] ntf_users = [] mtf_posts = [] mtf_users = [] ntf_list = notification_results.list() mtf_list = notification_mention_results.list() for x in xrange(len(ntf_list)): ntf_posts += postModel.getPostsByPostId(ntf_list[x].pid) ntf_users += users.get_users_by_id(ntf_list[x].uid) for x in xrange(len(mtf_list)): mtf_posts += postModel.getPostsByPostId(mtf_list[x].pid) mtf_users += users.get_users_by_id(mtf_list[x].uid) ntf_list = ntf_list + mtf_list ntf_posts = ntf_posts + mtf_posts ntf_users = ntf_users + mtf_users notification_num = notification_num+mention_num else: rights = 0 is_voted = None notification_results = None notification_num = None ntf_list = None ntf_posts = None ntf_users = None return view.base(view.member_node_contributed(u, profile, nodeList, authors),user, siteName, rights, ntf_list, notification_num, ntf_posts, ntf_users)
def GET(self): if user.is_logged: per = users.get_permission_by_douid(user.douban_id) rights = per[0].rights else: rights = 0 return view.base(view.blog(), user, siteName, rights, ntf_list, notification_num, ntf_posts, ntf_users)
def GET(self): per = users.get_permission_by_douid(user.douban_id) rights = per[0].rights if rights > 0: #权限判断 return view.base(view.node_new(), user, siteName, rights, ntf_list=None, notification_num=None, ntf_posts=None, ntf_users=None) else: raise web.notfound()
def GET(self, arg, p=1): node = nodeModel.getNodeByNodeId(arg) if node: timestrf = misc.timestrf page = int(p) perpage = 10 offset = (page - 1) * perpage node_author_info = users.get_user_by_id(node.node_author) postList = postModel.getPostListByNodeIdSortByScore(arg, offset, perpage).list() a = [] for post in postList: a += str(post.postAuthor).split() authors = [] for i in xrange(len(a)): authors += users.get_users_by_id(a[i]) #得到权限 if user.is_logged: per = users.get_permission_by_douid(user.douban_id) rights = per[0].rights #得到提醒 notification_results, notification_num = notification.get_unread_notification(user.id) #得到@提醒 notification_mention_results, mention_num= notification.get_unread_metion_notifition(user.id) #链表 得到提醒的详细id\名称等 ntf_posts = [] ntf_users = [] mtf_posts = [] mtf_users = [] ntf_list = notification_results.list() mtf_list = notification_mention_results.list() for x in xrange(len(ntf_list)): ntf_posts += postModel.getPostsByPostId(ntf_list[x].pid) ntf_users += users.get_users_by_id(ntf_list[x].uid) for x in xrange(len(mtf_list)): mtf_posts += postModel.getPostsByPostId(mtf_list[x].pid) mtf_users += users.get_users_by_id(mtf_list[x].uid) ntf_list = ntf_list + mtf_list ntf_posts = ntf_posts + mtf_posts ntf_users = ntf_users + mtf_users notification_num = notification_num+mention_num else: rights = 0 notification_results = None notification_num = None ntf_list = None ntf_posts = None ntf_users = None return view.base(view.node_show(timestrf, rights, node, postList, node_author_info, user, authors, sort='interesting'), user, siteName, rights, ntf_list, notification_num, ntf_posts, ntf_users) else: raise web.notfound()
def GET(self): rights = None ntf_list = None notification_num = None ntf_posts = None ntf_users = None return view.base(view.member_setting_avatar(user, mid_src=''), user, siteName, rights, ntf_list, notification_num, ntf_posts, ntf_users)
def GET(self): last_users = users.last_users().list() last_image = image.get_last_image().list() #得到最新图片的上传者ID authorsID = [] for u in last_image: authorsID += str(u.userID).split() #根据ID去用户表查找 authors = [] for i in xrange(len(authorsID)): authors += users.get_users_by_id(authorsID[i]) #得到最新图片ID # img_ids = [] # for i in last_image: # img_ids += str(i.id).split() #得到最新图片的被喜欢数 # count = [] # for i in xrange(len(img_ids)): # count += str(image.GetFavUserCount(img_ids[i])) rights = None notification_results = None notification_num = None ntf_list = None ntf_posts = None ntf_users = None apply_log = {} return view.base(view.explore(last_users, last_image, authors), user, siteName, rights, ntf_list, notification_num, ntf_posts, ntf_users)
def GET(self, username, p=1): u = users.get_user_by_username(username) print user if u: page = int(p) perpage = 5 offset = (page - 1) * perpage created_posts = postModel.getCreatedPostsByUserId(u.id, offset, perpage).list() nodes = [] for i in xrange(len(created_posts)): nodes += nodeModel.getNodesByNodeId(created_posts[i].nodeId) #得到资料 profile = users.get_profile_by_user_id(u.id) #是否登录, if user.is_logged: per = users.get_permission_by_douid(user.douban_id) rights = per[0].rights #得到提醒 notification_results, notification_num = notification.get_unread_notification(user.id) #得到@提醒 notification_mention_results, mention_num= notification.get_unread_metion_notifition(user.id) #链表 得到提醒的详细id\名称等 ntf_posts = [] ntf_users = [] mtf_posts = [] mtf_users = [] ntf_list = notification_results.list() mtf_list = notification_mention_results.list() for x in xrange(len(ntf_list)): ntf_posts += postModel.getPostsByPostId(ntf_list[x].pid) ntf_users += users.get_users_by_id(ntf_list[x].uid) for x in xrange(len(mtf_list)): mtf_posts += postModel.getPostsByPostId(mtf_list[x].pid) mtf_users += users.get_users_by_id(mtf_list[x].uid) ntf_list = ntf_list + mtf_list ntf_posts = ntf_posts + mtf_posts ntf_users = ntf_users + mtf_users notification_num = notification_num+mention_num else: rights = 0 is_voted = None notification_results = None notification_num = None ntf_list = None ntf_posts = None ntf_users = None return view.base(view.member_home(u, profile, created_posts, nodes, user), user, siteName, rights, ntf_list, notification_num, ntf_posts, ntf_users) else: raise web.notfound()
def GET(self): per = users.get_permission_by_douid(user.douban_id) rights = per[0].rights if rights > 1: postList = postModel.getRecent20Posts() return view.base(view.post_latest(postList), user, siteName, rights, ntf_list=None, notification_num=None, ntf_posts=None, ntf_users=None) else: raise web.notfound()
def POST(self): data = web.input(path={}) paths = data.get('path').split(',') names = data.get('name').split(',') userID = user.id #creationTime = time.mktime(time.localtime()) image.AddImage(paths, names, userID) #入库 return view.base(view.media_describe(paths, names), user, siteName)
def render_account(show='all', login_form=login_form(), register_form=register_form(), forgot_password_form=forgot_password_form(), on_success_message=''): return view.base( view.account(show, login_form, register_form, forgot_password_form, on_success_message))
def GET(self): rights = None ntf_list = None notification_num = None ntf_posts = None ntf_users = None return view.base(view.home(), user, site_name, rights, ntf_list, notification_num, ntf_posts, ntf_users)
def GET(self): rights=None ntf_list=None notification_num=None ntf_posts=None ntf_users=None return view.base(view.home(), user, site_name, rights, ntf_list, notification_num, ntf_posts, ntf_users )
def render_settings(nickname_form=nickname_form(), email_form=email_form(), password_form=password_form(), on_success_message=''): counts = applicants.get_counts() user = session.get_session() return view.base( view.settings(user, nickname_form, email_form, password_form, on_success_message))
def GET(self): if user.is_logged: per = users.get_permission_by_douid(user.douban_id) rights = per[0].rights if rights > 1: return view.base(view.update(), user, siteName, rights, ntf_list, notification_num, ntf_posts, ntf_users) else: raise web.notfound() else: raise web.notfound()
def render_account(show='all', login_form=login_form(), register_form=register_form(), forgot_password_form=forgot_password_form(), reset_password_form=reset_password_form(), token = '', on_success_message='', error_message=''): rights=None ntf_list=None notification_num=None ntf_posts=None ntf_users=None return view.base( view.account(show, login_form, register_form, forgot_password_form, reset_password_form, token, on_success_message, error_message), user, site_name, rights, ntf_list, notification_num, ntf_posts, ntf_users )
def GET(self, arg): per = users.get_permission_by_douid(user.douban_id) rights = per[0].rights if rights > 0: #权限判断 node = nodeModel.getNodeByNodeId(arg) if node: return view.base(view.post_new(arg, node, user), user, siteName, rights, ntf_list=None, notification_num=None, ntf_posts=None, ntf_users=None) else: raise web.notfound() else: raise web.notfound()
def GET(self, username, p=1): u = users.get_user_by_username(username) profile = users.get_profile_by_user_id(u.id) page = int(p) perpage = 10 offset = (page - 1) * perpage nodeList = nodeModel.getCreatedNodesByUserId(u.id, offset, perpage).list() #是否登录, if user.is_logged: per = users.get_permission_by_douid(user.douban_id) rights = per[0].rights #得到提醒 notification_results, notification_num = notification.get_unread_notification( user.id) #得到@提醒 notification_mention_results, mention_num = notification.get_unread_metion_notifition( user.id) #链表 得到提醒的详细id\名称等 ntf_posts = [] ntf_users = [] mtf_posts = [] mtf_users = [] ntf_list = notification_results.list() mtf_list = notification_mention_results.list() for x in xrange(len(ntf_list)): ntf_posts += postModel.getPostsByPostId(ntf_list[x].pid) ntf_users += users.get_users_by_id(ntf_list[x].uid) for x in xrange(len(mtf_list)): mtf_posts += postModel.getPostsByPostId(mtf_list[x].pid) mtf_users += users.get_users_by_id(mtf_list[x].uid) ntf_list = ntf_list + mtf_list ntf_posts = ntf_posts + mtf_posts ntf_users = ntf_users + mtf_users notification_num = notification_num + mention_num else: rights = 0 is_voted = None notification_results = None notification_num = None ntf_list = None ntf_posts = None ntf_users = None return view.base(view.member_node(u, profile, nodeList, user), user, siteName, rights, ntf_list, notification_num, ntf_posts, ntf_users)
def GET(self): per = users.get_permission_by_douid(user.douban_id) rights = per[0].rights if rights > 1: nodeList = nodeModel.getLastNodes().list() authors = [] for i in xrange(len(nodeList)): authors += users.get_users_by_id(nodeList[i].node_author) return view.base(view.node_all(nodeList, authors), user, siteName, rights, ntf_list=None, notification_num=None, ntf_posts=None, ntf_users=None) else: return web.notfound()
def GET(self): per = users.get_permission_by_douid(user.douban_id) rights = per[0].rights postList = postModel.getRecent20Posts() return view.base(view.post_latest(postList), user, siteName, rights, ntf_list=None, notification_num=None, ntf_posts=None, ntf_users=None)
def GET(self, img_id): img = image.get_img_by_imgid(img_id) author = web.listget(users.get_users_by_id(img.userID) , 0, {}) fav_user = image.GetFavImageByImageId(img_id).list() fav_user_ids = [] for i in xrange(len(fav_user)): fav_user_ids += str(fav_user[i].user_id).split() usernnames = [] for i in xrange(len(fav_user_ids)): usernnames += users.get_users_by_id(fav_user_ids[i]) return view.base(view.photo_fans(img_id, img, usernnames, author), user, siteName)
def GET(self): # u = users.get_user_by_id(session.get_user_id()) # ut = u.nicknameChangeTime #得到上次修改昵称的时间 # c = datetime.datetime.now()#得到当前时间 # if (c - ut).days < 30: #时间差 # can_change_nickname = False # else: # can_change_nickname = True #得到权限 per = users.get_permission_by_douid(user.douban_id) rights = per[0].rights #得到提醒 notification_results, notification_num = notification.get_unread_notification( user.id) #得到@提醒 notification_mention_results, mention_num = notification.get_unread_metion_notifition( user.id) #链表 得到提醒的详细id\名称等 ntf_posts = [] ntf_users = [] mtf_posts = [] mtf_users = [] ntf_list = notification_results.list() mtf_list = notification_mention_results.list() for x in xrange(len(ntf_list)): ntf_posts += postModel.getPostsByPostId(ntf_list[x].pid) ntf_users += users.get_users_by_id(ntf_list[x].uid) for x in xrange(len(mtf_list)): mtf_posts += postModel.getPostsByPostId(mtf_list[x].pid) mtf_users += users.get_users_by_id(mtf_list[x].uid) ntf_list = ntf_list + mtf_list ntf_posts = ntf_posts + mtf_posts ntf_users = ntf_users + mtf_users notification_num = notification_num + mention_num #得到资料设置 profile = users.get_profile_by_user_id(user.id) #得到邮箱验证状态 confirm = users.get_confirm_email_by_douban_id(user.douban_id) return view.base(view.member_setting_profile(user, profile, confirm), user, siteName, rights, ntf_list, notification_num, ntf_posts, ntf_users)
def GET(self, img_id): img = image.get_img_by_imgid(img_id) author = web.listget(users.get_users_by_id(img.userID), 0, {}) fav_user = image.GetFavImageByImageId(img_id).list() fav_user_ids = [] for i in xrange(len(fav_user)): fav_user_ids += str(fav_user[i].user_id).split() usernnames = [] for i in xrange(len(fav_user_ids)): usernnames += users.get_users_by_id(fav_user_ids[i]) return view.base(view.photo_fans(img_id, img, usernnames, author), user, siteName)
def GET(self): # u = users.get_user_by_id(session.get_user_id()) # ut = u.nicknameChangeTime #得到上次修改昵称的时间 # c = datetime.datetime.now()#得到当前时间 # if (c - ut).days < 30: #时间差 # can_change_nickname = False # else: # can_change_nickname = True #得到权限 per = users.get_permission_by_douid(user.douban_id) rights = per[0].rights #得到提醒 notification_results, notification_num = notification.get_unread_notification(user.id) #得到@提醒 notification_mention_results, mention_num= notification.get_unread_metion_notifition(user.id) #链表 得到提醒的详细id\名称等 ntf_posts = [] ntf_users = [] mtf_posts = [] mtf_users = [] ntf_list = notification_results.list() mtf_list = notification_mention_results.list() for x in xrange(len(ntf_list)): ntf_posts += postModel.getPostsByPostId(ntf_list[x].pid) ntf_users += users.get_users_by_id(ntf_list[x].uid) for x in xrange(len(mtf_list)): mtf_posts += postModel.getPostsByPostId(mtf_list[x].pid) mtf_users += users.get_users_by_id(mtf_list[x].uid) ntf_list = ntf_list + mtf_list ntf_posts = ntf_posts + mtf_posts ntf_users = ntf_users + mtf_users notification_num = notification_num+mention_num #得到资料设置 profile = users.get_profile_by_user_id(user.id) #得到邮箱验证状态 confirm = users.get_confirm_email_by_douban_id(user.douban_id) return view.base(view.member_setting_profile(user, profile, confirm), user, siteName, rights, ntf_list, notification_num, ntf_posts, ntf_users)
def render_account(show='all', login_form=login_form(), register_form=register_form(), forgot_password_form=forgot_password_form(), reset_password_form=reset_password_form(), token='', on_success_message='', error_message=''): rights = None ntf_list = None notification_num = None ntf_posts = None ntf_users = None return view.base( view.account(show, login_form, register_form, forgot_password_form, reset_password_form, token, on_success_message, error_message), user, site_name, rights, ntf_list, notification_num, ntf_posts, ntf_users)
def GET(self, id): img = image.get_img_by_imgid(id) if img: i = web.input(start=0, order=default_order, desc='desc', query='') start = int(i.start) user_id = session.is_logged() and session.get_user_id() author_id = img.userID results, num_results = image.query(author_id) pager = web.storage( paging.get_paging_results(start, num_results, int(id), results, results_per_page)) #tm = time.strftime('%Y年%m月%d日', time.localtime(img.creationTime)) author = users.get_user_by_id(img.userID) results = list(results) is_favorite = image.IsFavorite(user_id, img.id) #得到被多少人喜欢 #count = image.GetFavUserCount(img_id) #浏览人数加1 if user_id and image.user_not_viewed_image(user_id, id): image.add_img_hit(id) image.add_user_to_img_viewed(user_id, id) #得到评论 comments = image.get_comment_by_image_id(id).list() #得到评论者信息 comments_authors_ids = [] for i in xrange(len(comments)): #comments_authors_ids += str(comments[i].user_id).split() comments_authors_ids += users.get_users_by_id( comments[i].user_id).list() return view.base( view.photo_single(img, pager, user_id, user, author, is_favorite, comments, comments_authors_ids), user, siteName) else: raise web.notfound()
def GET(self, username, p=1): u = users.get_user_by_username(username) if u: page = int(p) perpage = 5 offset = (page - 1) * perpage liked_pids = postModel.getLikedPostsByUserId( u.id, offset, perpage).list() liked_posts = [] for i in xrange(len(liked_pids)): liked_posts += postModel.getPostsByPostId(liked_pids[i].pid) authors = [] for i in xrange(len(liked_posts)): authors += users.get_users_by_id(liked_posts[i].postAuthor) nodes = [] for i in xrange(len(liked_posts)): nodes += nodeModel.getNodesByNodeId(liked_posts[i].nodeId) #得到资料 profile = users.get_profile_by_user_id(u.id) #是否登录, if user.is_logged: per = users.get_permission_by_douid(user.douban_id) rights = per[0].rights #得到提醒 notification_results, notification_num = notification.get_unread_notification( user.id) #得到@提醒 notification_mention_results, mention_num = notification.get_unread_metion_notifition( user.id) #链表 得到提醒的详细id\名称等 ntf_posts = [] ntf_users = [] mtf_posts = [] mtf_users = [] ntf_list = notification_results.list() mtf_list = notification_mention_results.list() for x in xrange(len(ntf_list)): ntf_posts += postModel.getPostsByPostId(ntf_list[x].pid) ntf_users += users.get_users_by_id(ntf_list[x].uid) for x in xrange(len(mtf_list)): mtf_posts += postModel.getPostsByPostId(mtf_list[x].pid) mtf_users += users.get_users_by_id(mtf_list[x].uid) ntf_list = ntf_list + mtf_list ntf_posts = ntf_posts + mtf_posts ntf_users = ntf_users + mtf_users notification_num = notification_num + mention_num else: rights = 0 is_voted = None notification_results = None notification_num = None ntf_list = None ntf_posts = None ntf_users = None return view.base( view.member_favorite(u, profile, liked_posts, nodes, authors, user), user, siteName, rights, ntf_list, notification_num, ntf_posts, ntf_users) else: raise web.notfound()
def GET(self, name): userid = session.get_user_id() user_data = users.get_user_by_id(userid) return view.base(view.index(user_data))
def GET(self, arg, ntf_type=''): #ntf_type为提醒类型,用来让用户从提醒页面访问片段页面时可以看到对应提醒 post = postModel.getPostByPostId(arg) if post: post_author_info = users.get_user_by_id(post.postAuthor) node = nodeModel.getNodeByNodeId(post.nodeId) timestrf = misc.timestrf likers = postModel.get_voters_by_pid(post.id) likers_list = [] for i in xrange(len(likers)): likers_list += users.get_users_by_id(likers[i].uid) comments = postModel.get_comments_by_pid(post.id).list() commenters = [] for i in xrange(len(comments)): commenters += users.get_users_by_id(comments[i].uid) #是否登录, if user.is_logged: per = users.get_permission_by_douid(user.douban_id) rights = per[0].rights #是否投过票 is_voted = postModel.is_voted(arg, user.id) #得到提醒 notification_results, notification_num = notification.get_unread_notification( user.id) #得到@提醒 notification_mention_results, mention_num = notification.get_unread_metion_notifition( user.id) #链表 得到提醒的详细id\名称等 ntf_posts = [] ntf_users = [] mtf_posts = [] mtf_users = [] ntf_list = notification_results.list() mtf_list = notification_mention_results.list() for x in xrange(len(ntf_list)): ntf_posts += postModel.getPostsByPostId(ntf_list[x].pid) ntf_users += users.get_users_by_id(ntf_list[x].uid) for x in xrange(len(mtf_list)): mtf_posts += postModel.getPostsByPostId(mtf_list[x].pid) mtf_users += users.get_users_by_id(mtf_list[x].uid) #获取提醒页面传过来的提醒类型参数 ntf_type = web.input(ntf_type='').ntf_type ntf_list = ntf_list + mtf_list ntf_posts = ntf_posts + mtf_posts ntf_users = ntf_users + mtf_users notification_num = notification_num + mention_num else: rights = 0 is_voted = None notification_results = None notification_num = None ntf_list = None ntf_posts = None ntf_users = None return view.base( view.post_single(rights, node, post, post_author_info, user, timestrf, likers_list, comments, commenters, ntf_type, is_voted, misc), user, siteName, rights, ntf_list, notification_num, ntf_posts, ntf_users) else: raise web.notfound()
def GET(self): # if user.is_logged: rec_posts = admin.get_rec_posts() # if rec_posts: postList = [] for i in xrange(len(rec_posts)): postList += postModel.getPostsByPostId(rec_posts[i].pid) a = [] for post in postList: a += str(post.postAuthor).split() authors = [] for i in xrange(len(a)): authors += users.get_users_by_id(a[i]) n= [] for post in postList: n += str(post.nodeId).split() nodes = [] for i in xrange(len(n)): nodes += nodeModel.getNodesByNodeId(n[i]) if user.is_logged: per = users.get_permission_by_douid(user.douban_id) rights = per[0].rights if users.is_user_exist_in_apply_log(user.douban_id): #如果申请记录表中有此用户记录: apply_log = users.get_log_result(user.douban_id) else: apply_log = {} #得到提醒 notification_results, notification_num = notification.get_unread_notification(user.id) #得到@提醒 notification_mention_results, mention_num= notification.get_unread_metion_notifition(user.id) #链表 得到提醒的详细id\名称等 ntf_posts = [] ntf_users = [] mtf_posts = [] mtf_users = [] ntf_list = notification_results.list() mtf_list = notification_mention_results.list() for x in xrange(len(ntf_list)): ntf_posts += postModel.getPostsByPostId(ntf_list[x].pid) ntf_users += users.get_users_by_id(ntf_list[x].uid) for x in xrange(len(mtf_list)): mtf_posts += postModel.getPostsByPostId(mtf_list[x].pid) mtf_users += users.get_users_by_id(mtf_list[x].uid) ntf_list = ntf_list + mtf_list ntf_posts = ntf_posts + mtf_posts ntf_users = ntf_users + mtf_users notification_num = notification_num+mention_num else: rights = None apply_log = None ntf_list = None notification_num = None ntf_posts = None ntf_users = None return view.base(view.recommend_posts(postList, authors, nodes, user, rights, apply_log), user, siteName, rights, ntf_list, notification_num, ntf_posts, ntf_users)
def GET(self): rec_nodes = admin.get_rec_nodes() nodeList = [] for node in rec_nodes: nodeList.extend(nodeModel.getNodesByNodeId(node.nid)) authors = [] for node in nodeList: authors.extend(users.get_users_by_id(node.node_author)) #得到最新的那个post lastest_posts = [] for node in nodeList: recent_post_in_node = postModel.getRecentOnePostsInNode(node.id) if recent_post_in_node: lastest_posts.extend(recent_post_in_node.creation_ts.timetuple()) #得到当前用户的权限 if user.is_logged: per = users.get_permission_by_douid(user.douban_id) rights = per[0].rights if users.is_user_exist_in_apply_log(user.douban_id): #如果申请记录表中有此用户记录: apply_log = users.get_log_result(user.douban_id) else: apply_log = {} #得到提醒 notification_results, notification_num = notification.get_unread_notification(user.id) #得到@提醒 notification_mention_results, mention_num= notification.get_unread_metion_notifition(user.id) #链表 得到提醒的详细id\名称等 ntf_posts = [] ntf_users = [] mtf_posts = [] mtf_users = [] ntf_list = notification_results.list() mtf_list = notification_mention_results.list() for notify in ntf_list: ntf_posts.extend(postModel.getPostsByPostId(notify.pid)) ntf_users.extend(users.get_users_by_id(notify.uid)) for notify in mtf_list: mtf_posts.extend(postModel.getPostsByPostId(notify.pid)) mtf_users.extend(users.get_users_by_id(notify.uid)) ntf_list = ntf_list + mtf_list ntf_posts = ntf_posts + mtf_posts ntf_users = ntf_users + mtf_users notification_num = notification_num+mention_num else: rights = None notification_results = None notification_num = None ntf_list = None ntf_posts = None ntf_users = None apply_log = {} return view.base(view.recommend_nodes(nodeList, authors, user, rights, apply_log, lastest_posts, datetime), user, siteName, rights, ntf_list, notification_num, ntf_posts, ntf_users)
def GET(self): return view.base(view.help())
def GET(self): # foo = web.cookies(cookieName=defaultValue) # foo.age #if user.is_logged: if True: # 全部开放 rec_posts = admin.get_rec_posts() postList = [] # if len(rec_posts) > 20: # map(lambda x:postList.extend(postModel.getPostsByPostId(x.pid)), rec_posts) # else: # postList = list(postModel.getRecent20Posts()) map(lambda x:postList.extend(postModel.getPostsByPostId(x.pid)), rec_posts) #postList = sort_dict_by_multi_key(postList, ['magnitude', 'creation_ts'], reverse=True) #postList = sorted(postList, key=lambda x:x.creation_ts, reverse=True) authors = [] map(lambda x:authors.extend(users.get_users_by_id(x)), [x.postAuthor for x in postList]) nodes = [] map(lambda x:nodes.extend(nodeModel.getNodesByNodeId(x)), [x.nodeId for x in postList]) if user.is_logged: rights = users.get_permission_by_douid(user.douban_id)[0].rights if users.is_user_exist_in_apply_log(user.douban_id): #如果申请记录表中有此用户记录: apply_log = users.get_log_result(user.douban_id) else: apply_log = {} #得到提醒 notification_results, notification_num = notification.get_unread_notification(user.id) #得到@提醒 notification_mention_results, mention_num= notification.get_unread_metion_notifition(user.id) #链表 得到提醒的详细id\名称等 ntf_posts = [] ntf_users = [] mtf_posts = [] mtf_users = [] ntf_list = notification_results.list() mtf_list = notification_mention_results.list() for notify in ntf_list: ntf_posts.extend(postModel.getPostsByPostId(notify.pid)) ntf_users.extend(users.get_users_by_id(notify.uid)) for notify in mtf_list: mtf_posts.extend(postModel.getPostsByPostId(notify.pid)) mtf_users.extend(users.get_users_by_id(notify.uid)) ntf_list = ntf_list + mtf_list ntf_posts = ntf_posts + mtf_posts ntf_users = ntf_users + mtf_users notification_num = notification_num+mention_num else: rights = None apply_log = None ntf_list = None notification_num = None ntf_posts = None ntf_users = None return view.base(view.recommend_posts(postList, authors, nodes, user, rights, apply_log, filter_tags), user, siteName, rights, ntf_list, notification_num, ntf_posts, ntf_users) else: from config import db #得到上线时间距今多少天 t = time.strptime('2013-03-15 02:15:57', "%Y-%m-%d %X") ts = datetime.datetime(* t[:6]) delta = (datetime.datetime.now() - ts).days #得到用户数 user_count = int(db.select('users', what='count(distinct id) as c')[0].c) #得到话题数 node_count = int(db.select('_node', what='count(distinct id) as c')[0].c) #得到片段数 post_count = int(db.select('_post', what='count(distinct id) as c')[0].c) #得到喜欢数 vote_count = int(db.select('_post_vote_user', what='count(distinct id) as c')[0].c) #得到评论数 comm_count = int(db.select('_post_comments', what='count(distinct id) as c')[0].c) r = str(random.randint(1, 17)) return view.base01(view.landing(r, delta, user_count, node_count, post_count, vote_count, comm_count), siteName)
def GET(self): rights = users.get_permission_by_douid(user.douban_id)[0].rights postList = postModel.getRecent20Posts() return view.base(view.post_latest(postList), user, siteName, rights, ntf_list=None, notification_num=None, ntf_posts=None, ntf_users=None)
def GET(self, username, p=1): u = users.get_user_by_username(username) if u: page = int(p) perpage = 5 offset = (page - 1) * perpage created_posts = postModel.getCreatedPostsByUserId(u.id, offset, perpage).list() nodes = [] for i in xrange(len(created_posts)): nodes += nodeModel.getNodesByNodeId(created_posts[i].nodeId) #得到资料 profile = users.get_profile_by_user_id(u.id) #note 跳转到豆瓣 # raise web.seeother('http://www.douban.com/people/'+ username) # pf = users.get_profile_by_user_id(u.id) # #得到上传的图片数 # results,num_results = image.query(u.id) # #得到喜欢的图片数 # fav_count = image.GetUserFavCount(u.id) # #得到用户上传的图片路径 # imagePath = image.get_paths_by_id(u.id).list() # paths = [] # for p in imagePath: # paths += p.path.split() # #得到图片id # imageIDs = image.get_imageID_by_id(u.id).list() # img_ids = [] # for i in imageIDs: # img_ids += str(i.id).split() # return view.base(view.member_home(u, pf, paths, img_ids, num_results, fav_count), user, siteName) #是否登录, if user.is_logged: per = users.get_permission_by_douid(user.douban_id) rights = per[0].rights #得到提醒 notification_results, notification_num = notification.get_unread_notification(user.id) #得到@提醒 notification_mention_results, mention_num= notification.get_unread_metion_notifition(user.id) #链表 得到提醒的详细id\名称等 ntf_posts = [] ntf_users = [] mtf_posts = [] mtf_users = [] ntf_list = notification_results.list() mtf_list = notification_mention_results.list() for x in xrange(len(ntf_list)): ntf_posts += postModel.getPostsByPostId(ntf_list[x].pid) ntf_users += users.get_users_by_id(ntf_list[x].uid) for x in xrange(len(mtf_list)): mtf_posts += postModel.getPostsByPostId(mtf_list[x].pid) mtf_users += users.get_users_by_id(mtf_list[x].uid) ntf_list = ntf_list + mtf_list ntf_posts = ntf_posts + mtf_posts ntf_users = ntf_users + mtf_users notification_num = notification_num+mention_num else: rights = 0 is_voted = None notification_results = None notification_num = None ntf_list = None ntf_posts = None ntf_users = None return view.base(view.member_home(u, profile, created_posts, nodes, user, replace_breaks), user, siteName, rights, ntf_list, notification_num, ntf_posts, ntf_users) else: raise web.notfound()
def POST(self): cgi.maxlen = 2 * 1024 * 1024 # 限制2MB try: x = web.input(uploadImg={}) homedir = os.getcwd() filedir = '%s/static/upload/image' % homedir #图片存放路径 if 'uploadImg' in x: # to check if the file-object is created filepath = x.uploadImg.filename.replace( '\\', '/') # replaces the windows-style slashes with linux ones. filename = filepath.split( '/' )[-1] # splits the and chooses the last part (the filename with extension) #获取文件名 ext = filename.split('.', -1)[-1] #获取后缀 if ext == 'jpg' or ext == 'gif' or ext == 'jpeg' or ext == 'png' or ext == 'JPG': now = datetime.datetime.now() d_path = filedir + '/%d/%d/%d' % (now.year, now.month, now.day) if not os.path.exists(d_path): os.makedirs(d_path) #创建当前日期目录 t = '%d%d%d%d%d%d' % (now.year, now.month, now.day, now.hour, now.minute, now.second) all = list( '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSQUVWXYZ' ) randStr = '' for i in range(10): index = random.randint(0, len(all) - 1) randStr = randStr + all[index] #生成10位随机数 authKey = hashlib.md5(randStr + user.username).hexdigest() filename = t + '_' + authKey + '.' + ext #以时间+authKey作为文件名 fout = open( d_path + '/' + filename, 'wb' ) # creates the file where the uploaded file should be stored fout.write(x.uploadImg.file.read( )) # writes the uploaded file to the newly created file. fout.close() # closes the file, upload complete. im = Image.open(d_path + '/' + filename) width, height = im.size #判断比例 if width / height > 5 or height / width > 5: os.remove(d_path + '/' + filename) #删除图片 #session.reset() return view.base( view.member_setting_avatar( user, mid_src='', message='图片的比例有些不太合适,请选择一张更容易辨识的图片吧'), user, siteName) else: path = d_path + '/' + filename #for thumb utils.make_thumb(path) #创建缩略图 #big_src = '/static/upload/image/%d/%d/%d/' %(now.year, now.month, now.day) + filename mid_src = '/static/upload/image/%d/%d/%d/' % ( now.year, now.month, now.day) + t + '_' + authKey + '_160.jpg' #sml_src = '/static/upload/image/%d/%d/%d/' %(now.year, now.month, now.day) + t + '_' + authKey + '_48x48.jpg' user_id = user.id avatar = '/%d/%d/%d/' % (now.year, now.month, now.day) + t + '_' + authKey users.save_user_avatar(user_id, avatar) #入库 #session.reset() rights = None ntf_list = None notification_num = None ntf_posts = None ntf_users = None return view.base( view.member_setting_avatar(user, mid_src), user, siteName, rights, ntf_list, notification_num, ntf_posts, ntf_users) else: #session.reset() return view.base( view.member_setting_avatar( user, mid_src='', message='上传格式仅支持jpg/png/gif/jpeg'), user, siteName) except ValueError: #session.reset() rights = None ntf_list = None notification_num = None ntf_posts = None ntf_users = None return view.base( view.member_setting_avatar(user, mid_src='', message='文件太大了,我吃不消哇~'), user, siteName, rights, ntf_list, notification_num, ntf_posts, ntf_users)
def GET(self): # if user.is_logged: rec_posts = admin.get_rec_posts() # if rec_posts: postList = [] for i in xrange(len(rec_posts)): postList += postModel.getPostsByPostId(rec_posts[i].pid) a = [] for post in postList: a += str(post.postAuthor).split() authors = [] for i in xrange(len(a)): authors += users.get_users_by_id(a[i]) n = [] for post in postList: n += str(post.nodeId).split() nodes = [] for i in xrange(len(n)): nodes += nodeModel.getNodesByNodeId(n[i]) if user.is_logged: per = users.get_permission_by_douid(user.douban_id) rights = per[0].rights if users.is_user_exist_in_apply_log( user.douban_id): #如果申请记录表中有此用户记录: apply_log = users.get_log_result(user.douban_id) else: apply_log = {} #得到提醒 notification_results, notification_num = notification.get_unread_notification( user.id) #得到@提醒 notification_mention_results, mention_num = notification.get_unread_metion_notifition( user.id) #链表 得到提醒的详细id\名称等 ntf_posts = [] ntf_users = [] mtf_posts = [] mtf_users = [] ntf_list = notification_results.list() mtf_list = notification_mention_results.list() for x in xrange(len(ntf_list)): ntf_posts += postModel.getPostsByPostId(ntf_list[x].pid) ntf_users += users.get_users_by_id(ntf_list[x].uid) for x in xrange(len(mtf_list)): mtf_posts += postModel.getPostsByPostId(mtf_list[x].pid) mtf_users += users.get_users_by_id(mtf_list[x].uid) ntf_list = ntf_list + mtf_list ntf_posts = ntf_posts + mtf_posts ntf_users = ntf_users + mtf_users notification_num = notification_num + mention_num else: rights = None apply_log = None ntf_list = None notification_num = None ntf_posts = None ntf_users = None return view.base( view.recommend_posts(postList, authors, nodes, user, rights, apply_log), user, siteName, rights, ntf_list, notification_num, ntf_posts, ntf_users)
def GET(self): rec_nodes = admin.get_rec_nodes() nodeList = [] for i in xrange(len(rec_nodes)): nodeList += nodeModel.getNodesByNodeId(rec_nodes[i].nid) a = [] for node in nodeList: a += str(node.node_author).split() authors = [] for i in xrange(len(a)): authors += users.get_users_by_id(a[i]) #得到最新的那个post lastest_posts = [] for i in xrange(len(nodeList)): #如果没有,去取node的创建时间 if postModel.getRecentOnePostsInNode(nodeList[i].id): lastest_posts += str( time.mktime( postModel.getRecentOnePostsInNode( nodeList[i].id).creation_ts.timetuple())).split() else: lastest_posts += str( time.mktime( nodeModel.getNodeByNodeId( nodeList[i].id).creation_ts.timetuple())).split() #得到当前用户的权限 if user.is_logged: per = users.get_permission_by_douid(user.douban_id) rights = per[0].rights if users.is_user_exist_in_apply_log( user.douban_id): #如果申请记录表中有此用户记录: apply_log = users.get_log_result(user.douban_id) else: apply_log = {} #得到提醒 notification_results, notification_num = notification.get_unread_notification( user.id) #得到@提醒 notification_mention_results, mention_num = notification.get_unread_metion_notifition( user.id) #链表 得到提醒的详细id\名称等 ntf_posts = [] ntf_users = [] mtf_posts = [] mtf_users = [] ntf_list = notification_results.list() mtf_list = notification_mention_results.list() for x in xrange(len(ntf_list)): ntf_posts += postModel.getPostsByPostId(ntf_list[x].pid) ntf_users += users.get_users_by_id(ntf_list[x].uid) for x in xrange(len(mtf_list)): mtf_posts += postModel.getPostsByPostId(mtf_list[x].pid) mtf_users += users.get_users_by_id(mtf_list[x].uid) ntf_list = ntf_list + mtf_list ntf_posts = ntf_posts + mtf_posts ntf_users = ntf_users + mtf_users notification_num = notification_num + mention_num else: rights = None notification_results = None notification_num = None ntf_list = None ntf_posts = None ntf_users = None apply_log = {} return view.base( view.recommend_nodes(nodeList, authors, user, rights, apply_log, lastest_posts, datetime), user, siteName, rights, ntf_list, notification_num, ntf_posts, ntf_users)
def GET(self): userid = session.get_user_id() user_data = users.get_user_by_id(userid) # print user_data return view.base(view.index(user_data))
def GET(self, arg, ntf_type=''): #ntf_type为提醒类型,用来让用户从提醒页面访问片段页面时可以看到对应提醒 post = postModel.getPostByPostId(arg) if post: post_author_info = users.get_user_by_id(post.postAuthor) node = nodeModel.getNodeByNodeId(post.nodeId) timestrf = misc.timestrf likers = postModel.get_voters_by_pid(post.id) likers_list = [] for i in xrange(len(likers)): likers_list += users.get_users_by_id(likers[i].uid) comments = postModel.get_comments_by_pid(post.id).list() commenters = [] for i in xrange(len(comments)): commenters += users.get_users_by_id(comments[i].uid) #是否登录, if user.is_logged: per = users.get_permission_by_douid(user.douban_id) rights = per[0].rights #是否投过票 is_voted = postModel.is_voted(arg, user.id) #得到提醒 notification_results, notification_num = notification.get_unread_notification(user.id) #得到@提醒 notification_mention_results, mention_num= notification.get_unread_metion_notifition(user.id) #链表 得到提醒的详细id\名称等 ntf_posts = [] ntf_users = [] mtf_posts = [] mtf_users = [] ntf_list = notification_results.list() mtf_list = notification_mention_results.list() for x in xrange(len(ntf_list)): ntf_posts += postModel.getPostsByPostId(ntf_list[x].pid) ntf_users += users.get_users_by_id(ntf_list[x].uid) for x in xrange(len(mtf_list)): mtf_posts += postModel.getPostsByPostId(mtf_list[x].pid) mtf_users += users.get_users_by_id(mtf_list[x].uid) #获取提醒页面传过来的提醒类型参数 ntf_type = web.input(ntf_type='').ntf_type ntf_list = ntf_list + mtf_list ntf_posts = ntf_posts + mtf_posts ntf_users = ntf_users + mtf_users notification_num = notification_num+mention_num else: rights = 0 is_voted = None notification_results = None notification_num = None ntf_list = None ntf_posts = None ntf_users = None return view.base(view.post_single(rights, node, post, post_author_info, user, timestrf, likers_list, comments, commenters, ntf_type, is_voted, misc), user, siteName, rights, ntf_list, notification_num, ntf_posts, ntf_users) else: raise web.notfound()
def GET(self): return view.base(view.index(view.sendmail_form(sendmail_form())))
def GET(self): rec_nodes = admin.get_rec_nodes() nodeList = [] for i in xrange(len(rec_nodes)): nodeList += nodeModel.getNodesByNodeId(rec_nodes[i].nid) a = [] for node in nodeList: a += str(node.node_author).split() authors = [] for i in xrange(len(a)): authors += users.get_users_by_id(a[i]) #得到最新的那个post lastest_posts = [] for i in xrange(len(nodeList)): #如果没有,去取node的创建时间 if postModel.getRecentOnePostsInNode(nodeList[i].id): lastest_posts += str(time.mktime(postModel.getRecentOnePostsInNode(nodeList[i].id).creation_ts.timetuple())).split() else: lastest_posts += str(time.mktime(nodeModel.getNodeByNodeId(nodeList[i].id).creation_ts.timetuple())).split() #得到当前用户的权限 if user.is_logged: per = users.get_permission_by_douid(user.douban_id) rights = per[0].rights if users.is_user_exist_in_apply_log(user.douban_id): #如果申请记录表中有此用户记录: apply_log = users.get_log_result(user.douban_id) else: apply_log = {} #得到提醒 notification_results, notification_num = notification.get_unread_notification(user.id) #得到@提醒 notification_mention_results, mention_num= notification.get_unread_metion_notifition(user.id) #链表 得到提醒的详细id\名称等 ntf_posts = [] ntf_users = [] mtf_posts = [] mtf_users = [] ntf_list = notification_results.list() mtf_list = notification_mention_results.list() for x in xrange(len(ntf_list)): ntf_posts += postModel.getPostsByPostId(ntf_list[x].pid) ntf_users += users.get_users_by_id(ntf_list[x].uid) for x in xrange(len(mtf_list)): mtf_posts += postModel.getPostsByPostId(mtf_list[x].pid) mtf_users += users.get_users_by_id(mtf_list[x].uid) ntf_list = ntf_list + mtf_list ntf_posts = ntf_posts + mtf_posts ntf_users = ntf_users + mtf_users notification_num = notification_num+mention_num else: rights = None notification_results = None notification_num = None ntf_list = None ntf_posts = None ntf_users = None apply_log = {} return view.base(view.recommend_nodes(nodeList, authors, user, rights, apply_log, lastest_posts, datetime), user, siteName, rights, ntf_list, notification_num, ntf_posts, ntf_users)