* Add 'modified' field to tickets - updated when the ticket or a followup is saved

* Added 'Priority' ot tickets along with update code.
This commit is contained in:
Ross Poulton 2008-01-10 00:28:45 +00:00
parent 5052d40876
commit 8aae8564ba
5 changed files with 57 additions and 7 deletions

View File

@ -99,9 +99,18 @@ class Ticket(models.Model):
(CLOSED_STATUS, 'Closed'), (CLOSED_STATUS, 'Closed'),
) )
PRIORITY_CHOICES = (
(1, '1 (Critical)'),
(2, '2 (High)'),
(3, '3 (Normal)'),
(4, '4 (Low)'),
(5, '5 (Very Low)'),
)
title = models.CharField(maxlength=200) title = models.CharField(maxlength=200)
queue = models.ForeignKey(Queue) queue = models.ForeignKey(Queue)
created = models.DateTimeField(auto_now_add=True) created = models.DateTimeField(blank=True)
modified = models.DateTimeField(blank=True)
submitter_email = models.EmailField(blank=True, null=True, help_text='The submitter will receive an email for all public follow-ups left for this task.') submitter_email = models.EmailField(blank=True, null=True, help_text='The submitter will receive an email for all public follow-ups left for this task.')
assigned_to = models.ForeignKey(User, related_name='assigned_to', blank=True, null=True) assigned_to = models.ForeignKey(User, related_name='assigned_to', blank=True, null=True)
status = models.IntegerField(choices=STATUS_CHOICES, default=OPEN_STATUS) status = models.IntegerField(choices=STATUS_CHOICES, default=OPEN_STATUS)
@ -109,6 +118,8 @@ class Ticket(models.Model):
description = models.TextField(blank=True, null=True) description = models.TextField(blank=True, null=True)
resolution = models.TextField(blank=True, null=True) resolution = models.TextField(blank=True, null=True)
priority = models.IntegerField(choices=PRIORITY_CHOICES, default=3, blank=3)
def _get_assigned_to(self): def _get_assigned_to(self):
""" Custom property to allow us to easily print 'Unassigned' if a """ Custom property to allow us to easily print 'Unassigned' if a
ticket has no owner, or the users name if it's assigned. If the user ticket has no owner, or the users name if it's assigned. If the user
@ -148,6 +159,11 @@ class Ticket(models.Model):
if not self.id: if not self.id:
# This is a new ticket as no ID yet exists. # This is a new ticket as no ID yet exists.
self.created = datetime.now() self.created = datetime.now()
if not self.priority:
self.priority = 3
self.modified = datetime.now()
super(Ticket, self).save() super(Ticket, self).save()
@ -181,6 +197,13 @@ class FollowUp(models.Model):
def __unicode__(self): def __unicode__(self):
return '%s' % self.title return '%s' % self.title
def save(self):
t = self.ticket
t.modified = datetime.now()
t.save()
super(FollowUp, self).save()
class TicketChange(models.Model): class TicketChange(models.Model):
""" For each FollowUp, any changes to the parent ticket (eg Title, Priority, """ For each FollowUp, any changes to the parent ticket (eg Title, Priority,
etc) are tracked here for display purposes. etc) are tracked here for display purposes.

View File

@ -93,6 +93,16 @@ def ticket_from_message(message, queue):
except: except:
ticket = None ticket = None
priority = 3
smtp_priority = message.get('priority', '')
smtp_importance = message.get('importance', '')
high_priority_types = ('high', 'important', '1', 'urgent')
if smtp_priority in high_priority_types or smtp_importance in high_priority_types:
priority = 2
if ticket == None: if ticket == None:
t = Ticket( t = Ticket(
title=subject, title=subject,
@ -100,6 +110,7 @@ def ticket_from_message(message, queue):
submitter_email=sender_email, submitter_email=sender_email,
created=now, created=now,
description=body, description=body,
priority=priority,
) )
t.save() t.save()

View File

