From 8aae8564baef2e1d5f435d09f5e3f9558c66abbf Mon Sep 17 00:00:00 2001 From: Ross Poulton Date: Thu, 10 Jan 2008 00:28:45 +0000 Subject: [PATCH] * Add 'modified' field to tickets - updated when the ticket or a followup is saved * Added 'Priority' ot tickets along with update code. --- models.py | 25 ++++++++++++++++++++++++- scripts/get_email.py | 11 +++++++++++ templates/helpdesk/dashboard.html | 6 +++--- templates/helpdesk/ticket.html | 14 +++++++++++--- views.py | 8 ++++++++ 5 files changed, 57 insertions(+), 7 deletions(-) diff --git a/models.py b/models.py index 45848b8e..9c043dd2 100644 --- a/models.py +++ b/models.py @@ -99,9 +99,18 @@ class Ticket(models.Model): (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) 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.') assigned_to = models.ForeignKey(User, related_name='assigned_to', blank=True, null=True) status = models.IntegerField(choices=STATUS_CHOICES, default=OPEN_STATUS) @@ -109,6 +118,8 @@ class Ticket(models.Model): description = 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): """ 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 @@ -148,6 +159,11 @@ class Ticket(models.Model): if not self.id: # This is a new ticket as no ID yet exists. self.created = datetime.now() + + if not self.priority: + self.priority = 3 + + self.modified = datetime.now() super(Ticket, self).save() @@ -181,6 +197,13 @@ class FollowUp(models.Model): def __unicode__(self): return '%s' % self.title + + def save(self): + t = self.ticket + t.modified = datetime.now() + t.save() + super(FollowUp, self).save() + class TicketChange(models.Model): """ For each FollowUp, any changes to the parent ticket (eg Title, Priority, etc) are tracked here for display purposes. diff --git a/scripts/get_email.py b/scripts/get_email.py index dca1f5ff..7642c2ea 100644 --- a/scripts/get_email.py +++ b/scripts/get_email.py @@ -93,6 +93,16 @@ def ticket_from_message(message, queue): except: 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: t = Ticket( title=subject, @@ -100,6 +110,7 @@ def ticket_from_message(message, queue): submitter_email=sender_email, created=now, description=body, + priority=priority, ) t.save() diff --git a/templates/helpdesk/dashboard.html b/templates/helpdesk/dashboard.html index 6dfeee68..43787db7 100644 --- a/templates/helpdesk/dashboard.html +++ b/templates/helpdesk/dashboard.html @@ -23,11 +23,11 @@ $(document).ready(function() { #TitleQueueStatusLast Update {% for ticket in user_tickets %} -{{ ticket.id }} +{{ ticket.ticket }} {{ ticket.title }} {{ ticket.queue }} {{ ticket.get_status_display }} -{{ ticket.last_update|timesince }} +{{ ticket.modified|timesince }} {% endfor %} @@ -37,7 +37,7 @@ $(document).ready(function() { #TitleQueueCreated  {% for ticket in unassigned_tickets %} -{{ ticket.id }} +{{ ticket.ticket }} {{ ticket.title }} {{ ticket.queue }} {{ ticket.created|timesince }} ago diff --git a/templates/helpdesk/ticket.html b/templates/helpdesk/ticket.html index f7b7cea3..3f453cd6 100644 --- a/templates/helpdesk/ticket.html +++ b/templates/helpdesk/ticket.html @@ -36,16 +36,21 @@ + Priority + {{ ticket.get_priority_display }} + + + Description - + {{ ticket.description }} -{% if ticket.resolution %} +{% if ticket.resolution %} Resolution{% ifequal ticket.get_status_display "Resolved" %} [Accept & Close]{% endifequal %} - + {{ ticket.resolution }} {% endif %} @@ -102,6 +107,9 @@ Changed {{ change.field }} from {{ change.old_value }} to {{ change.new_value }} + + + diff --git a/views.py b/views.py index a89f1ab3..0287c9a0 100644 --- a/views.py +++ b/views.py @@ -80,6 +80,7 @@ def view_ticket(request, ticket_id): RequestContext(request, { 'ticket': ticket, 'active_users': User.objects.filter(is_active=True), + 'priorities': Ticket.PRIORITY_CHOICES, })) view_ticket = login_required(view_ticket) @@ -91,6 +92,8 @@ def update_ticket(request, ticket_id): title = request.POST.get('title', '') public = request.POST.get('public', False) owner = int(request.POST.get('owner', None)) + priority = int(request.POST.get('priority', ticket.priority)) + if not owner and ticket.assigned_to: owner = ticket.assigned_to.id @@ -129,6 +132,11 @@ def update_ticket(request, ticket_id): c.save() 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: ticket.resolution = comment