Beispiel #1
0
def my_comment(request):
    question = Question.objects.filter(
        question_comment__user_id=request.user.id).distinct()
    return render(request,
                  'useracount/my_comment.html',
                  context={
                      'questions': question,
                      'form': QuestionForms(),
                      'comment_form': CommentForms()
                  })
Beispiel #2
0
def forum(request):
    comment_form = CommentForms()
    question = Question.objects.all()
    question_filter = QuestionFilter()
    form = QuestionForms()
    if 'filter_question' in request.POST:
        if request.method == 'POST':
            question_filter = QuestionFilter(request.POST, queryset=question)
            question = question_filter.qs
            if question_filter.is_valid():
                data = {
                    'questions': question,
                    'form': form,
                    'comment_form': comment_form,
                    'question_filter': question_filter
                }
                return render(request, 'blogsite/forum1.html', context=data)
    if request.method == 'POST':
        form = QuestionForms(request.POST)
        if form.is_valid():
            question_obj = form.save(commit=False)
            question_obj.author = request.user
            slug_set = question_obj.question
            question_obj.slug = slug_set.replace(" ", "-") + "-" + str(
                uuid.uuid1())
            question_obj.save()
            return redirect('/blogsite/forum/')

    data = {
        'questions': question,
        'form': form,
        'comment_form': comment_form,
        'question_filter': question_filter
    }
    return render(request, 'blogsite/forum1.html', context=data)
Beispiel #3
0
def question_edit(request, slug):
    show_form = slug
    question = Question.objects.get(slug=slug)
    form = QuestionForms(instance=question)
    if request.method == 'POST':
        form = QuestionForms(data=request.POST, instance=question)
        if form.is_valid():
            form.save()
            return redirect('/account/profile/')
    data = {
        'questions': Question.objects.filter(author_id=request.user.id),
        'show_form': show_form,
        'form': form
    }
    return render(request, 'useracount/my_profile.html', context=data)
Beispiel #4
0
def comments(request, slug):
    question = Question.objects.get(slug=slug)
    comment_form = CommentForms()
    if request.method == 'POST':
        comment_form = CommentForms(request.POST)
        if comment_form.is_valid():
            comment = comment_form.save(commit=False)
            comment.user = request.user
            comment.question = question
            comment.save()
            return redirect('/account/profile/')

    data = {
        'questions': question,
        'form': QuestionForms(),
        'comment_form': comment_form
    }
    return render(request, 'useracount/my_profile.html', context=data)
Beispiel #5
0
def blog_details(request, slug):
    question = Question.objects.get(slug=slug)
    comment_form = CommentForms()
    if request.method == 'POST':
        comment_form = CommentForms(request.POST)
        if comment_form.is_valid():
            comment = comment_form.save(commit=False)
            comment.user = request.user
            comment.question = question
            comment.save()
            return redirect('/blogsite/forum/')

    data = {
        'questions': question,
        'form': QuestionForms(),
        'comment_form': comment_form
    }
    return render(request, 'blogsite/forum1.html', context=data)
Beispiel #6
0
def question_comment(request):
    if request.method == 'GET':
        question = Question.objects.all()
        questions = []
        for x in question:
            comment = Comment.objects.filter(question_id=x.id)
            if len(comment) != 0:
                questions.append(x)
        data = {
            'questions': questions,
            'form': QuestionForms(),
            'question_filter': QuestionFilter(),
            'comment_form': CommentForms()
        }
        return render(request, 'blogsite/comment.html', context=data)

    if 'filter_question' in request.POST:
        if request.method == 'POST':
            question = Question.objects.all()
            question_filter = QuestionFilter(request.POST, queryset=question)
            question = question_filter.qs

            if question_filter.is_valid():
                data = {
                    'questions': question,
                    'form': QuestionForms(),
                    'question_filter': question_filter
                }
                return render(request, 'blogsite/forum1.html', context=data)

    if request.method == 'POST':
        form = QuestionForms(request.POST)
        if form.is_valid():
            question_obj = form.save(commit=False)
            question_obj.author = request.user
            slug_set = question_obj.question
            question_obj.slug = slug_set.replace(" ", "-") + "-" + str(
                uuid.uuid1())
            question_obj.save()
            return redirect('/blogsite/forum/')