当前位置: 首页>>代码示例>>Python>>正文


Python CommentForm.save方法代码示例

本文整理汇总了Python中comments.forms.CommentForm.save方法的典型用法代码示例。如果您正苦于以下问题:Python CommentForm.save方法的具体用法?Python CommentForm.save怎么用?Python CommentForm.save使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在comments.forms.CommentForm的用法示例。


在下文中一共展示了CommentForm.save方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: AddCommentView

# 需要导入模块: from comments.forms import CommentForm [as 别名]
# 或者: from comments.forms.CommentForm import save [as 别名]
class AddCommentView(TemplateView):
	@method_decorator(writeable_site_required)
	@method_decorator(login_required)
	def dispatch(self, request, *args, **kwargs):
		commentable_id = self.args[0]
		self.commentable = get_object_or_404(self.commentable_model, id=commentable_id)
		self.comment = Comment(commentable=self.commentable, user=request.user)
		return super(AddCommentView, self).dispatch(request, *args, **kwargs)

	def get(self, request, *args, **kwargs):
		self.form = CommentForm(instance=self.comment, prefix='comment')
		context = self.get_context_data()
		return self.render_to_response(context)

	def post(self, request, *args, **kwargs):
		self.form = CommentForm(request.POST, instance=self.comment, prefix='comment')
		if self.form.is_valid():
			self.form.save()
			return redirect(
				self.commentable.get_absolute_url() + ('#comment-%d' % self.comment.id)
			)
		else:
			context = self.get_context_data()
			return self.render_to_response(context)

	def get_context_data(self, **kwargs):
		context = super(AddCommentView, self).get_context_data(**kwargs)
		context['commentable'] = self.commentable
		context['commentable_name'] = self.get_commentable_name(self.commentable)
		context['comment_form'] = self.form
		context['submit_action'] = self.submit_action
		return context

	template_name = 'comments/add_comment.html'
开发者ID:DannyCork,项目名称:demozoo,代码行数:36,代码来源:views.py

示例2: edit_comment

# 需要导入模块: from comments.forms import CommentForm [as 别名]
# 或者: from comments.forms.CommentForm import save [as 别名]
def edit_comment(request, comment_id):
    if not request.user.is_authenticated():
        return request_login(request)
    try:
        comment = Comment.objects.get(id=comment_id)
    except:
        raise Http404
    if not request.user == comment.user:
        messages.add_message(request,
                             messages.ERROR,
                             "You can only edit your own comments.")
        return HttpResponseRedirect(reverse('proposal',
                                            args=[
                                                str(comment.proposal.id),
                                                comment.proposal.slug
                                            ]))
    else:
        if request.method == "POST":
            if comment.is_new():
                form = CommentForm(request.POST, instance=comment)
                if form.is_valid():
                    form.save()
                    messages.add_message(request,
                                         messages.SUCCESS,
                                         "Comment edited.")
                    return HttpResponseRedirect(reverse("proposal", args=[
                        str(comment.proposal.id), comment.proposal.slug
                    ]) + "#comment_" + str(comment.id))
                else:
                    messages.add_message(request,
                                         messages.ERROR,
                                         "Invalid comment")
            else:
                messages.add_message(request,
                                     messages.ERROR,
                                     "You can only edit a comment in the "
                                     "first 5 minutes.")
        form = CommentForm(instance=comment)
        if comment.is_new():
            if request.is_ajax():
                extend_template = "ajax_base.html"
            else:
                extend_template = "base.html"
            return render(request,
                          "edit_comment_form.html",
                          {"form": form,
                           "comment": comment,
                           "extend_template": extend_template})
        else:
            messages.add_message(request,
                                 messages.ERROR,
                                 "You can only edit a comment in the "
                                 "first 5 minutes.")
            return HttpResponseRedirect(reverse("proposal", args=[
                str(comment.proposal.id), comment.proposal.slug
            ]) + "#comment_" + str(comment.id))
开发者ID:HughMcGrade,项目名称:eusay,代码行数:58,代码来源:views.py

示例3: update

# 需要导入模块: from comments.forms import CommentForm [as 别名]
# 或者: from comments.forms.CommentForm import save [as 别名]
def update(request, pk):
    comment = get_object_or_404(Comment, pk=pk)
    if request.method == "POST":
        form = CommentForm(request.POST, instance=comment)
        if form.is_valid():
            form.save()
            return HttpResponseRedirect("%s#%s" % (
                comment.link.get_absolute_url(), comment.id))
        else:
            print form.errors
开发者ID:doganaydin,项目名称:Linkfloyd,代码行数:12,代码来源:views.py

