示例#1
0
def comment_post(request):
    comment_time = time.strftime('%Y-%m-%d %H:%M:%S',
                                 time.localtime(time.time()))
    try:
        filename = request.POST['filename'].encode('utf-8')
    except:
        HttpResponse('error')
    try:
        username = request.session['username']
        content = request.POST['content'].encode('utf-8')
        if len(content) < 2:
            return render(request, '404.html')
        comment = Comments()
        comment.filename = filename
        comment.name = username
        comment.content = content
        comment.isRegisted = 1
        comment.time = comment_time
        comment.save()
        file
    except:
        try:
            username = request.POST['username'].encode('utf-8')
            email = request.POST['email'].encode('utf-8')
            content = request.POST['content'].encode('utf-8')
            print len(username)
            if len(username) < 2 or len(email) < 2 or len(content) < 2:
                return render(request, '404.html')
            username += '(游客)'
            comment = Comments()
            comment.filename = filename
            comment.name = username
            comment.content = content
            comment.email = email
            comment.isRegisted = 0
            comment.time = comment_time
            comment.save()

        except:
            return render(request, '404.html')
    return HttpResponseRedirect('/detail?file=%s' % (filename))
示例#2
0
def add_comment(request):
    subject_type = request.POST['subject_type']

    new_record = Comments()
    new_record.author = request.user
    new_record.subject_id = request.POST['id']
    new_record.subject_type = subject_type
    new_record.content = request.POST['content']
    new_record.full_clean()
    new_record.save()
    if subject_type == 'Article':
        prefix = 'article'
    else:
        prefix = 'event'
    return redirect('/{}/{}'.format(prefix, request.POST['id']))
示例#3
0
def article(request, book_id):
    """评论页面"""
    if request.method == 'GET':
        print(book_id)
        book = Books.objects.get_books_by_id(book_id)
        return render(request, 'books/article.html', {'book': book})
    elif request.method == 'POST':
        if request.session.has_key('islogin'):
            if book_id:
                content = request.POST.get('comment', '')
                title = request.POST.get('title', '')

                comment = Comments()
                comment.user_id = request.session.get('passport_id')
                comment.book_id = int(book_id)
                comment.content = content
                comment.title = title
                comment.save()

                context = {'comment': comment, 'book_id': book_id}
                return redirect(reverse('books:article', book_id, context))
        else:
            return render(request, 'books/index.html')