Exemplo n.º 1
0
def page_comment_edit(request, c_id):
    if request.method == "GET":
        comment = PageComment.objects.get(id=c_id)

        if request.user != comment.user and not request.user.is_staff:
            comment.page.id
            request.session["error_message"] = u"댓글을 수정할 수 있는 권한이 없습니다"
            return redirect('/%s' % comment.page.id)

        c = {"comment": comment}
        update_context(request, c)
        return my_render(request, 'book/include/page_comment_edit.html', c)

    elif request.method == "POST":

        comment = PageComment.objects.get(id=c_id)
        content = unicode.strip(request.POST.get("content", ""))
        comment.content = content
        comment.save()

        cache_remove("book_%s" % comment.page.book.id)
        cache_remove(comment.page.id)

        request.session["ok_message"] = u"댓글이 수정되었습니다"
        return redirect('/%s#comment_%s' % (comment.page.id, c_id))
Exemplo n.º 2
0
def page_comment_edit(request, c_id):
    if request.method == "GET":
        comment = PageComment.objects.get(id=c_id)

        if request.user != comment.user and not request.user.is_staff:
            comment.page.id
            request.session["error_message"] = u"댓글을 수정할 수 있는 권한이 없습니다"
            return redirect('/%s' % comment.page.id)

        c = {"comment": comment}
        update_context(request, c)
        return my_render(request, 'book/include/page_comment_edit.html', c)

    elif request.method == "POST":

        comment = PageComment.objects.get(id=c_id)
        content = unicode.strip(request.POST.get("content", ""))
        comment.content = content
        comment.save()

        cache_remove("book_%s" % comment.page.book.id)
        cache_remove(comment.page.id)

        request.session["ok_message"] = u"댓글이 수정되었습니다"
        return redirect('/%s#comment_%s' % (comment.page.id, c_id))
Exemplo n.º 3
0
def book_recommend(request, _id):
    book = Book.objects.get(id=_id)
    ip = get_ip(request)
    if ip not in book.recommend.all():
        book.recommend.add(ip)
        cache_remove("book_%s" % book.id)
    return redirect("/book/%s" % book.id)
Exemplo n.º 4
0
def book_recommend(request, _id):
    book = Book.objects.get(id=_id)
    ip = get_ip(request)
    if ip not in book.recommend.all():
        book.recommend.add(ip)
        cache_remove("book_%s" % book.id)
    return redirect("/book/%s" % book.id)
Exemplo n.º 5
0
def remove_comment(request):
    comment_id = request.POST.get("comment_id")
    comment = PageComment.objects.get(id=comment_id)
    page = comment.page
    if request.user == comment.user:
        comment.delete()
        cache_remove("book_%s" % page.book.id)
        cache_remove(page.id)
    return redirect('book.profile_views.comment')
Exemplo n.º 6
0
def remove_comment(request):
    comment_id = request.POST.get("comment_id")
    comment = PageComment.objects.get(id=comment_id)
    page = comment.page
    if request.user == comment.user:
        comment.delete()
        cache_remove("book_%s" % page.book.id)
        cache_remove(page.id)
    return redirect('book.profile_views.comment')
Exemplo n.º 7
0
def page_comment_remove(request):
    comment_id = request.POST.get("comment_id")
    comment = PageComment.objects.get(id=comment_id)
    page = comment.page
    if request.user == comment.user:
        comment.delete()
        cache_remove("book_%s" % page.book.id)
        cache_remove(page.id)

    result = render(request, 'book/include/page_comment.html', {"page": page})
    return HttpResponse(result.content)
Exemplo n.º 8
0
def page_comment_remove(request):
    comment_id = request.POST.get("comment_id")
    comment = PageComment.objects.get(id=comment_id)
    page = comment.page
    if request.user == comment.user or request.user.is_superuser:
        comment.delete()
        cache_remove("book_%s" % page.book.id)
        cache_remove(page.id)

    result = render(request, 'book/include/page_comment.html', {"page": page})
    return HttpResponse(result.content)
Exemplo n.º 9
0
def page_comment_save(request):
    page_id = request.POST.get("page_id")
    content = request.POST.get("content")

    page = Page.objects.get(id=page_id)
    pc = PageComment(user=request.user, page=page, content=content)
    pc.save()

    cache_remove("book_%s" % page.book.id)
    cache_remove(page.id)

    body = u"""%(user)s 님의 댓글 (작성일시: %(create_time)s)
-----------------------------------------------------------------------------

%(content)s

-----------------------------------------------------------------------------
%(subject)s URL : http://wikidocs.net/%(page_id)s
    """ % {
        "user": request.user.first_name,
        "create_time": pc.create_time.strftime(u"%Y-%m-%d %X"),
        "content": content,
        "page_id": page.id,
        "subject": page.subject
    }

    emails = []
    for user in page.book.user.all():
        if user != request.user:
            emails.append(user.email)

    # 댓글에 이름 언급 시 이메일 송신
    for pc in PageComment.objects.filter(page=page):
        if pc.user and content.find(pc.user.first_name) != -1 \
                and pc.user != request.user and pc.user.email not in emails:
            emails.append(pc.user.email)

    send_mail(u"%s 페이지에 댓글이 작성되었습니다." % (page.subject),
              body,
              settings.DEFAULT_FROM_EMAIL,
              emails)

    result = render(request, 'book/include/page_comment.html', {"page": page})
    return HttpResponse(result.content)
