예제 #1
0
 def mutate(root, info, input=None):
     Posts = []
     for post_input in input.posts:
         post = Post.objects.get(pk=post_input['id'])
         if post is None:
             return CreateComment(comment=None)
         Posts.append(post)
     comment_instance = Comment(text=input.text, author=input.author)
     comment_instance.save()
     comment_instance.posts.set(Posts)
     return CreateComment(comment=comment_instance)
예제 #2
0
파일: views.py 프로젝트: blx666/MyBlog
def publishcomment(request):
    ##使用一个form类
    content = request.POST['comment']
    blogid = request.POST['blogid']
    commentModel = Comment()
    commentModel.content = content
    commentModel.blogid_id = blogid
    commentModel.save()
    blogModelList = Blog.objects.all()
    return render(request, 'blogapp/publishblog.html',
                  {'blogModelList': blogModelList})
예제 #3
0
def comment(request):
    now = datetime.datetime.now()
    if request.method == 'POST': # If the form has been submitted...
        form = CommentForm(request.POST) # A form bound to the POST data
        if form.is_valid(): # All validation rules pass
            # Process the data in form.cleaned_data
            try:
                form_name = User.objects.get(username = request.user)
            except User.DoesNotExist:
                return HttpResponseRedirect('/login/')
            form_comment = form.cleaned_data['comment']
            form_hid_id = form.cleaned_data['hidden_id']
            form_hid_name = form.cleaned_data['hidden_name']
            c = Comment(post_fkey_id = form_hid_id, uname = form_name, comment = form_comment, com_date = now)
            c.save()
            return HttpResponseRedirect('/posts/%s/%d/' %(form_hid_name, form_hid_id)) # Redirect after POST
예제 #4
0
def detail(request,page_num):

    if request.method == "GET":
        form = CommentForm

    if request.method == "POST":
        form = CommentForm(request.POST)
        if form.is_valid():
            name = form.cleaned_data['name']
            comment = form.cleaned_data['comment']
            a = Aritcle.objects.get(id=page_num)
            c = Comment(name = name,comment = comment,belong_to=a)
            c.save()
            return redirect(to=detail,page_num=page_num)
    context = {}
    #comment_list = Comment.objects.all()
    article = Aritcle.objects.get(id=page_num)
    context['article'] = article
    #context['comment_list'] = comment_list
    context['form'] = form
    return render(request, 'detail.html', context)
예제 #5
0
    #semi-perfect length :)
    if len(excerpt) > 80:
        mark_pos = excerpt.find(strip_tags(mark))
        mark_len = len(strip_tags(mark))

        #might need some improvement
        start_diff = mark_pos - 30
        end_diff = len(excerpt) - mark_pos - mark_len - 30

        #might need some improvement as well
        start = (start_diff > 0) and (start_diff) or 0
        if end_diff < 0:
            end = len(excerpt)
        else:
            end = len(excerpt) - end_diff - ((start_diff < 0) and start_diff or 0)

        excerpt = excerpt[start:end]
        excerpt = ' '.join(excerpt.split(' ')[1:-1])

    excerpt = "[...] " + excerpt + " [...]"

    c = Comment(
        author_name=escape(title), 
        author_website=escape(resource),
        content=escape(excerpt),
        date=datetime.now(),
        comment_type='linkback',
        post=post_id)
    c.save()

    return "Pingback registered. Thank you."