diff --git a/forms.py b/forms.py index ecd4070a..7b7e686c 100644 --- a/forms.py +++ b/forms.py @@ -47,7 +47,7 @@ class TicketForm(forms.Form): assigned_to = forms.ChoiceField(choices=(), required=False, label=u'Case owner') - def save(self): + def save(self, user): """ Writes and returns a Ticket() object @@ -64,4 +64,16 @@ class TicketForm(forms.Form): t.assigned_to = self.cleaned_data['assigned_to'] t.save() + f = FollowUp( ticket=t, + title='Ticket Opened', + date=datetime.now(), + public=True, + comment=self.cleaned_data['body'], + user=user, + ) + if self.cleaned_data['assigned_to']: + f.title = 'Ticket Opened & Assigned to %s' % self.cleaned_data['assigned_to'] + + f.save() + return t diff --git a/views.py b/views.py index f745d6a8..7528ce0a 100644 --- a/views.py +++ b/views.py @@ -171,7 +171,7 @@ def create_ticket(request): form.fields['queue'].choices = [('', '--------')] + [[q.id, q.title] for q in Queue.objects.all()] form.fields['assigned_to'].choices = [('', '--------')] + [[u.id, u.username] for u in User.objects.filter(is_active=True)] if form.is_valid(): - ticket = form.save() + ticket = form.save(user=request.user) return HttpResponseRedirect(ticket.get_absolute_url()) else: form = TicketForm()