@ -23,11 +23,11 @@ $(document).ready(function() {
<tr class='row_columnheads'><th>#</th><th>Title</th><th>Queue</th><th>Status</th><th>Last Update</th></tr> <tr class='row_columnheads'><th>#</th><th>Title</th><th>Queue</th><th>Status</th><th>Last Update</th></tr>
{% for ticket in user_tickets %} {% for ticket in user_tickets %}
<tr class='row_{% cycle odd,even %} row_hover'> <tr class='row_{% cycle odd,even %} row_hover'>
<th><a href='{{ ticket.get_absolute_url }}'>{{ ticket.id }}</a></th> <th><a href='{{ ticket.get_absolute_url }}'>{{ ticket.ticket }}</a></th>
<th><a href='{{ ticket.get_absolute_url }}'>{{ ticket.title }}</a></th> <th><a href='{{ ticket.get_absolute_url }}'>{{ ticket.title }}</a></th>
<td>{{ ticket.queue }}</td> <td>{{ ticket.queue }}</td>
<td>{{ ticket.get_status_display }}</td> <td>{{ ticket.get_status_display }}</td>
<td>{{ ticket.last_update|timesince }}</td> <td><span title='{{ ticket.modified|date:"r" }}'>{{ ticket.modified|timesince }}</span></td>
</tr> </tr>
{% endfor %} {% endfor %}
</table> </table>
@ -37,7 +37,7 @@ $(document).ready(function() {
<tr class='row_columnheads'><th>#</th><th>Title</th><th>Queue</th><th>Created</th><th>&nbsp;</th></tr> <tr class='row_columnheads'><th>#</th><th>Title</th><th>Queue</th><th>Created</th><th>&nbsp;</th></tr>
{% for ticket in unassigned_tickets %} {% for ticket in unassigned_tickets %}
<tr class='row_{% cycle odd,even %} row_hover'> <tr class='row_{% cycle odd,even %} row_hover'>
<th><a href='{{ ticket.get_absolute_url }}'>{{ ticket.id }}</a></th> <th><a href='{{ ticket.get_absolute_url }}'>{{ ticket.ticket }}</a></th>
<th><a href='{{ ticket.get_absolute_url }}'>{{ ticket.title }}</a></th> <th><a href='{{ ticket.get_absolute_url }}'>{{ ticket.title }}</a></th>
<td>{{ ticket.queue }}</td> <td>{{ ticket.queue }}</td>
<td><span title='{{ ticket.created|date:"r" }}'>{{ ticket.created|timesince }} ago</span></td> <td><span title='{{ ticket.created|date:"r" }}'>{{ ticket.created|timesince }} ago</span></td>

View File

@ -36,16 +36,21 @@
</tr> </tr>
<tr class='row_even'> <tr class='row_even'>
<th>Priority</th>
<td>{{ ticket.get_priority_display }}</td>
</tr>
<tr class='row_odd'>
<th colspan='2'>Description</th> <th colspan='2'>Description</th>
</tr> </tr>
<tr class='row_odd'> <tr class='row_even'>
<td colspan='2'>{{ ticket.description }}</td> <td colspan='2'>{{ ticket.description }}</td>
</tr> </tr>
{% if ticket.resolution %}<tr class='row_even'> {% if ticket.resolution %}<tr class='row_odd'>
<th colspan='2'>Resolution{% ifequal ticket.get_status_display "Resolved" %} [<a href='?close'>Accept &amp; Close</a>]{% endifequal %}</th> <th colspan='2'>Resolution{% ifequal ticket.get_status_display "Resolved" %} [<a href='?close'>Accept &amp; Close</a>]{% endifequal %}</th>
</tr> </tr>
<tr class='row_odd'> <tr class='row_even'>
<td colspan='2'>{{ ticket.resolution }}</td> <td colspan='2'>{{ ticket.resolution }}</td>
</tr>{% endif %} </tr>{% endif %}
@ -102,6 +107,9 @@ Changed {{ change.field }} from {{ change.old_value }} to {{ change.new_value }}
<label for='id_owner'>Owner</label> <label for='id_owner'>Owner</label>
<select id='id_owner' name='owner'><option value='0'>Unassign</option>{% for u in active_users %}<option value='{{ u.id }}' {% ifequal u.id ticket.assigned_to.id %}selected{% endifequal %}>{{ u }}</option>{% endfor %}</select> <select id='id_owner' name='owner'><option value='0'>Unassign</option>{% for u in active_users %}<option value='{{ u.id }}' {% ifequal u.id ticket.assigned_to.id %}selected{% endifequal %}>{{ u }}</option>{% endfor %}</select>
<label for='id_priority'>Priority</label>
<select id='id_priority' name='priority'>{% for p in priorities %}<option value='{{ p.0 }}'{% ifequal p.0 ticket.priority %} selected='selected'{% endifequal %}>{{ p.1 }}</option>{% endfor %}</select>
</div> </div>
<label for='id_public'>Is this update public?</label> <input type='checkbox' name='public' value='1' checked='checked' /> <label for='id_public'>Is this update public?</label> <input type='checkbox' name='public' value='1' checked='checked' />

View File

@ -80,6 +80,7 @@ def view_ticket(request, ticket_id):
RequestContext(request, { RequestContext(request, {
'ticket': ticket, 'ticket': ticket,
'active_users': User.objects.filter(is_active=True), 'active_users': User.objects.filter(is_active=True),
'priorities': Ticket.PRIORITY_CHOICES,
})) }))
view_ticket = login_required(view_ticket) view_ticket = login_required(view_ticket)
@ -91,6 +92,8 @@ def update_ticket(request, ticket_id):
title = request.POST.get('title', '') title = request.POST.get('title', '')
public = request.POST.get('public', False) public = request.POST.get('public', False)
owner = int(request.POST.get('owner', None)) owner = int(request.POST.get('owner', None))
priority = int(request.POST.get('priority', ticket.priority))
if not owner and ticket.assigned_to: if not owner and ticket.assigned_to:
owner = ticket.assigned_to.id owner = ticket.assigned_to.id
@ -129,6 +132,11 @@ def update_ticket(request, ticket_id):
c.save() c.save()
ticket.title = title ticket.title = title
if priority != ticket.priority:
c = TicketChange(followup=f, field='Priority', old_value=ticket.priority, new_value=priority)
c.save()
ticket.priority = priority
if f.new_status == Ticket.RESOLVED_STATUS: if f.new_status == Ticket.RESOLVED_STATUS:
ticket.resolution = comment ticket.resolution = comment