Пример #1
0
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)
Пример #2
0
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))
Пример #3
0
def register_new_account(nick_name, email, password):

    with transaction.atomic():
        # 用户账户注册
        account = UserAccount()

        account.user_name = email
        account.email = email
        account.password = get_secret_password(password)
        account.type = 0
        account.banned = 1
        # 未激活
        account.status = 0
        account.save()

        user_info = UserInfo()
        user_info.user_id = account.id
        # 生成环信账号
        user_info.ease_mob = generate_ease_mob_id(account.id)
        user_info.nick_name = nick_name
        user_info.gender = 0
        user_info.avatar = 0
        user_info.status = 1
        user_info.save()

        token = AccessToken.create_new_toke(user_info.user_id)

    result = {"account": account, "user_info": user_info, "token": token}

    return result
Пример #4
0
    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
Пример #5
0
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")
Пример #6
0
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")
Пример #7
0
def user_search_api(request):

    nick_name = request.GET.get("nick_name")
    if not nick_name:
        return json_fail_response("搜索内容不能为空")

    user_list = UserInfo.query_user_by_nick_name(nick_name)
    return json_success_response(user_list)
Пример #8
0
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)
Пример #9
0
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
Пример #10
0
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)
Пример #11
0
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)
Пример #12
0
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)
Пример #13
0
def user_info_api_by_ease_mob_handler(request):
    ease_mob = request.GET.get("ease_mob")
    user_info = UserInfo.query_format_info_by_ease_mob(ease_mob)
    return HttpResponse(json.dumps({"user_info": user_info}))
Пример #14
0
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}))
Пример #15
0
 def format_user(user):
     result = UserInfo.query_format_info_by_user_id(user.id)
     return result