def user_setting_handler(request): user_account = request.META["user_info"] user_info = UserInfo.query_format_info_by_user_id(user_account.id) if request.method == "GET": data = dict() user_info["email"] = UserAccount.query_user_by_id(user_account.id).email data["user_info"] = user_info return render(request, "about/setting.html", data) # 获取头像 avatar = UploadImage(request) image_list = avatar.save() nick_name = request.POST.get("nick_name") gender = request.POST.get("gender") user = UserInfo.objects.get(user_id=user_account.id) user.gender = gender if nick_name != user_info["nick_name"]: user.nick_name = nick_name if len(image_list) > 0: user.avatar = image_list[0].id user.save() # 刷新缓存 UserInfo.query_format_info_by_user_id(user_account.id, False) return HttpResponseRedirect("/user/info/" + str(user_account.id))
def refresh_cache(user_id, login_user): UserFollow.query_user_meta_count(user_id, is_follow=False, use_cache=False) UserFollow.query_user_meta_count(login_user, is_follow=True, use_cache=False) UserInfo.query_format_info_by_user_id(user_id, use_cache=False) UserInfo.query_format_info_by_user_id(login_user, use_cache=False)
def format_comment_item(comment, visitor_id=0, need_reply=True): result = dict() result["id"] = comment.id result["user_info"] = UserInfo.query_format_info_by_user_id( comment.user_id) result["meta_info"] = CommentMeta.get_format_meta( comment.id, visitor_id=visitor_id) result["content"] = comment.content # 该条评论的回复列表 if need_reply: result["reply_list"] = BlogComment.query_comment_reply_list( comment.id, visitor_id=visitor_id) else: result["reply_list"] = None # 该条评论的回复信息 result[ "reply_info"] = None if comment.reply_id == 0 else BlogComment.query_comment_by_id( comment.reply_id, visitor_id, False) result["created_time"] = str( comment.created_time.strftime("%Y %b %d %H:%M")) return result
def active_account_handler(request): token = request.GET.get("access_token") pass_port = request.GET.get("pass_port") try: access_token = AccessToken.objects.get(access_token=token) if not verify_password(access_token.access_token + access_token.salt, pass_port): return json_fail_response("无效的用户请求") if access_token.status == 0: return json_fail_response("token失效") except AccessToken.DoesNotExist: return json_fail_response("请求无效!") try: account = UserAccount.objects.get(id=access_token.user_id) if account.status == 1: return json_fail_response("当前用户已经激活") except UserAccount.DoesNotExist: return json_fail_response("激活用户不存在") account.status = 1 account.save() # 注册环信 user_info = UserInfo.query_format_info_by_user_id(account.id, use_cache=False) register_ease_mob(user_info['ease_mob']) return redirect("/auth/login")
def home_recommend_handler(request): operator = request.META["user_info"] if request.method == "GET": result = dict() article_id = request.GET.get("article_id") result["data"] = BlogArticle.query_article_by_id(article_id) result["operator"] = operator result["user_info"] = UserInfo.query_format_info_by_user_id(operator.id) return render(request, "manage/recommend.html", result) image_list = UploadImage(request).save() article_id = request.POST.get("article_id") introl = request.POST.get("intro") weight = request.POST.get("weight") # TODO:参数检测 recommend = HomeRecommend() recommend.share_id = article_id recommend.reco_cover = image_list[0].id recommend.reco_intro = introl recommend.weight = weight recommend.operator_id = operator.id recommend.status = 1 recommend.save() return HttpResponseRedirect("/manage")
def follower_list_handler(request, user_id): """获取某一个人的粉丝列表""" login_user = request.META["user_info"] result = dict() result["user_info"] = UserInfo.query_format_info_by_user_id( login_user.id) if login_user else None result["author"] = UserInfo.query_format_info_by_user_id(user_id) # 查询双方的关系 if login_user: result["author"]["relation"] = UserFollow.query_user_relation( login_user.id, user_id) else: result["author"]["relation"] = 0 follower_list = UserFollow.query_user_relation_list(user_id, is_follow=False) result["follower_list"] = format_relation_users( follower_list, False, 0 if not login_user else login_user.id) return render(request, "relation/follower/follower.html", result)
def format_relation_users(user_list, is_follow, login_user): """格式化一个用户的关注或者粉丝列表""" result = list() for user in user_list: user_id = user.follow_user if is_follow else user.user_id user_info = UserInfo.query_format_info_by_user_id(user_id) if login_user: user_info["relation"] = UserFollow.query_user_relation( login_user, user_id) else: user_info["relation"] = 0 result.append(user_info) return result
def user_info_handler(request, user_id): user = request.META["user_info"] result = dict() result["user_info"] = UserInfo.query_format_info_by_user_id( user.id) if user else None result[ "author"] = None if user_id == 0 else UserInfo.query_format_info_by_user_id( user_id) result["article_list"] = BlogArticle.query_articles_by_user(user_id) # 查询双方的关系 if user_id != 0 and user: result["author"]["relation"] = UserFollow.query_user_relation( user.id, user_id) else: result["author"]["relation"] = 0 for article in result["article_list"]: if len(article["content"]) > 200: article["content"] = article["content"][:200] return render(request, "about/user.html", result)
def index_handler(request): data = dict() data["section_info"] = "1" account = request.META["user_info"] if account: account = UserInfo.query_format_info_by_user_id(account.id) data["user_info"] = account data["recommend_list"] = HomeRecommend.query_recommend_list(0) # 阅读榜单 data["hit_list"] = get_format_top_article_list(order="hit") # 点赞榜单 data["like_list"] = get_format_top_article_list(order="like") # 评论榜单 data["comment_list"] = get_format_top_article_list(order="comment") return render(request, "index/index.html", data)
def edit_article_handler(request, article_id): """ 编辑文章 处理模块 """ result = base_result() user_id = request.META["user_info"].id if article_id != "0": result["data"] = BlogArticle.query_article_by_id(article_id) renderer = mistune.Renderer(hard_wrap=True, parse_inline_html=True) markdown = mistune.Markdown(renderer=renderer) result["mark_down"] = markdown(result["data"]["content"]) else: result["mark_down"] = None del result["data"] result["kind_list"] = BlogKind.query_user_kind(1) result["user_info"] = UserInfo.query_format_info_by_user_id(user_id) return render(request, "manage/edit.html", result)
def user_info_api_handler(request): user_id = request.GET.get("user_id") user_info = UserInfo.query_format_info_by_user_id(user_id) return HttpResponse(json.dumps({"user_info": user_info}))
def format_user(user): result = UserInfo.query_format_info_by_user_id(user.id) return result