示例4: add_comment

# 需要导入模块: from comments.forms import CommentForm [as 别名]
# 或者: from comments.forms.CommentForm import save [as 别名]
def add_comment(request, article_id):
    if request.POST and ("pause", not request.session):
        form = CommentForm(request.POST)
        return_path = request.META.get('HTTP_REFERER', '/')
        if form.is_valid():
            comment = form.save(commit=False)
            comment.comment_user = request.user
            comment.comment_article = Article.objects.get(id = article_id)
            form.save()
            request.session.set_expiry(600)
            request.session['pause'] = True
    return  redirect(return_path)
开发者ID:maximchuk,项目名称:myblog,代码行数:14,代码来源:views.py

示例5: addcomment

# 需要导入模块: from comments.forms import CommentForm [as 别名]
# 或者: from comments.forms.CommentForm import save [as 别名]
def addcomment(request, talent_id):
    if request.POST and ("pause" not in request.session):
        # sozdaem formu-->raznosim v nee dannie is post zaprosa
        form = CommentForm(request.POST)
        # esli forma validna
        if form.is_valid():
            # zapret auti sohraneniya formi
            comment = form.save(commit=False)
            # nahodim, k kakomu talantu sohranit'
            comment.comments_talent = Talent.objects.get(id=talent_id)
            comment.comments_from = request.user
            form.save()
        # request.session.set_expiry(60)
        # request.session['pause'] = True
    return redirect('/talents/get/%s/' % talent_id)
开发者ID:timofeyantonenko,项目名称:JDream,代码行数:17,代码来源:views.py

示例6: blog

# 需要导入模块: from comments.forms import CommentForm [as 别名]
# 或者: from comments.forms.CommentForm import save [as 别名]
def blog(request, slug):
    from comments.models import BLOG
    blog = Blog.objects.get(slug=slug)
    if not blog:
        raise Http404
    form = CommentForm()
    if request.POST:
        form = CommentForm(request.POST)
        if form.is_valid():
            comment = form.save(commit=False)
            comment.author = request.user
            comment.thing_id = blog.id
            comment.type = BLOG
            comment.thread_id, comment.reverse_thread_id = \
                    get_thread_id(type='blog', thing_id=blog.id)
            comment.save()
            return HttpResponseRedirect(reverse(
                'blog.views.blog',
                args=(blog.slug,)))

    commentsPage, commentsIndex, commentsTree = \
        get_comments_page(request, type=BLOG, obj=blog, rpp=10)

    return render_to_response(request, 'blog/blog.html', {
        'blog': blog,
        'commentForm': form,
        'comments': commentsPage,
        'commentsIndex': commentsIndex,
        'commentsTree': commentsTree,
    })
开发者ID:mrigor,项目名称:blogly,代码行数:32,代码来源:views.py

示例7: article_show

# 需要导入模块: from comments.forms import CommentForm [as 别名]
# 或者: from comments.forms.CommentForm import save [as 别名]
def article_show(request, channel, slug):
    try:
        article = Article.published_detail.get(slug=slug, channel__slug=channel)
        article.views_count_last_week += 1
        article.views_count += 1
        article.save()
    except:
        raise Http404(u'Notícia não encontrada')
    
    if request.method == 'POST':
        form = CommentForm(request.POST)
        if form.is_valid():
            comment = form.save(commit=False)
            comment.submit_date = datetime.now()
            comment.user = None
            comment.site = Site.objects.get_current()
            comment.ip_address = request.META.get("REMOTE_ADDR", None)
            comment.content_type = ContentType.objects.get_for_model(article)
            comment.object_pk = article.id
            comment.save()
            return HttpResponseRedirect(reverse('article_show',args=(article.channel.slug,article.slug)))
    else:
        form = CommentForm()

    related_articles = article.get_related_articles()
    return render_to_response('articles/article_show.html', {
        'article': article,
        'related_articles': related_articles,
        'form':form,
        'is_article':True,
    }, context_instance=RequestContext(request))
开发者ID:vitorh45,项目名称:exemplos,代码行数:33,代码来源:views.py

示例8: edit_comment

