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


Python forms.CommentForm类代码示例

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


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

示例1: post_show

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,代码行数:30,代码来源:views.py

示例2: publication_detail

def publication_detail(request, pk):
	try :
		object = Parution.objects.get(pk=pk)
		comments = Comment.objects.filter(parution=object)
		comment_form = CommentForm(request.POST or None)

		context = {
					"object":object,
					"comments":comments,
				}
		
		if comment_form.is_valid():
			comment_text = comment_form.cleaned_data['comment']
			print(comment_text)
			print(request.user)
			print(object)
			print(request.get_full_path())
			print(object.get_absolute_url())
			new_comment = Comment.objects.create_comment(user=request.user,text=comment_text,path=request.get_full_path(),parution=object)
			return HttpResponseRedirect(object.get_absolute_url())
			return render(request,"blogdef/parution_detail.html",context)	

		context["comment_form"]=comment_form
		return render(request,"blogdef/parution_detail.html",context)	
	except :
		raise Http404
开发者ID:rogilesor,项目名称:myBlog,代码行数:26,代码来源:views.py

示例3: post

    def post(self, request, *args, **kwargs):
        if not request.user.is_authenticated():
            return Response(status.HTTP_401_UNAUTHORIZED)

        ct = ContentType.objects.get_for_model(MODELS_MAPPINGS[kwargs['model']])

        try:
            obj = ct.get_object_for_this_type(pk=kwargs['object_id'])
        except ObjectDoesNotExist:
            raise ErrorResponse(status.HTTP_404_NOT_FOUND)

        form = CommentForm(request.POST)
        if not form.is_valid():
            raise ErrorResponse(status.HTTP_400_BAD_REQUEST)

        data = {
            'content_type': ct,
            'object_id': kwargs['object_id'],
            'user': request.user,
            'created': datetime.datetime.now(),
            'content': form.cleaned_data['content'],
        }

        parent = form.cleaned_data['parent']
        if parent:
            instance = parent.add_child(**data)
        else:
            instance = Comment.add_root(**data)

        if request.is_ajax():
            return Response(status.HTTP_201_CREATED)
        return HttpResponseRedirect(obj.get_absolute_url())
开发者ID:svartalf,项目名称:abakron,代码行数:32,代码来源:api.py

示例4: detail

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,代码行数:25,代码来源:views.py

示例5: post

 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,代码行数:7,代码来源:views.py

示例6: NewsDetail

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,代码行数:30,代码来源:views.py

示例7: new

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,代码行数:33,代码来源:views.py

示例8: video_show

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,代码行数:28,代码来源:views.py

示例9: AddCommentView

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,代码行数:34,代码来源:views.py

示例10: edit_comment

