2007-12-27 01:29:17 +01:00
|
|
|
""" ..
|
2008-02-06 05:36:07 +01:00
|
|
|
Jutda Helpdesk - A Django powered ticket tracker for small enterprise.
|
2007-12-27 01:29:17 +01:00
|
|
|
|
2008-02-06 05:36:07 +01:00
|
|
|
(c) Copyright 2008 Jutda. All Rights Reserved. See LICENSE for details.
|
2007-12-27 01:29:17 +01:00
|
|
|
|
2008-02-06 05:36:07 +01:00
|
|
|
forms.py - Definitions of newforms-based forms for creating and maintaining
|
|
|
|
tickets.
|
2007-12-27 01:29:17 +01:00
|
|
|
"""
|
|
|
|
|
2008-08-12 01:24:18 +02:00
|
|
|
from django import forms
|
2007-12-28 04:33:33 +01:00
|
|
|
from helpdesk.models import Ticket, Queue, FollowUp
|
2007-12-28 04:38:39 +01:00
|
|
|
from django.contrib.auth.models import User
|
2007-12-27 01:29:17 +01:00
|
|
|
from datetime import datetime
|
2008-05-07 11:04:18 +02:00
|
|
|
from django.utils.translation import ugettext as _
|
2007-12-27 01:29:17 +01:00
|
|
|
|
|
|
|
class TicketForm(forms.Form):
|
2008-05-07 11:04:18 +02:00
|
|
|
queue = forms.ChoiceField(label=_('Queue'), required=True, choices=())
|
2007-12-27 01:29:17 +01:00
|
|
|
|
|
|
|
title = forms.CharField(max_length=100, required=True,
|
|
|
|
widget=forms.TextInput(),
|
2008-05-07 11:04:18 +02:00
|
|
|
label=_('Summary of the problem'))
|
2007-12-27 01:29:17 +01:00
|
|
|
|
|
|
|
submitter_email = forms.EmailField(required=False,
|
2008-05-07 11:04:18 +02:00
|
|
|
label=_('Submitter E-Mail Address'),
|
|
|
|
help_text=_('This e-mail address will receive copies of all public updates to this ticket.'))
|
2007-12-27 01:29:17 +01:00
|
|
|
|
|
|
|
body = forms.CharField(widget=forms.Textarea(),
|
2008-05-07 11:04:18 +02:00
|
|
|
label=_('Description of Issue'), required=True)
|
2007-12-27 01:29:17 +01:00
|
|
|
|
|
|
|
assigned_to = forms.ChoiceField(choices=(), required=False,
|
2008-05-07 11:04:18 +02:00
|
|
|
label=_('Case owner'),
|
|
|
|
help_text=_('If you select an owner other than yourself, they\'ll be e-mailed details of this ticket immediately.'))
|
2008-01-10 06:06:47 +01:00
|
|
|
|
|
|
|
priority = forms.ChoiceField(choices=Ticket.PRIORITY_CHOICES,
|
|
|
|
required=False,
|
|
|
|
initial='3',
|
2008-05-07 11:04:18 +02:00
|
|
|
label=_('Priority'),
|
|
|
|
help_text=_('Please select a priority carefully. If unsure, leave it as \'3\'.'))
|
2007-12-27 01:29:17 +01:00
|
|
|
|
2007-12-28 04:29:45 +01:00
|
|
|
def save(self, user):
|
2007-12-27 01:29:17 +01:00
|
|
|
"""
|
|
|
|
Writes and returns a Ticket() object
|
|
|
|
|
|
|
|
"""
|
|
|
|
q = Queue.objects.get(id=int(self.cleaned_data['queue']))
|
2008-01-15 00:39:43 +01:00
|
|
|
|
|
|
|
t = Ticket( title = self.cleaned_data['title'],
|
|
|
|
submitter_email = self.cleaned_data['submitter_email'],
|
|
|
|
created = datetime.now(),
|
2007-12-27 01:29:17 +01:00
|
|
|
status = Ticket.OPEN_STATUS,
|
|
|
|
queue = q,
|
|
|
|
description = self.cleaned_data['body'],
|
2008-01-10 06:06:47 +01:00
|
|
|
priority = self.cleaned_data['priority'],
|
2007-12-27 01:29:17 +01:00
|
|
|
)
|
2008-01-15 00:39:43 +01:00
|
|
|
|
2007-12-27 01:29:17 +01:00
|
|
|
if self.cleaned_data['assigned_to']:
|
2007-12-28 04:38:39 +01:00
|
|
|
try:
|
|
|
|
u = User.objects.get(id=self.cleaned_data['assigned_to'])
|
|
|
|
t.assigned_to = u
|
|
|
|
except:
|
|
|
|
t.assigned_to = None
|
2007-12-27 01:29:17 +01:00
|
|
|
t.save()
|
|
|
|
|
2008-01-15 00:39:43 +01:00
|
|
|
f = FollowUp( ticket = t,
|
2008-05-07 11:04:18 +02:00
|
|
|
title = _('Ticket Opened'),
|
2008-01-15 00:39:43 +01:00
|
|
|
date = datetime.now(),
|
|
|
|
public = True,
|
|
|
|
comment = self.cleaned_data['body'],
|
|
|
|
user = user,
|
2007-12-28 04:29:45 +01:00
|
|
|
)
|
|
|
|
if self.cleaned_data['assigned_to']:
|
2008-05-07 11:04:18 +02:00
|
|
|
f.title = _('Ticket Opened & Assigned to %(name)s') % {'name': t.get_assigned_to}
|
2007-12-28 04:29:45 +01:00
|
|
|
|
|
|
|
f.save()
|
2008-01-15 00:39:43 +01:00
|
|
|
|
|
|
|
context = {
|
|
|
|
'ticket': t,
|
|
|
|
'queue': q,
|
|
|
|
}
|
|
|
|
|
2008-04-02 01:26:12 +02:00
|
|
|
from helpdesk.lib import send_templated_mail
|
2008-01-21 02:02:12 +01:00
|
|
|
|
2008-01-15 00:39:43 +01:00
|
|
|
if t.submitter_email:
|
2008-04-02 01:26:12 +02:00
|
|
|
send_templated_mail('newticket_submitter', context, recipients=t.submitter_email, sender=q.from_address, fail_silently=True)
|
2007-12-28 04:29:45 +01:00
|
|
|
|
2008-02-06 00:35:40 +01:00
|
|
|
if t.assigned_to and t.assigned_to != user:
|
2008-04-02 01:26:12 +02:00
|
|
|
send_templated_mail('assigned_owner', context, recipients=t.assigned_to.email, sender=q.from_address, fail_silently=True)
|
2008-01-21 02:02:12 +01:00
|
|
|
|
|
|
|
if q.new_ticket_cc:
|
2008-04-02 01:26:12 +02:00
|
|
|
send_templated_mail('newticket_cc', context, recipients=q.new_ticket_cc, sender=q.from_address, fail_silently=True)
|
2008-02-06 00:35:40 +01:00
|
|
|
|
|
|
|
if q.updated_ticket_cc and q.updated_ticket_cc != q.new_ticket_cc:
|
2008-04-02 01:26:12 +02:00
|
|
|
send_templated_mail('newticket_cc', context, recipients=q.updated_ticket_cc, sender=q.from_address, fail_silently=True)
|
2008-01-21 02:02:12 +01:00
|
|
|
|
2007-12-27 01:29:17 +01:00
|
|
|
return t
|
2008-01-16 01:26:24 +01:00
|
|
|
|
|
|
|
class PublicTicketForm(forms.Form):
|
2008-05-07 11:04:18 +02:00
|
|
|
queue = forms.ChoiceField(label=_('Queue'), required=True, choices=())
|
2008-01-16 01:26:24 +01:00
|
|
|
|
|
|
|
title = forms.CharField(max_length=100, required=True,
|
|
|
|
widget=forms.TextInput(),
|
2008-05-07 11:04:18 +02:00
|
|
|
label=_('Summary of your query'))
|
2008-01-16 01:26:24 +01:00
|
|
|
|
|
|
|
submitter_email = forms.EmailField(required=True,
|
2008-05-07 11:04:18 +02:00
|
|
|
label=_('Your E-Mail Address'),
|
|
|
|
help_text=_('We will e-mail you when your ticket is updated.'))
|
2008-01-16 01:26:24 +01:00
|
|
|
|
|
|
|
body = forms.CharField(widget=forms.Textarea(),
|
2008-05-07 11:04:18 +02:00
|
|
|
label=_('Description of your issue'), required=True,
|
|
|
|
help_text=_('Please be as descriptive as possible, including any details we may need to address your query.'))
|
2008-01-16 01:26:24 +01:00
|
|
|
|
|
|
|
priority = forms.ChoiceField(choices=Ticket.PRIORITY_CHOICES,
|
|
|
|
required=True,
|
|
|
|
initial='3',
|
2008-05-07 11:04:18 +02:00
|
|
|
label=_('Urgency'),
|
|
|
|
help_text=_('Please select a priority carefully.'))
|
2008-01-16 01:26:24 +01:00
|
|
|
|
|
|
|
def save(self):
|
|
|
|
"""
|
|
|
|
Writes and returns a Ticket() object
|
|
|
|
|
|
|
|
"""
|
|
|
|
q = Queue.objects.get(id=int(self.cleaned_data['queue']))
|
|
|
|
|
|
|
|
t = Ticket( title = self.cleaned_data['title'],
|
|
|
|
submitter_email = self.cleaned_data['submitter_email'],
|
|
|
|
created = datetime.now(),
|
|
|
|
status = Ticket.OPEN_STATUS,
|
|
|
|
queue = q,
|
|
|
|
description = self.cleaned_data['body'],
|
|
|
|
priority = self.cleaned_data['priority'],
|
|
|
|
)
|
|
|
|
|
|
|
|
t.save()
|
|
|
|
|
|
|
|
f = FollowUp( ticket = t,
|
2008-05-07 11:04:18 +02:00
|
|
|
title = _('Ticket Opened Via Web'),
|
2008-01-16 01:26:24 +01:00
|
|
|
date = datetime.now(),
|
|
|
|
public = True,
|
|
|
|
comment = self.cleaned_data['body'],
|
|
|
|
)
|
|
|
|
|
|
|
|
f.save()
|
|
|
|
|
|
|
|
context = {
|
|
|
|
'ticket': t,
|
|
|
|
'queue': q,
|
|
|
|
}
|
|
|
|
|
2008-04-02 01:26:12 +02:00
|
|
|
from helpdesk.lib import send_templated_mail
|
|
|
|
send_templated_mail('newticket_submitter', context, recipients=t.submitter_email, sender=q.from_address, fail_silently=True)
|
2008-01-16 01:26:24 +01:00
|
|
|
|
2008-01-21 02:02:12 +01:00
|
|
|
if q.new_ticket_cc:
|
2008-04-02 01:26:12 +02:00
|
|
|
send_templated_mail('newticket_cc', context, recipients=q.new_ticket_cc, sender=q.from_address, fail_silently=True)
|
2008-02-06 00:35:40 +01:00
|
|
|
|
|
|
|
if q.updated_ticket_cc and q.updated_ticket_cc != q.new_ticket_cc:
|
2008-04-02 01:26:12 +02:00
|
|
|
send_templated_mail('newticket_cc', context, recipients=q.updated_ticket_cc, sender=q.from_address, fail_silently=True)
|
2008-01-21 02:02:12 +01:00
|
|
|
|
2008-01-16 01:26:24 +01:00
|
|
|
return t
|