Beispiel #1
0
def comment(request, theme):
    if request.method == "POST":
        com = Comment.objects.order_by('idComment')[:1]
        for c in com:
            idC = c.idComment + 1

        com = Comments(request.POST)

        username = request.user
        f = get_object_or_404(Forum, theme=theme)
        #validamos el formulario
        if com.is_valid():
            comment = Comment()
            comment.theme = f
            comment.idComment = idC
            comment.username = username
            comment.commentText = request.POST["commentText"]
            comment.title = request.POST["title"]
            comment.date = datetime.date.today()

            comment.save()

            return (showComments(request, theme))
    else:
        com = Comment.objects.order_by('idComment')[:1]
        for c in com:
            idC = c.idComment + 1
        com = Comment()

    return render(request, 'comentarios.html', {'commentForm': com})
Beispiel #2
0
def comment(request,theme):
    if request.method =="POST":
        com = Comment.objects.order_by('idComment')[:1]
        for c in com:
            idC = c.idComment+1

        com = Comments(request.POST)

        username = request.user
        f = get_object_or_404(Forum,theme=theme)
        #validamos el formulario
        if com.is_valid():
            comment = Comment()
            comment.theme = f
            comment.idComment = idC
            comment.username = username
            comment.commentText = request.POST["commentText"]
            comment.title = request.POST["title"]
            comment.date = datetime.date.today()

            comment.save()

            return (showComments(request,theme))
        else:
            print comm.errors
    else:
        com = Comment.objects.order_by('idComment')[:1]
        for c in com:
            idC = c.idComment+1
        com = Comment()

    return render(request,'comentarios.html',{'commentForm':com})
Beispiel #3
0
def showComments(request, theme):
    #obtenemos el foro asociado a un tema
    form = Forum.objects.get(theme=theme)
    #filtramos comentarios de un foro con un tema
    comForm = Comment.objects.filter(theme=form).order_by('date')

    if request.method == "POST":
        idC = 0
        com = Comment.objects.order_by('idComment')[:1]
        for c in com:
            idC = c.idComment + 1

        com = Comments(request.POST)

        username = request.user
        f = get_object_or_404(Forum, theme=theme)
        #validamos el formulario
        if com.is_valid():
            comment = Comment()
            comment.theme = f
            comment.idComment = idC
            comment.username = username
            comment.commentText = request.POST["commentText"]
            comment.title = request.POST["title"]
            comment.date = datetime.date.today()

            comment.save()

            return redirect("/foros/theme/" + theme, {
                'com': comForm,
            })
    else:
        com = Comment.objects.order_by('idComment')[:1]
        for c in com:
            idC = c.idComment + 1
        com = Comment()

    context = {'com': comForm, 'commentForm': com, 'theme': theme}
    return render(request, 'comentarios.html', context)
Beispiel #4
0
def showComments(request,theme):
    #obtenemos el foro asociado a un tema
    form = Forum.objects.get(theme=theme)
    #filtramos comentarios de un foro con un tema
    comForm = Comment.objects.filter(theme=form).order_by('date')

    if request.method =="POST":
        idC = 0
        com = Comment.objects.order_by('idComment')[:1]
        for c in com:
            idC = c.idComment+1

        com = Comments(request.POST)

        username = request.user
        f = get_object_or_404(Forum,theme=theme)
        #validamos el formulario
        if com.is_valid():
            comment = Comment()
            comment.theme = f
            comment.idComment = idC
            comment.username = username
            comment.commentText = request.POST["commentText"]
            comment.title = request.POST["title"]
            comment.date = datetime.date.today()

            comment.save()

            return redirect("/foros/theme/"+theme,{'com': comForm,})
    else:
        com = Comment.objects.order_by('idComment')[:1]
        for c in com:
            idC = c.idComment+1
        com = Comment()

    context = {'com': comForm,'commentForm':com,'theme': theme}
    return render(request,'comentarios.html',context)