Exemplo n.º 10
0
def page_comment_save(request):
    page_id = request.POST.get("page_id")
    content = request.POST.get("content")

    page = Page.objects.get(id=page_id)
    pc = PageComment(user=request.user, page=page, content=content)
    pc.save()

    cache_remove("book_%s" % page.book.id)
    cache_remove(page.id)

    body = u"""%(user)s 님의 댓글 (작성일시: %(create_time)s)
-----------------------------------------------------------------------------

%(content)s

-----------------------------------------------------------------------------
%(subject)s URL : http://wikidocs.net/%(page_id)s
    """ % {
        "user": request.user.first_name,
        "create_time": pc.create_time.strftime(u"%Y-%m-%d %X"),
        "content": content,
        "page_id": page.id,
        "subject": page.subject
    }

    emails = []
    for user in page.book.user.all():
        if user != request.user:
            emails.append(user.email)

    # 댓글에 이름 언급 시 이메일 송신
    for pc in PageComment.objects.filter(page=page):
        if pc.user and content.find(pc.user.first_name) != -1 \
                and pc.user != request.user and pc.user.email not in emails:
            emails.append(pc.user.email)

    send_mail(u"%s 페이지에 댓글이 작성되었습니다." % (page.subject), body,
              settings.DEFAULT_FROM_EMAIL, emails)

    result = render(request, 'book/include/page_comment.html', {"page": page})
    return HttpResponse(result.content)
Exemplo n.º 11
0
def book_comment_save(request):
    book_id = request.POST.get("book_id")
    content = request.POST.get("content")

    book = Book.objects.get(id=book_id)
    bc = BookComment(user=request.user, book=book, content=content)
    bc.save()
    cache_remove("book_%s" % book.id)

    body = u"""%(user)s 님의 댓글 (작성일시: %(create_time)s)
-----------------------------------------------------------------------------

%(content)s

-----------------------------------------------------------------------------
%(subject)s URL : http://wikidocs.net/book/%(book_id)s
    """ % {
        "user": request.user.first_name,
        "create_time": bc.create_time.strftime(u"%Y-%m-%d %X"),
        "content": content,
        "book_id": book.id,
        "subject": book.subject
    }

    emails = []
    for user in book.user.all():
        if user != request.user:
            emails.append(user.email)

    # 댓글에 이름 언급 시 이메일 송신
    for bc in BookComment.objects.filter(book=book):
        if content.find(
                bc.user.first_name
        ) != -1 and bc.user != request.user and bc.user.email not in emails:
            emails.append(bc.user.email)

    send_mail(u"%s 에 댓글이 작성되었습니다." % (book.subject), body,
              settings.DEFAULT_FROM_EMAIL, emails)

    result = render(request, 'book/include/book_comment.html', {"book": book})
    return HttpResponse(result.content)
Exemplo n.º 12
0
def book_comment_save(request):
    book_id = request.POST.get("book_id")
    content = request.POST.get("content")

    book = Book.objects.get(id=book_id)
    bc = BookComment(user=request.user, book=book, content=content)
    bc.save()
    cache_remove("book_%s" % book.id)

    body = u"""%(user)s 님의 댓글 (작성일시: %(create_time)s)
-----------------------------------------------------------------------------

%(content)s

-----------------------------------------------------------------------------
%(subject)s URL : http://wikidocs.net/book/%(book_id)s
    """ % {
        "user": request.user.first_name,
        "create_time": bc.create_time.strftime(u"%Y-%m-%d %X"),
        "content": content,
        "book_id": book.id,
        "subject": book.subject
    }

    emails = []
    for user in book.user.all():
        if user != request.user:
            emails.append(user.email)

    # 댓글에 이름 언급 시 이메일 송신
    for bc in BookComment.objects.filter(book=book):
        if content.find(bc.user.first_name) != -1 and bc.user != request.user and bc.user.email not in emails:
            emails.append(bc.user.email)

    send_mail(u"%s 에 댓글이 작성되었습니다." % (book.subject),
              body,
              settings.DEFAULT_FROM_EMAIL,
              emails)

    result = render(request, 'book/include/book_comment.html', {"book": book})
    return HttpResponse(result.content)