Beispiel #1
0
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})
Beispiel #2
0
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})
Beispiel #3
0
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})
Beispiel #4
0
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
        })
Beispiel #5
0
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