# 需要导入模块: from comments.forms import CommentForm [as 别名]
# 或者: from comments.forms.CommentForm import save [as 别名]
def edit_comment(request, sub_id, comment_id):
    submission = Submission.objects.get(pk=sub_id)
    try:
        comment = Comment.objects.get(pk=comment_id)
        if comment.user.email != request.session['email']:
            return HttpResponseRedirect('/submissions/show/'+str(sub_id))
    except Comment.DoesNotExist:
        raise Http404("Comment does not exist")
    if request.method == 'POST':
        comment_form = CommentForm(request.POST, instance=comment)
        if comment_form.is_valid():
            comment = comment_form.save(commit=False)
            comment.user = UserProfile.objects.get(email=request.session['email'])
            # comment.content = bleach.clean(comment.content, strip=True)
            # comment.content = markdown.markdown(comment.content)
            comment.save()
            submission.comments.add(comment)
            return HttpResponseRedirect('/submissions/show/' + str(sub_id))
        else:
            raise Http404("Form is not valid")
    elif request.method == 'GET':
        c_edit = comment
        # c_edit.content = bleach.clean(c_edit.content, strip=True)
        comment_form = CommentForm(instance=c_edit)

        return render(request, 'submissions/edit_comment.html',
                      {'form': comment_form, 'sub_id': sub_id, 'comment':comment})
开发者ID:karthikgg,项目名称:bobblehead,代码行数:29,代码来源:views.py

示例9: video_show

# 需要导入模块: from comments.forms import CommentForm [as 别名]
# 或者: from comments.forms.CommentForm import save [as 别名]
def video_show(request, slug):
    try:
        video = Video.objects.get(slug=slug)
    except:
        raise Http404(u'Vídeo não encontrado.')

    related_videos = video.get_related_videos()

    if request.method == 'POST':
        form = CommentForm(request.POST)
        if form.is_valid():
            comment = form.save(commit=False)
            comment.submit_date = datetime.now()
            comment.user = None
            comment.site = Site.objects.get_current()
            comment.ip_address = request.META.get("REMOTE_ADDR", None)
            comment.content_type = ContentType.objects.get_for_model(video)
            comment.object_pk = video.id
            comment.save()
            return HttpResponseRedirect(reverse('video_show',args=[video.slug]))
    else:
        form = CommentForm()

    return render_to_response('videos/video_show.html', {
        'video': video,
        'related_videos':related_videos,
        'form':form,
    }, context_instance=RequestContext(request))
开发者ID:vitorh45,项目名称:exemplos,代码行数:30,代码来源:views.py

示例10: add_comment

# 需要导入模块: from comments.forms import CommentForm [as 别名]
# 或者: from comments.forms.CommentForm import save [as 别名]
def add_comment(request, object_type, id):
    
    skip = False
    if object_type == 'comicpage':
        object = get_object_or_404(ComicPage, pk=id)
    elif object_type == 'article':
        object = get_object_or_404(Article, pk=id)
    elif object_type == 'profile':
        object = get_object_or_404(Profile, pk=id)
        friend_status = get_relationship_status(object.user, request.user)
        if friend_status < 2 and object.user != request.user:
            skip = True
    elif object_type == 'tutorial': 
        object = get_object_or_404(Tutorial, pk=id)
    elif object_type == 'episode': 
        object = get_object_or_404(Episode, pk=id)
    elif object_type == 'video': 
        object = get_object_or_404(Video, pk=id)
    if request.method == 'POST' and not skip:
        form = CommentForm(request.POST)
        if form.is_valid():
            comment = form.save(commit=False)
            comment.author = request.user
            comment.save()
            object.comments.add(comment)
    comments = object.comments.filter(is_deleted=False)
    return render_to_response('comments/list.html', {'comments':comments}, context_instance=RequestContext(request))
开发者ID:wowioboy,项目名称:popgalaxy_v2,代码行数:29,代码来源:views.py

示例11: NewsDetail

# 需要导入模块: from comments.forms import CommentForm [as 别名]
# 或者: from comments.forms.CommentForm import save [as 别名]
class NewsDetail(DetailView):
    model = Article
    template_name = 'news/article.html'

    @method_decorator(login_required)
    def dispatch(self, request, *args, **kwargs):
        self.comment_form = CommentForm(request.POST or None) # create filled (POST) or empty form (initial GET)
        if request.method == 'POST':
            self.comment_form.instance.article_id = self.get_object().id

            if self.comment_form.is_valid():
                comment = self.comment_form.save(commit=True)
                client = Client()
                client.publish(self.get_object().get_cent_comments_channel_name(), comment.as_compact_dict())
                cent_response = client.send()
                print('sent to channel {}, got response from centrifugo: {}'.format(self.get_object().get_cent_comments_channel_name(),
                                                                                    cent_response))
                return HttpResponse()
                # return HttpResponseRedirect(reverse('news:detail', args=[self.get_object().pk,]))
            else:
                return super().get(request, *args, **kwargs)
                # context = self.get_context_data()
                # return render('news/article.html', context)

        return super().dispatch(request, *args, **kwargs)

    def get_context_data(self, **kwargs):
        context = super().get_context_data(**kwargs)
        context['comment_form'] = self.comment_form
        return context
