Exemplo n.º 1
0
class MyTicketDetailView(DetailView):
    model = Ticket
    template_name = 'tickets/ticket_mydetail.html'
    form = TicketCommentCreateForm()

    def get_context_data(self, **kwargs):
        context = super(MyTicketDetailView, self).get_context_data(**kwargs)
        context['form'] = self.form
        return context

    def post(self, request, *args, **kwargs):
        self.form = TicketCommentCreateForm(request.POST)
        if self.form.is_valid():
            self.form_valid(self.form)
            return HttpResponseRedirect(reverse('tickets:detail', args=[self.kwargs['pk']]))
        return super(MyTicketDetailView, self).get(request, *args, **kwargs)

    def form_valid(self, form):
        comment = form.instance
        comment.author = self.request.user
        comment.ticket = Ticket.objects.get(id=self.kwargs['pk'])
        comment.save()
        messages.success(self.request, _(u"Your comment has been successfully added to the ticket."))

    def get_queryset(self):
        return Ticket.objects.filter(creator=self.request.user)
Exemplo n.º 2
0
 def post(self, request, *args, **kwargs):
     self.form = TicketCommentCreateForm(request.POST)
     if self.form.is_valid():
         self.form_valid(self.form)
         return HttpResponseRedirect(reverse('tickets:detail', args=[self.kwargs['pk']]))
     return super(MyTicketDetailView, self).get(request, *args, **kwargs)