def show_tickets(request, pk):
    """
    These view is for show the details of issues and also it keeping comment form and comments detail as well  
    """
    ticket = get_object_or_404(add_tickets_form , pk=pk)
    ticket.views += 1
    ticket.save()
    print(ticket)
    #ticket_id = request.POST.get('ticket_id', None)
    #issue = add_tickets_form.objects.filter(id=ticket_id).first()
    if request.method == "POST":
       commentbox = CommentForm(request.POST)
       if commentbox.is_valid():
            comment_data = commentbox.cleaned_data
            add_issue = Comment_form.objects.create(
                comment = comment_data['comment'],
                user = request.user,
                ticket = get_object_or_404(add_tickets_form, pk=pk)
                )
            add_issue.save()
            return redirect(show_tickets,ticket.pk)
       print(commentbox)
    else:
        commentbox = CommentForm()
        
    comment = Comment_form.objects.all
    
    #like = like_posts.objects.all()
    
    return render(request, 'show_tickets.html', {'ticket':ticket, 'commentbox':commentbox, 'comment':comment})
    def test_comment_form_valid_data(self):
        """
            Test CommentForm with valid data.
        """

        form = CommentForm(data={'comment': 'I am a comment.'})

        self.assertTrue(form.is_valid())
Example #3
0
 def post(self, request, *args, **kwargs):
     commentForm = CommentForm(request.POST)
     if commentForm.is_valid():
         commentForm.save(request, Ticket.objects.get(id=kwargs['ticket_id']))
         return self.get(request, kwargs)
     self.get(request, *args, **kwargs)
     context = self.get_context_data(**kwargs) #check for error on empty message
     context['commentForm'] = commentForm
     return render(request, self.template_name, context)
    def test_comment_form_no_data(self):
        """
            Test CommentForm with no data.
        """

        form = CommentForm(data={})

        self.assertFalse(form.is_valid())
        self.assertEquals(len(form.errors), 1)
def edit_comments(request,id):
    comments = get_object_or_404(Comment_form,id=id)
    if request.method == "POST":
        form = CommentForm(request.POST, instance=comments)
        if form.is_valid():
            form.save()
            return redirect(index)
    else:
        form = CommentForm(instance=comments)
    return render(request,"edit_comments.html",{'form':form})
Example #6
0
    def post(self, request):
        ticketForm = TicketForm(request.POST, request=request)
        commentForm = CommentForm(request.POST)

        if ticketForm.is_valid() and commentForm.is_valid():
            ticket = ticketForm.save(request)
            comment = commentForm.save(request, ticket)
            return redirect('ticket details', ticket_id=ticket.id)
        context = self.get_context_data()
        context['ticketForm'] = ticketForm
        context['commentForm'] = commentForm
        return render(request, 'tickets/add-ticket.html', context)
Example #7
0
def add_comment(request, pk, uid):
    """ Create a view to allow adding comments to a ticket """
    ticket = get_object_or_404(Ticket, pk=pk) if pk else None
    if request.method == "POST":
        form = CommentForm(request.POST)
        if form.is_valid():
            form.save()
            messages.success(request, "Comment added")
            return redirect('show_comments', pk)
    else:
        form = CommentForm(initial={'ticket_id': pk, 'user_name': uid})
        return render(request, "commentform.html", {'ticket': ticket, 'form': form})
Example #8
0
def tickets_view_one(request, pk):
    """ View a Single Ticket """
    # get ticket details
    ticket = get_object_or_404(Ticket, pk=pk)
    # increase number of views by 1
    ticket.views += 1
    ticket.save()
    # filter comments on specific ticket
    comments = Comment.objects.filter(ticket_id=ticket.pk)
    # filter upvotes on specific ticket by user ID
    upvotes = Upvote.objects.filter(ticket_id=ticket.pk).values("user_id")
    voters = [vote["user_id"] for vote in upvotes]
    donors = User.objects.filter(id__in=voters)
    # render drop-down list for superusers to update status
    ticket_status_list = TicketStatus.objects.all()
    tkt_status = ticket.ticket_status.id
    # POST methods
    if request.method == "POST":
        comment_form = CommentForm(request.POST)
        if comment_form.is_valid():
            comment_form.instance.commenter = request.user
            comment_form.instance.ticket = ticket
            comment_form.save()
            # remove two ticket views to avoid duplicates on POST
            ticket.views -= 2
            ticket.save()
            messages.success(request, f"Comment successfully added!")
            return redirect(tickets_view_one, ticket.pk)
    else:
        comment_form = CommentForm()
        donation_form = DonationForm()
    context = {
        "comment_form": comment_form,
        "comments": comments,
        "donation_form": donation_form,
        "donors": donors,
        "publishable": settings.STRIPE_PUBLISHABLE,
        "ticket": ticket,
        "ticket_status_list": ticket_status_list,
        "tkt_status": tkt_status,
        "voters": voters,
    }
    return render(request, "tickets_view_one.html", context)
Example #9
0
def add_comment(request, id):
    url_name = resolve(request.path_info).url_name

    if request.method == "POST":
        form = CommentForm(request.POST)

        if form.is_valid():
            if url_name == 'comment_bug':
                comment = BugComment()
                comment.bug_id = id
            elif url_name == 'comment_feature':
                comment = FeatureComment()
                comment.feature_id = id

            comment.commenter = auth.get_user(request)
            comment.content = form.cleaned_data['content']
            comment.save()

            messages.success(request, "Thank you for your comment!")

        else:
            messages.error(request, "There was a problem... please try again!")

    return redirect(reverse(url_name.replace('comment', 'show'), args=(id)))
Example #10
0
 def test_comment_is_long_enough(self):
     form = CommentForm({"comment": "test comment"})
     self.assertTrue(form.is_valid())
Example #11
0
 def test_comment_is_not_long_enough(self):
     form = CommentForm({"comment": "test"})
     self.assertFalse(form.is_valid())
Example #12
0
 def post(self, request, *args, **kwargs):
     form = CommentForm(request.POST)
     if form.is_valid():
         self.form_valid(form)
     return super(TicketDetailView, self).get(request, *args, **kwargs)