Пример #1
0
def comentario_nuevo(request,post_pk):
	post=get_object_or_404(Post,pk=post_pk)
	if request.method=='POST':
		form=ComentarioForm(request.POST)
		if form.is_valid():
			comentario=form.save(commit=False)
			comentario.post=post
			comentario.save()	
			return redirect('post_detalle',post_pk=post.pk)
	else:
		form=ComentarioForm()
	return render(request,'blog/comentario_nuevo.html',{'form':form,'post':post})
Пример #2
0
def add_comentario_to_post(request, pk):
    post = get_object_or_404(Post, pk=pk)
    if request.method == "POST":
        form = ComentarioForm(request.POST)
        print ("ok")
        if form.is_valid():
            comentario = form.save(commit=False)
            comentario.post = post
            comentario.save()
            return redirect('post_detail', pk=post.pk)
        else:
            print ("Not ok")
    else:
        form = ComentarioForm()
    return render(request, 'blog/add_comentario_to_post.html', {'form': form})
Пример #3
0
def nuevocomentario(request, id_entrada):
	entry=Entry.objects.get(pk=id_entrada)
	usuario = request.user
	if usuario.is_authenticated():
		usuario = request.user
	else:
		usuario = None
	if request.method=='POST':
		formulario=ComentarioForm(request.POST)
		if formulario.is_valid():
			comment = formulario.save(commit=False)
			comment.entry=entry
			comment.user=usuario
			comment.save()
			return HttpResponseRedirect('/entry/%s' % entry.slug)
	else:
		formulario=ComentarioForm()
	return render_to_response('comentarioform.html', {'formulario':formulario, 'entrada':entry}, context_instance=RequestContext(request))
Пример #4
0
def blog_detail(request, pk, template_name="blog_detail.html"):
    postagem = Postagem.objects.get(pk=pk)

    formulario = ComentarioForm()
    if request.method == "POST":
        formulario = ComentarioForm(request.POST)
        if formulario.is_valid():
            comentario = Comentario(
                autor=formulario.cleaned_data["autor"],
                comentario=formulario.cleaned_data["comentario"],
                postagem=postagem)
            comentario.save()

    comentarios = Comentario.objects.filter(postagem=postagem)
    context = {
        "postagem": postagem,
        "comentarios": comentarios,
        "formulario": formulario
    }
    return render(request, template_name, context)
Пример #5
0
def agregar_comentario(request, articulo_id):
    articulo = Articulo.objects.get(id=articulo_id)

    if request.POST:
      form = ComentarioForm(request.POST)
      if form.is_valid():
        comentario = form.save(commit=False)

        comentario.fecha_pub = timezone.now()
        comentario.articulo = articulo

        comentario.save()

        return HttpResponseRedirect('/articulos/obtener/%s' % articulo_id)
    else:
        form = ComentarioForm()

    args = {}
    args.update(csrf(request))

    args['articulo'] = articulo
    args['form'] = form

    return render_to_response('agregar_comentario.html', args)
Пример #6
0
def blog(request, id_post=None):
    """
    Muestra un post con sus comentarios
    """
    # Si se accede a la url sin un id del post se usa el último
    if not id_post:
        id_post = Post.objects.aggregate(Max('id'))
        if id_post['id__max']:
            id_post = id_post['id__max']
        else:
            raise Http404

    post = get_object_or_404(Post, id=id_post)
    comentarios = Comentario.objects.filter(post=post, estado="M")
    comentado = False

    if request.method == 'POST':
        form = ComentarioForm(request.POST)
        if form.is_valid():
            comentario = form.save(commit=False)
            comentario.post = post
            comentario.save()
            comentado = True
            form = ComentarioForm()
    else:
        form = ComentarioForm()
        
    indice_posts = Post.objects.exclude(id=id_post).order_by('-id')[:10]

    return direct_response(request, "blog/post.html",
                           {"post": post,
                            "comentarios": comentarios,
                            "indice_posts": indice_posts,
                            "form": form,
                            "comentado": comentado,
                            "titulo": "Post: %s" % post.titulo})
Пример #7
0
def comentario_novo(request, pk):
    post = get_object_or_404(Post, pk=pk)

    if request.method == 'POST':
        form = ComentarioForm(request.POST)
        if form.is_valid():
            comentario = form.save(commit=False)
            comentario.post = post
            comentario.save()
            return redirect(reverse('post', kwargs={'pk': post.pk}))
    else:
        form = ComentarioForm()
    return render(request, 'comentario.html', {'form': form})
Пример #8
0
def comentario_nuevo(request, post_pk):
    post = get_object_or_404(Post, pk=post_pk)
    if request.method == 'POST':
        form = ComentarioForm(request.POST)
        if form.is_valid():
            comentario = form.save(commit=False)
            comentario.post = post
            comentario.save()
            return redirect('post_detalle', post_pk=post.pk)
    else:
        form = ComentarioForm()
    return render(request, 'blog/comentario_nuevo.html', {
        'form': form,
        'post': post
    })
Пример #9
0
def agregar_comentario(request, articulo_id):
    articulo = Articulo.objects.get(id=articulo_id)

    if request.POST:
        form = ComentarioForm(request.POST)
        if form.is_valid():
            comentario = form.save(commit=False)

            comentario.fecha_pub = timezone.now()
            comentario.articulo = articulo

            comentario.save()

            return HttpResponseRedirect('/articulos/obtener/%s' % articulo_id)
    else:
        form = ComentarioForm()

    args = {}
    args.update(csrf(request))

    args['articulo'] = articulo
    args['form'] = form

    return render_to_response('agregar_comentario.html', args)
Пример #10
0
def mostrarNoticia(request, noticias):
    noticia_list = Noticia.objects.get(id=noticias)
    try:
        comentarios = Comentarios.objects.filter(Noticia=noticias)
    except Comentarios.DoesNotExist:
        comentarios = None
    autor = User.objects.all()[:5]
    categoria = Categoria.objects.all()

    if request.method == 'POST':
        form = ComentarioForm(request.POST)
        if form.is_valid():
            formulario = form.save(commit=False)
            formulario.Noticia = noticia_list
            formulario.save()
            context = {'form': formulario, 'noticia': noticia_list, 'categoria_index': categoria, 'autor_index': autor,
                       'comentarios': comentarios}
            print form
            return render(request, "blog/mostrarNoticia.html", context)
    else:
        form = ComentarioForm()
    context = {'form': form, 'noticia': noticia_list, 'categoria_index': categoria, 'autor_index': autor,
               'comentarios': comentarios}
    return render(request, "blog/mostrarNoticia.html", context)