开发者ID:roman-spiridonov,项目名称:sandbox,代码行数:32,代码来源:views.py

示例12: new

# 需要导入模块: from comments.forms import CommentForm [as 别名]
# 或者: from comments.forms.CommentForm import save [as 别名]
def new(request, pk):
    note = get_object_or_404(Note, pk=pk)
    if request.method == 'POST':
        form = CommentForm(request.POST)
        if form.is_valid():
            comment = form.save(commit=False)
            comment.note = note
            comment.user = request.user
            comment.save()
            # add rep
            add_rep(request, c=comment)
            # create notification
            notify(comment=comment)
            d = {
                    'comment': comment,
                    'comment_form': CommentForm(),
                    'note': note,
                    'reply_form': ReplyForm(),
                    'static': settings.STATIC_URL,
            }
            comment_form = loader.get_template('comments/comment_form.html')
            comment_temp = loader.get_template('comments/comment.html')
            context = RequestContext(request, add_csrf(request, d))
            data = {
                        'comment': comment_temp.render(context),
                        'comment_count': note.comment_count(),
                        'comment_form': comment_form.render(context),
                        'comment_pk': comment.pk,
                        'note_pk': note.pk,
            }
            return HttpResponse(json.dumps(data), mimetype='application/json')
    return HttpResponseRedirect(reverse('readings.views.detail', 
        args=[reading.slug]))
开发者ID:tommydangerous,项目名称:skimreads,代码行数:35,代码来源:views.py

示例13: detail

# 需要导入模块: from comments.forms import CommentForm [as 别名]
# 或者: from comments.forms.CommentForm import save [as 别名]
def detail(request, pk):
    post = get_object_or_404(Post, pk=pk)
    if post.draft:
        if post.user != request.user:
            messages.error(request,'you have not permission to see that post',extra_tags='alert alert-danger')
            return redirect('posts:index')
    form=CommentForm(request.POST or None)
    # add comment
    if form.is_valid() and request.user.is_authenticated:
        instance=form.save(commit=False)
        instance.user=request.user
        instance.post=post
        parent=None
        try:
            parent_id=int(request.POST.get('parent_id'))
        except:
            parent_id=None
        if parent_id:
            query=Comment.objects.filter(id=parent_id)
            if query.exists():
                parent=query.first()
        instance.parent=parent
        instance.save()
        return redirect('posts:detail',pk)
    return render(request, 'detail.html', {'post': post,'comment_form':form})
开发者ID:ahmedemad2051,项目名称:django-study,代码行数:27,代码来源:views.py

示例14: post

# 需要导入模块: from comments.forms import CommentForm [as 别名]
# 或者: from comments.forms.CommentForm import save [as 别名]
 def post(self, request, pk):
     self.object = get_object_or_404(Article, id=pk)
     comment = CommentForm(request.POST)
     commit_instance = comment.save()
     self.object.comments.add(commit_instance)
     self.object.save()
     return redirect(reverse('article_detail', args=[pk]))
开发者ID:winglq,项目名称:site,代码行数:9,代码来源:views.py

示例15: post_show

# 需要导入模块: from comments.forms import CommentForm [as 别名]
# 或者: from comments.forms.CommentForm import save [as 别名]
def post_show(request, blog, slug):    
    try:
        blog = Blog.objects.get(slug=blog)
    except:
        raise Http404(u'Não disponível')
    try:
        post = Post.published.get(slug=slug, blog=blog)
    except:
        raise Http404(u'Não disponível')    

    if request.method == 'POST':
        form = CommentForm(request.POST)
        if form.is_valid():
            comment = form.save(commit=False)
            comment.submit_date = datetime.now()
            comment.user = None
            comment.site = Site.objects.get_current()
            comment.ip_address = request.META.get("REMOTE_ADDR", None)
            comment.content_type = ContentType.objects.get_for_model(post)
            comment.object_pk = post.id
            comment.save()
            return HttpResponseRedirect(reverse('post_show',args=(blog.slug,post.slug)))
    else:
        form = CommentForm()

    return render_to_response('blog/post_show.html', {
        'post': post,
        'blog': blog,
        'form':form,
    }, context_instance=RequestContext(request))
开发者ID:vitorh45,项目名称:exemplos,代码行数:32,代码来源:views.py


注:本文中的comments.forms.CommentForm.save方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。