def edit_comment(request, problem_id, solution_id, comment_id):
    solution = Solution.objects.get(pk=solution_id)
    try:
        comment = Comment.objects.get(pk=comment_id)
        if comment.user.email != request.session['email']:
            return HttpResponseRedirect('/problems/'+str(problem_id)+'/show_solution/'+str(solution_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.save()
            solution.comments.add(comment)
            return HttpResponseRedirect('/problems/'+str(problem_id)+'/show_solution/'+str(solution_id))
        else:
            print comment_form.errors
    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, 'problems/edit_comment.html',
                      {'form': comment_form, 'problem_id': problem_id, 'solution_id': solution_id, 'comment':comment})
开发者ID:karthikgg,项目名称:bobblehead,代码行数:25,代码来源:views.py

示例11: postshow

def postshow(request, id):
	if not request.user.is_authenticated():
		raise Http404
	instance = get_object_or_404(Post, id=id)
	queryset = Post.objects.get(id=id)
	initial_data = {
		"content_type": instance.get_content_type,
		"object_id": instance.id
	}
	form = CommentForm(request.POST or None, initial=initial_data)
	if form.is_valid():
		c_type = form.cleaned_data.get("content_type")
		content_type = ContentType.objects.get(model=c_type)
		obj_id = form.cleaned_data.get('object_id')
		content_data = form.cleaned_data.get("content")
		new_comment, created = Comment.objects.get_or_create(
							user = request.user,
							content_type= content_type,
							object_id = obj_id,
							content = content_data
						)
		if created:
			print("Yeah it work")
		# print(comment_from.cleaned_data)
	comments = instance.comments
	#comments = Comment.objects.filter(user=request.user)
	#comments = Comment.objects.filter(post=instance)
	context = {
		'post': queryset,
		'comments':comments,
		'comment_from':form,
	}
	return render(request,"post/show.html",context)
开发者ID:dehors,项目名称:CursoDJ19,代码行数:33,代码来源:views.py

示例12: sound

def sound(request, username, sound_id):
    try:
        sound = Sound.objects.select_related("license", "user", "user__profile", "pack", "remix_group").get(id=sound_id)
        if sound.user.username.lower() != username.lower():
            raise Http404
        user_is_owner = request.user.is_authenticated() and (
            sound.user == request.user
            or request.user.is_superuser
            or request.user.is_staff
            or Group.objects.get(name="moderators") in request.user.groups.all()
        )
        # If the user is authenticated and this file is his, don't worry about moderation_state and processing_state
        if user_is_owner:
            if sound.moderation_state != "OK":
                messages.add_message(request, messages.INFO, "Be advised, this file has <b>not been moderated</b> yet.")
            if sound.processing_state != "OK":
                messages.add_message(request, messages.INFO, "Be advised, this file has <b>not been processed</b> yet.")
        else:
            if sound.moderation_state != "OK" or sound.processing_state != "OK":
                raise Http404
    except Sound.DoesNotExist:  # @UndefinedVariable
        try:
            DeletedSound.objects.get(sound_id=sound_id)
            return render_to_response("sounds/deleted_sound.html", {}, context_instance=RequestContext(request))
        except DeletedSound.DoesNotExist:
            raise Http404

    tags = sound.tags.select_related("tag__name")

    if request.method == "POST":
        form = CommentForm(request, request.POST)
        if request.user.profile.is_blocked_for_spam_reports():
            messages.add_message(
                request,
                messages.INFO,
                "You're not allowed to post the comment because your account has been temporaly blocked after multiple spam reports",
            )
        else:
            if form.is_valid():
                comment_text = form.cleaned_data["comment"]
                sound.comments.add(Comment(content_object=sound, user=request.user, comment=comment_text))
                sound.num_comments = sound.num_comments + 1
                sound.save()
                try:
                    # send the user an email to notify him of the new comment!
                    logger.debug(
                        "Notifying user %s of a new comment by %s" % (sound.user.username, request.user.username)
                    )
                    send_mail_template(
                        u"You have a new comment.",
                        "sounds/email_new_comment.txt",
                        {"sound": sound, "user": request.user, "comment": comment_text},
                        None,
                        sound.user.email,
                    )
                except Exception, e:
                    # if the email sending fails, ignore...
                    logger.error("Problem sending email to '%s' about new comment: %s" % (request.user.email, e))

                return HttpResponseRedirect(sound.get_absolute_url())
开发者ID:yanomamo,项目名称:freesound,代码行数:60,代码来源:views.py

示例13: after_transcribe_comment

def after_transcribe_comment(request, document_id):
    """
    Prompt for a comment after a transcription is done.
    """
    document = get_object_or_404(Document, pk=document_id, 
                                 type="post",
                                 scan__isnull=False,
                                 transcription__isnull=False)

    # Don't prompt for comment if they've already commented on this post.
    if document.comments.filter(user=request.user).exists() or (not settings.COMMENTS_OPEN):
        return redirect(document.get_absolute_url() + "#transcription")

    if document.transcription.complete:
        prompt_text = "Thanks for writing! I finished the transcription for your post."
    else:
        prompt_text = "Thanks for writing! I worked on the transcription for your post."
    form = CommentForm(request.POST or None, initial={
        'comment': prompt_text
    })
    if form.is_valid():
        comment, created = Comment.objects.get_or_create(
            document=document,
            comment=form.cleaned_data['comment'],
            user=request.user,
        )
        if created:
            comment.document = document
        return redirect("%s#%s" % (request.path, comment.pk))
    
    return render(request, "scanning/after_transcribe_comment.html", {
        'document': document,
        'form': form,
    })
开发者ID:Shidash,项目名称:btb,代码行数:34,代码来源:views.py

示例14: blog

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,代码行数:30,代码来源:views.py

示例15: article_show

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,代码行数:31,代码来源:views.py


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