コード例 #1
0
ファイル: views.py プロジェクト: virusdefender/MyForum
def user_profile(request):
    username = request.GET.get("username", request.user.username)
    if not user_exist(username):
        raise Http404
        #post = Post.objects.filter(author=request.user.username)
    new_message = Message.objects.filter(to_user=request.user.username, status=False).exists()
    return render(request, "Account/user_profile.html", {"new_message": new_message})
コード例 #2
0
ファイル: views.py プロジェクト: SkyBulk/MyForum
def user_profile(request):
    username = request.GET.get("username", request.user.username)
    if not user_exist(username):
        raise Http404
        #post = Post.objects.filter(author=request.user.username)
    new_message = Message.objects.filter(to_user=request.user.username,
                                         status=False).exists()
    return render(request, "Account/user_profile.html",
                  {"new_message": new_message})
コード例 #3
0
ファイル: views.py プロジェクト: virusdefender/MyForum
def all_post(request, username, page_num=1):
    if not user_exist(username):
        raise Http404
    posts = Post.objects.filter(author=username).order_by("-create_time")
    page_info = Paginator(posts, 10)
    total_page = page_info.num_pages
    if int(page_num) > total_page:
        raise Http404
    return render(request, "Account/user_all_post.html", {"posts": page_info.page(page_num),
                                                          "page_num": unicode(page_num),
                                                          "total_page": unicode(total_page),
                                                          "pre_page": unicode(int(page_num) - 1),
                                                          "next_page": unicode(int(page_num) + 1),
                                                          "username": username})
コード例 #4
0
ファイル: views.py プロジェクト: SkyBulk/MyForum
def all_post(request, username, page_num=1):
    if not user_exist(username):
        raise Http404
    posts = Post.objects.filter(author=username).order_by("-create_time")
    page_info = Paginator(posts, 10)
    total_page = page_info.num_pages
    if int(page_num) > total_page:
        raise Http404
    return render(
        request, "Account/user_all_post.html", {
            "posts": page_info.page(page_num),
            "page_num": unicode(page_num),
            "total_page": unicode(total_page),
            "pre_page": unicode(int(page_num) - 1),
            "next_page": unicode(int(page_num) + 1),
            "username": username
        })
コード例 #5
0
ファイル: views.py プロジェクト: virusdefender/MyForum
def send_message(request):
    if not request.user.is_authenticated():
        return HttpResponseRedirect("/account/login/?next=" + request.META.get('HTTP_REFERER', "/"))
    if request.method == "POST":
        form = MessageForm(request.POST)
        if form.is_valid():
            to_user = form.cleaned_data["to_user"]
            subject = form.cleaned_data["subject"]
            content = form.cleaned_data["content"]
            if not user_exist(to_user):
                response_json = {"status": "error", "content": "收件人账号不存在"}
                return HttpResponse(json.dumps(response_json))
            Message.objects.create(to_user=to_user, from_user=request.user.username, subject=subject, content=content)
            response_json = {"status": "success", "redirect": "/message/"}
            return HttpResponse(json.dumps(response_json))
        else:
            response_json = {"status": "error", "content": "表单数据错误"}
            return HttpResponse(json.dumps(response_json))
    else:
        raise Http404