Exemplo n.º 1
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)
Exemplo n.º 2
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.º 3
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.º 4
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)
Exemplo n.º 5
0
 def test_init(self):
     form = TicketCommentCreateForm({})
     self.assertFalse(form.is_valid())
     self.assertEqual(form.errors, {
         'comment': ['This field is required.']
     })