2008-02-06 05:36:07 +01:00
|
|
|
"""
|
2011-01-26 00:08:41 +01:00
|
|
|
django-helpdesk - A Django powered ticket tracker for small enterprise.
|
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
|
|
|
models.py - Model (and hence database) definitions. This is the core of the
|
|
|
|
helpdesk structure.
|
2007-12-27 01:29:17 +01:00
|
|
|
"""
|
2008-02-06 05:36:07 +01:00
|
|
|
|
2007-12-27 01:29:17 +01:00
|
|
|
from datetime import datetime
|
2008-01-15 01:20:00 +01:00
|
|
|
|
2007-12-27 01:29:17 +01:00
|
|
|
from django.contrib.auth.models import User
|
2008-01-15 01:20:00 +01:00
|
|
|
from django.db import models
|
|
|
|
from django.conf import settings
|
2009-10-13 12:28:42 +02:00
|
|
|
from django.utils.translation import ugettext_lazy as _, ugettext
|
2009-09-09 11:11:05 +02:00
|
|
|
from helpdesk.settings import HAS_TAG_SUPPORT
|
2007-12-27 01:29:17 +01:00
|
|
|
|
2009-09-09 11:11:05 +02:00
|
|
|
if HAS_TAG_SUPPORT:
|
|
|
|
from tagging.fields import TagField
|
2008-08-19 10:50:38 +02:00
|
|
|
|
2007-12-27 01:29:17 +01:00
|
|
|
class Queue(models.Model):
|
2007-12-27 02:35:34 +01:00
|
|
|
"""
|
2008-08-19 10:50:38 +02:00
|
|
|
A queue is a collection of tickets into what would generally be business
|
2007-12-27 02:35:34 +01:00
|
|
|
areas or departments.
|
|
|
|
|
2008-08-19 10:50:38 +02:00
|
|
|
For example, a company may have a queue for each Product they provide, or
|
2007-12-27 02:35:34 +01:00
|
|
|
a queue for each of Accounts, Pre-Sales, and Support.
|
|
|
|
|
|
|
|
"""
|
2008-08-19 10:50:38 +02:00
|
|
|
|
|
|
|
title = models.CharField(
|
|
|
|
_('Title'),
|
|
|
|
max_length=100,
|
|
|
|
)
|
|
|
|
|
|
|
|
slug = models.SlugField(
|
|
|
|
_('Slug'),
|
|
|
|
help_text=_('This slug is used when building ticket ID\'s. Once set, '
|
|
|
|
'try not to change it or e-mailing may get messy.'),
|
|
|
|
)
|
|
|
|
|
|
|
|
email_address = models.EmailField(
|
|
|
|
_('E-Mail Address'),
|
|
|
|
blank=True,
|
|
|
|
null=True,
|
|
|
|
help_text=_('All outgoing e-mails for this queue will use this e-mail '
|
|
|
|
'address. If you use IMAP or POP3, this should be the e-mail '
|
|
|
|
'address for that mailbox.'),
|
2008-11-18 02:43:50 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
locale = models.CharField(
|
|
|
|
_('Locale'),
|
|
|
|
max_length=10,
|
|
|
|
blank=True,
|
|
|
|
null=True,
|
|
|
|
help_text=_('Locale of this queue. All correspondence in this queue will be in this language.'),
|
2008-08-19 10:50:38 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
allow_public_submission = models.BooleanField(
|
|
|
|
_('Allow Public Submission?'),
|
|
|
|
blank=True,
|
2009-05-24 07:26:12 +02:00
|
|
|
default=False,
|
2008-08-19 10:50:38 +02:00
|
|
|
help_text=_('Should this queue be listed on the public submission '
|
|
|
|
'form?'),
|
|
|
|
)
|
|
|
|
|
|
|
|
allow_email_submission = models.BooleanField(
|
|
|
|
_('Allow E-Mail Submission?'),
|
|
|
|
blank=True,
|
2009-05-24 07:26:12 +02:00
|
|
|
default=False,
|
2008-08-19 10:50:38 +02:00
|
|
|
help_text=_('Do you want to poll the e-mail box below for new '
|
|
|
|
'tickets?'),
|
|
|
|
)
|
|
|
|
|
|
|
|
escalate_days = models.IntegerField(
|
|
|
|
_('Escalation Days'),
|
|
|
|
blank=True,
|
|
|
|
null=True,
|
|
|
|
help_text=_('For tickets which are not held, how often do you wish to '
|
|
|
|
'increase their priority? Set to 0 for no escalation.'),
|
|
|
|
)
|
|
|
|
|
|
|
|
new_ticket_cc = models.EmailField(
|
|
|
|
_('New Ticket CC Address'),
|
|
|
|
blank=True,
|
|
|
|
null=True,
|
|
|
|
help_text=_('If an e-mail address is entered here, then it will '
|
|
|
|
'receive notification of all new tickets created for this queue'),
|
|
|
|
)
|
|
|
|
|
|
|
|
updated_ticket_cc = models.EmailField(
|
|
|
|
_('Updated Ticket CC Address'),
|
|
|
|
blank=True,
|
|
|
|
null=True,
|
|
|
|
help_text=_('If an e-mail address is entered here, then it will '
|
|
|
|
'receive notification of all activity (new tickets, closed '
|
|
|
|
'tickets, updates, reassignments, etc) for this queue'),
|
|
|
|
)
|
|
|
|
|
|
|
|
email_box_type = models.CharField(
|
|
|
|
_('E-Mail Box Type'),
|
|
|
|
max_length=5,
|
|
|
|
choices=(('pop3', _('POP 3')), ('imap', _('IMAP'))),
|
|
|
|
blank=True,
|
|
|
|
null=True,
|
|
|
|
help_text=_('E-Mail server type for creating tickets automatically '
|
|
|
|
'from a mailbox - both POP3 and IMAP are supported.'),
|
|
|
|
)
|
|
|
|
|
|
|
|
email_box_host = models.CharField(
|
|
|
|
_('E-Mail Hostname'),
|
|
|
|
max_length=200,
|
|
|
|
blank=True,
|
|
|
|
null=True,
|
|
|
|
help_text=_('Your e-mail server address - either the domain name or '
|
|
|
|
'IP address. May be "localhost".'),
|
|
|
|
)
|
|
|
|
|
|
|
|
email_box_port = models.IntegerField(
|
|
|
|
_('E-Mail Port'),
|
|
|
|
blank=True,
|
|
|
|
null=True,
|
|
|
|
help_text=_('Port number to use for accessing e-mail. Default for '
|
|
|
|
'POP3 is "110", and for IMAP is "143". This may differ on some '
|
|
|
|
'servers. Leave it blank to use the defaults.'),
|
|
|
|
)
|
|
|
|
|
2008-08-20 03:57:41 +02:00
|
|
|
email_box_ssl = models.BooleanField(
|
|
|
|
_('Use SSL for E-Mail?'),
|
|
|
|
blank=True,
|
2009-05-24 07:26:12 +02:00
|
|
|
default=False,
|
2008-08-20 03:57:41 +02:00
|
|
|
help_text=_('Whether to use SSL for IMAP or POP3 - the default ports '
|
|
|
|
'when using SSL are 993 for IMAP and 995 for POP3.'),
|
|
|
|
)
|
2009-09-09 10:47:48 +02:00
|
|
|
|
2008-08-19 10:50:38 +02:00
|
|
|
email_box_user = models.CharField(
|
|
|
|
_('E-Mail Username'),
|
|
|
|
max_length=200,
|
|
|
|
blank=True,
|
|
|
|
null=True,
|
|
|
|
help_text=_('Username for accessing this mailbox.'),
|
|
|
|
)
|
|
|
|
|
|
|
|
email_box_pass = models.CharField(
|
|
|
|
_('E-Mail Password'),
|
|
|
|
max_length=200,
|
|
|
|
blank=True,
|
|
|
|
null=True,
|
|
|
|
help_text=_('Password for the above username'),
|
|
|
|
)
|
|
|
|
|
|
|
|
email_box_imap_folder = models.CharField(
|
|
|
|
_('IMAP Folder'),
|
|
|
|
max_length=100,
|
|
|
|
blank=True,
|
|
|
|
null=True,
|
|
|
|
help_text=_('If using IMAP, what folder do you wish to fetch messages '
|
|
|
|
'from? This allows you to use one IMAP account for multiple '
|
|
|
|
'queues, by filtering messages on your IMAP server into separate '
|
|
|
|
'folders. Default: INBOX.'),
|
|
|
|
)
|
|
|
|
|
|
|
|
email_box_interval = models.IntegerField(
|
|
|
|
_('E-Mail Check Interval'),
|
|
|
|
help_text=_('How often do you wish to check this mailbox? (in Minutes)'),
|
|
|
|
blank=True,
|
|
|
|
null=True,
|
|
|
|
default='5',
|
|
|
|
)
|
|
|
|
|
|
|
|
email_box_last_check = models.DateTimeField(
|
|
|
|
blank=True,
|
|
|
|
null=True,
|
|
|
|
editable=False,
|
|
|
|
# This is updated by management/commands/get_mail.py.
|
|
|
|
)
|
|
|
|
|
|
|
|
def __unicode__(self):
|
|
|
|
return u"%s" % self.title
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
ordering = ('title',)
|
2007-12-27 01:29:17 +01:00
|
|
|
|
2008-01-07 21:22:13 +01:00
|
|
|
def _from_address(self):
|
2008-08-19 10:50:38 +02:00
|
|
|
"""
|
|
|
|
Short property to provide a sender address in SMTP format,
|
|
|
|
eg 'Name <email>'. We do this so we can put a simple error message
|
|
|
|
in the sender name field, so hopefully the admin can see and fix it.
|
|
|
|
"""
|
2008-01-15 01:20:00 +01:00
|
|
|
if not self.email_address:
|
2008-05-07 11:04:18 +02:00
|
|
|
return u'NO QUEUE EMAIL ADDRESS DEFINED <%s>' % settings.DEFAULT_FROM_EMAIL
|
2008-01-15 01:20:00 +01:00
|
|
|
else:
|
2008-05-07 11:04:18 +02:00
|
|
|
return u'%s <%s>' % (self.title, self.email_address)
|
2008-01-07 21:22:13 +01:00
|
|
|
from_address = property(_from_address)
|
|
|
|
|
2008-09-09 10:32:01 +02:00
|
|
|
def save(self, force_insert=False, force_update=False):
|
2008-01-07 21:22:13 +01:00
|
|
|
if self.email_box_type == 'imap' and not self.email_box_imap_folder:
|
|
|
|
self.email_box_imap_folder = 'INBOX'
|
2008-08-19 10:50:38 +02:00
|
|
|
|
|
|
|
if not self.email_box_port:
|
2008-08-20 03:57:41 +02:00
|
|
|
if self.email_box_type == 'imap' and self.email_box_ssl:
|
|
|
|
self.email_box_port = 993
|
|
|
|
elif self.email_box_type == 'imap' and not self.email_box_ssl:
|
2008-08-19 10:50:38 +02:00
|
|
|
self.email_box_port = 143
|
2008-08-20 03:57:41 +02:00
|
|
|
elif self.email_box_type == 'pop3' and self.email_box_ssl:
|
|
|
|
self.email_box_port = 995
|
|
|
|
elif self.email_box_type == 'pop3' and not self.email_box_ssl:
|
2008-08-19 10:50:38 +02:00
|
|
|
self.email_box_port = 110
|
2008-09-09 10:32:01 +02:00
|
|
|
super(Queue, self).save(force_insert, force_update)
|
2007-12-27 01:29:17 +01:00
|
|
|
|
2008-01-15 01:20:00 +01:00
|
|
|
|
2007-12-27 01:29:17 +01:00
|
|
|
class Ticket(models.Model):
|
|
|
|
"""
|
2008-08-19 10:50:38 +02:00
|
|
|
To allow a ticket to be entered as quickly as possible, only the
|
|
|
|
bare minimum fields are required. These basically allow us to
|
|
|
|
sort and manage the ticket. The user can always go back and
|
2007-12-27 01:29:17 +01:00
|
|
|
enter more information later.
|
|
|
|
|
2008-08-19 10:50:38 +02:00
|
|
|
A good example of this is when a customer is on the phone, and
|
2007-12-27 01:29:17 +01:00
|
|
|
you want to give them a ticket ID as quickly as possible. You can
|
2008-08-19 10:50:38 +02:00
|
|
|
enter some basic info, save the ticket, give the customer the ID
|
2007-12-27 01:29:17 +01:00
|
|
|
and get off the phone, then add in further detail at a later time
|
|
|
|
(once the customer is not on the line).
|
2007-12-27 02:35:34 +01:00
|
|
|
|
2008-08-19 10:50:38 +02:00
|
|
|
Note that assigned_to is optional - unassigned tickets are displayed on
|
2007-12-27 02:35:34 +01:00
|
|
|
the dashboard to prompt users to take ownership of them.
|
2007-12-27 01:29:17 +01:00
|
|
|
"""
|
|
|
|
|
|
|
|
OPEN_STATUS = 1
|
|
|
|
REOPENED_STATUS = 2
|
|
|
|
RESOLVED_STATUS = 3
|
|
|
|
CLOSED_STATUS = 4
|
2008-08-19 10:50:38 +02:00
|
|
|
|
2007-12-27 01:29:17 +01:00
|
|
|
STATUS_CHOICES = (
|
2008-05-07 11:04:18 +02:00
|
|
|
(OPEN_STATUS, _('Open')),
|
|
|
|
(REOPENED_STATUS, _('Reopened')),
|
|
|
|
(RESOLVED_STATUS, _('Resolved')),
|
|
|
|
(CLOSED_STATUS, _('Closed')),
|
2007-12-27 01:29:17 +01:00
|
|
|
)
|
|
|
|
|
2008-01-10 01:28:45 +01:00
|
|
|
PRIORITY_CHOICES = (
|
2008-05-07 11:04:18 +02:00
|
|
|
(1, _('1. Critical')),
|
|
|
|
(2, _('2. High')),
|
|
|
|
(3, _('3. Normal')),
|
|
|
|
(4, _('4. Low')),
|
|
|
|
(5, _('5. Very Low')),
|
2008-01-10 01:28:45 +01:00
|
|
|
)
|
|
|
|
|
2008-08-19 10:50:38 +02:00
|
|
|
title = models.CharField(
|
|
|
|
_('Title'),
|
|
|
|
max_length=200,
|
|
|
|
)
|
2008-01-16 05:52:30 +01:00
|
|
|
|
2008-08-19 10:50:38 +02:00
|
|
|
queue = models.ForeignKey(Queue)
|
2007-12-27 01:29:17 +01:00
|
|
|
|
2008-08-19 10:50:38 +02:00
|
|
|
created = models.DateTimeField(
|
|
|
|
_('Created'),
|
|
|
|
blank=True,
|
|
|
|
help_text=_('Date this ticket was first created'),
|
|
|
|
)
|
|
|
|
|
|
|
|
modified = models.DateTimeField(
|
|
|
|
_('Modified'),
|
|
|
|
blank=True,
|
|
|
|
help_text=_('Date this ticket was most recently changed.'),
|
|
|
|
)
|
|
|
|
|
|
|
|
submitter_email = models.EmailField(
|
|
|
|
_('Submitter E-Mail'),
|
|
|
|
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(
|
|
|
|
_('Status'),
|
|
|
|
choices=STATUS_CHOICES,
|
|
|
|
default=OPEN_STATUS,
|
|
|
|
)
|
|
|
|
|
|
|
|
on_hold = models.BooleanField(
|
|
|
|
_('On Hold'),
|
|
|
|
blank=True,
|
2009-05-24 07:26:12 +02:00
|
|
|
default=False,
|
2008-08-19 10:50:38 +02:00
|
|
|
help_text=_('If a ticket is on hold, it will not automatically be '
|
|
|
|
'escalated.'),
|
|
|
|
)
|
|
|
|
|
|
|
|
description = models.TextField(
|
|
|
|
_('Description'),
|
|
|
|
blank=True,
|
|
|
|
null=True,
|
|
|
|
help_text=_('The content of the customers query.'),
|
|
|
|
)
|
|
|
|
|
|
|
|
resolution = models.TextField(
|
|
|
|
_('Resolution'),
|
|
|
|
blank=True,
|
|
|
|
null=True,
|
|
|
|
help_text=_('The resolution provided to the customer by our staff.'),
|
|
|
|
)
|
|
|
|
|
|
|
|
priority = models.IntegerField(
|
|
|
|
_('Priority'),
|
|
|
|
choices=PRIORITY_CHOICES,
|
|
|
|
default=3,
|
|
|
|
blank=3,
|
|
|
|
help_text=_('1 = Highest Priority, 5 = Low Priority'),
|
|
|
|
)
|
|
|
|
|
|
|
|
last_escalation = models.DateTimeField(
|
|
|
|
blank=True,
|
|
|
|
null=True,
|
|
|
|
editable=False,
|
|
|
|
help_text=_('The date this ticket was last escalated - updated '
|
|
|
|
'automatically by management/commands/escalate_tickets.py.'),
|
|
|
|
)
|
2008-01-10 01:28:45 +01:00
|
|
|
|
2007-12-27 01:29:17 +01:00
|
|
|
def _get_assigned_to(self):
|
2008-08-19 10:50:38 +02:00
|
|
|
""" 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
|
2007-12-27 02:35:34 +01:00
|
|
|
has a full name configured, we use that, otherwise their username. """
|
2007-12-27 01:29:17 +01:00
|
|
|
if not self.assigned_to:
|
2008-05-07 11:04:18 +02:00
|
|
|
return _('Unassigned')
|
2007-12-27 01:29:17 +01:00
|
|
|
else:
|
|
|
|
if self.assigned_to.get_full_name():
|
|
|
|
return self.assigned_to.get_full_name()
|
|
|
|
else:
|
2009-08-27 12:23:44 +02:00
|
|
|
return self.assigned_to.username
|
2007-12-27 01:29:17 +01:00
|
|
|
get_assigned_to = property(_get_assigned_to)
|
|
|
|
|
2008-01-07 21:22:13 +01:00
|
|
|
def _get_ticket(self):
|
2008-08-19 10:50:38 +02:00
|
|
|
""" A user-friendly ticket ID, which is a combination of ticket ID
|
|
|
|
and queue slug. This is generally used in e-mail subjects. """
|
2008-01-07 21:22:13 +01:00
|
|
|
|
2008-05-07 11:04:18 +02:00
|
|
|
return u"[%s]" % (self.ticket_for_url)
|
2008-01-07 21:22:13 +01:00
|
|
|
ticket = property(_get_ticket)
|
|
|
|
|
2008-01-16 01:26:24 +01:00
|
|
|
def _get_ticket_for_url(self):
|
2008-08-19 10:50:38 +02:00
|
|
|
""" A URL-friendly ticket ID, used in links. """
|
2008-05-07 11:04:18 +02:00
|
|
|
return u"%s-%s" % (self.queue.slug, self.id)
|
2008-01-16 01:26:24 +01:00
|
|
|
ticket_for_url = property(_get_ticket_for_url)
|
|
|
|
|
2008-01-12 06:37:45 +01:00
|
|
|
def _get_priority_img(self):
|
2008-08-19 10:50:38 +02:00
|
|
|
""" Image-based representation of the priority """
|
2008-01-12 06:37:45 +01:00
|
|
|
from django.conf import settings
|
2008-10-28 11:29:47 +01:00
|
|
|
return u"%shelpdesk/priorities/priority%s.png" % (settings.MEDIA_URL, self.priority)
|
2008-01-12 06:37:45 +01:00
|
|
|
get_priority_img = property(_get_priority_img)
|
|
|
|
|
2008-08-12 01:24:18 +02:00
|
|
|
def _get_priority_span(self):
|
2008-08-19 10:50:38 +02:00
|
|
|
"""
|
|
|
|
A HTML <span> providing a CSS_styled representation of the priority.
|
|
|
|
"""
|
2008-08-12 01:24:18 +02:00
|
|
|
from django.utils.safestring import mark_safe
|
|
|
|
return mark_safe(u"<span class='priority%s'>%s</span>" % (self.priority, self.priority))
|
|
|
|
get_priority_span = property(_get_priority_span)
|
|
|
|
|
2008-01-16 05:52:30 +01:00
|
|
|
def _get_status(self):
|
2008-08-19 10:50:38 +02:00
|
|
|
"""
|
|
|
|
Displays the ticket status, with an "On Hold" message if needed.
|
|
|
|
"""
|
2008-01-16 05:52:30 +01:00
|
|
|
held_msg = ''
|
2008-05-07 11:04:18 +02:00
|
|
|
if self.on_hold: held_msg = _(' - On Hold')
|
|
|
|
return u'%s%s' % (self.get_status_display(), held_msg)
|
2008-01-16 05:52:30 +01:00
|
|
|
get_status = property(_get_status)
|
|
|
|
|
2008-01-16 01:26:24 +01:00
|
|
|
def _get_ticket_url(self):
|
2008-08-19 10:50:38 +02:00
|
|
|
"""
|
|
|
|
Returns a publicly-viewable URL for this ticket, used when giving
|
|
|
|
a URL to the submitter of a ticket.
|
|
|
|
"""
|
2008-01-16 01:26:24 +01:00
|
|
|
from django.contrib.sites.models import Site
|
|
|
|
from django.core.urlresolvers import reverse
|
|
|
|
site = Site.objects.get_current()
|
2008-08-19 10:50:38 +02:00
|
|
|
return u"http://%s%s?ticket=%s&email=%s" % (
|
|
|
|
site.domain,
|
|
|
|
reverse('helpdesk_public_view'),
|
|
|
|
self.ticket_for_url,
|
|
|
|
self.submitter_email
|
|
|
|
)
|
2008-01-16 01:26:24 +01:00
|
|
|
ticket_url = property(_get_ticket_url)
|
|
|
|
|
2008-01-21 02:02:12 +01:00
|
|
|
def _get_staff_url(self):
|
2008-08-19 10:50:38 +02:00
|
|
|
"""
|
|
|
|
Returns a staff-only URL for this ticket, used when giving a URL to
|
|
|
|
a staff member (in emails etc)
|
|
|
|
"""
|
2008-01-21 02:02:12 +01:00
|
|
|
from django.contrib.sites.models import Site
|
|
|
|
from django.core.urlresolvers import reverse
|
|
|
|
site = Site.objects.get_current()
|
2008-08-19 10:50:38 +02:00
|
|
|
return u"http://%s%s" % (
|
|
|
|
site.domain,
|
|
|
|
reverse('helpdesk_view',
|
|
|
|
args=[self.id])
|
|
|
|
)
|
2008-01-21 02:02:12 +01:00
|
|
|
staff_url = property(_get_staff_url)
|
|
|
|
|
2009-09-09 11:11:05 +02:00
|
|
|
if HAS_TAG_SUPPORT:
|
|
|
|
tags = TagField(blank=True)
|
|
|
|
|
2007-12-27 01:29:17 +01:00
|
|
|
class Meta:
|
|
|
|
get_latest_by = "created"
|
|
|
|
|
|
|
|
def __unicode__(self):
|
2008-01-15 01:20:00 +01:00
|
|
|
return u'%s' % self.title
|
2007-12-27 01:29:17 +01:00
|
|
|
|
|
|
|
def get_absolute_url(self):
|
2009-01-19 11:02:05 +01:00
|
|
|
return ('helpdesk_view', (self.id,))
|
2008-01-15 01:20:00 +01:00
|
|
|
get_absolute_url = models.permalink(get_absolute_url)
|
2007-12-27 01:29:17 +01:00
|
|
|
|
2008-09-09 10:32:01 +02:00
|
|
|
def save(self, force_insert=False, force_update=False):
|
2007-12-27 01:29:17 +01:00
|
|
|
if not self.id:
|
|
|
|
# This is a new ticket as no ID yet exists.
|
|
|
|
self.created = datetime.now()
|
2008-08-19 10:50:38 +02:00
|
|
|
|
2008-01-10 01:28:45 +01:00
|
|
|
if not self.priority:
|
|
|
|
self.priority = 3
|
2008-08-19 10:50:38 +02:00
|
|
|
|
2008-01-10 01:28:45 +01:00
|
|
|
self.modified = datetime.now()
|
2007-12-27 01:29:17 +01:00
|
|
|
|
2008-09-09 10:32:01 +02:00
|
|
|
super(Ticket, self).save(force_insert, force_update)
|
2007-12-27 01:29:17 +01:00
|
|
|
|
2008-08-19 10:50:38 +02:00
|
|
|
|
2008-01-16 01:26:24 +01:00
|
|
|
class FollowUpManager(models.Manager):
|
|
|
|
def private_followups(self):
|
|
|
|
return self.filter(public=False)
|
2008-08-19 10:50:38 +02:00
|
|
|
|
2008-01-16 01:26:24 +01:00
|
|
|
def public_followups(self):
|
|
|
|
return self.filter(public=True)
|
2007-12-27 01:29:17 +01:00
|
|
|
|
2008-08-19 10:50:38 +02:00
|
|
|
|
2007-12-27 01:29:17 +01:00
|
|
|
class FollowUp(models.Model):
|
2008-08-19 10:50:38 +02:00
|
|
|
"""
|
|
|
|
A FollowUp is a comment and/or change to a ticket. We keep a simple
|
|
|
|
title, the comment entered by the user, and the new status of a ticket
|
2007-12-27 02:35:34 +01:00
|
|
|
to enable easy flagging of details on the view-ticket page.
|
|
|
|
|
|
|
|
The title is automatically generated at save-time, based on what action
|
|
|
|
the user took.
|
|
|
|
|
2008-08-19 10:50:38 +02:00
|
|
|
Tickets that aren't public are never shown to or e-mailed to the submitter,
|
2007-12-27 02:35:34 +01:00
|
|
|
although all staff can see them.
|
|
|
|
"""
|
2008-08-19 10:50:38 +02:00
|
|
|
|
2007-12-27 01:29:17 +01:00
|
|
|
ticket = models.ForeignKey(Ticket)
|
2008-08-19 10:50:38 +02:00
|
|
|
|
|
|
|
date = models.DateTimeField(
|
|
|
|
_('Date'),
|
|
|
|
)
|
|
|
|
|
|
|
|
title = models.CharField(
|
|
|
|
_('Title'),
|
|
|
|
max_length=200,
|
|
|
|
blank=True,
|
|
|
|
null=True,
|
|
|
|
)
|
|
|
|
|
|
|
|
comment = models.TextField(
|
|
|
|
_('Comment'),
|
|
|
|
blank=True,
|
|
|
|
null=True,
|
|
|
|
)
|
|
|
|
|
|
|
|
public = models.BooleanField(
|
|
|
|
_('Public'),
|
|
|
|
blank=True,
|
2009-05-24 07:26:12 +02:00
|
|
|
default=False,
|
2008-08-19 10:50:38 +02:00
|
|
|
help_text=_('Public tickets are viewable by the submitter and all '
|
|
|
|
'staff, but non-public tickets can only be seen by staff.'),
|
|
|
|
)
|
|
|
|
|
|
|
|
user = models.ForeignKey(
|
|
|
|
User,
|
|
|
|
blank=True,
|
|
|
|
null=True,
|
|
|
|
)
|
|
|
|
|
|
|
|
new_status = models.IntegerField(
|
|
|
|
_('New Status'),
|
|
|
|
choices=Ticket.STATUS_CHOICES,
|
|
|
|
blank=True,
|
|
|
|
null=True,
|
|
|
|
help_text=_('If the status was changed, what was it changed to?'),
|
|
|
|
)
|
2007-12-27 01:29:17 +01:00
|
|
|
|
2008-01-16 01:26:24 +01:00
|
|
|
objects = FollowUpManager()
|
|
|
|
|
2007-12-27 01:29:17 +01:00
|
|
|
class Meta:
|
|
|
|
ordering = ['date']
|
2008-08-19 10:50:38 +02:00
|
|
|
|
2007-12-27 01:29:17 +01:00
|
|
|
def __unicode__(self):
|
2008-01-15 01:20:00 +01:00
|
|
|
return u'%s' % self.title
|
2007-12-27 01:29:17 +01:00
|
|
|
|
2008-02-08 06:29:51 +01:00
|
|
|
def get_absolute_url(self):
|
2008-05-07 11:04:18 +02:00
|
|
|
return u"%s#followup%s" % (self.ticket.get_absolute_url(), self.id)
|
2008-02-08 06:29:51 +01:00
|
|
|
|
2008-09-09 10:32:01 +02:00
|
|
|
def save(self, force_insert=False, force_update=False):
|
2008-01-10 01:28:45 +01:00
|
|
|
t = self.ticket
|
|
|
|
t.modified = datetime.now()
|
2008-08-19 10:50:38 +02:00
|
|
|
self.date = datetime.now()
|
2008-01-10 01:28:45 +01:00
|
|
|
t.save()
|
2008-09-09 10:32:01 +02:00
|
|
|
super(FollowUp, self).save(force_insert, force_update)
|
2008-01-10 01:28:45 +01:00
|
|
|
|
2008-08-19 10:50:38 +02:00
|
|
|
|
2007-12-27 01:29:17 +01:00
|
|
|
class TicketChange(models.Model):
|
2008-08-19 10:50:38 +02:00
|
|
|
"""
|
|
|
|
For each FollowUp, any changes to the parent ticket (eg Title, Priority,
|
2007-12-27 02:35:34 +01:00
|
|
|
etc) are tracked here for display purposes.
|
|
|
|
"""
|
2008-08-19 10:50:38 +02:00
|
|
|
|
2008-08-13 23:42:57 +02:00
|
|
|
followup = models.ForeignKey(FollowUp)
|
2008-08-19 10:50:38 +02:00
|
|
|
|
|
|
|
field = models.CharField(
|
|
|
|
_('Field'),
|
|
|
|
max_length=100,
|
|
|
|
)
|
|
|
|
|
|
|
|
old_value = models.TextField(
|
|
|
|
_('Old Value'),
|
|
|
|
blank=True,
|
|
|
|
null=True,
|
|
|
|
)
|
|
|
|
|
|
|
|
new_value = models.TextField(
|
|
|
|
_('New Value'),
|
|
|
|
blank=True,
|
|
|
|
null=True,
|
|
|
|
)
|
2007-12-27 02:35:34 +01:00
|
|
|
|
|
|
|
def __unicode__(self):
|
2009-10-13 12:28:42 +02:00
|
|
|
str = u'%s ' % self.field
|
|
|
|
if not self.new_value:
|
|
|
|
str += ugettext('removed')
|
|
|
|
elif not self.old_value:
|
|
|
|
str += ugettext('set to %s') % self.new_value
|
2007-12-27 02:35:34 +01:00
|
|
|
else:
|
2009-10-13 12:28:42 +02:00
|
|
|
str += ugettext('changed from "%(old_value)s" to "%(new_value)s"') % {
|
|
|
|
'old_value': self.old_value,
|
|
|
|
'new_value': self.new_value
|
|
|
|
}
|
2007-12-27 02:35:34 +01:00
|
|
|
return str
|
2008-01-07 21:22:13 +01:00
|
|
|
|
2008-02-08 01:19:58 +01:00
|
|
|
|
2008-12-30 01:41:47 +01:00
|
|
|
def attachment_path(instance, filename):
|
2008-02-08 01:19:58 +01:00
|
|
|
"""
|
2008-12-30 01:41:47 +01:00
|
|
|
Provide a file path that will help prevent files being overwritten, by
|
|
|
|
putting attachments in a folder off attachments for ticket/followup_id/.
|
2008-02-08 01:19:58 +01:00
|
|
|
"""
|
2008-12-30 01:41:47 +01:00
|
|
|
import os
|
|
|
|
from django.conf import settings
|
|
|
|
os.umask(0)
|
|
|
|
path = 'helpdesk/attachments/%s/%s' % (instance.followup.ticket.ticket_for_url, instance.followup.id )
|
2009-03-08 07:18:03 +01:00
|
|
|
att_path = os.path.join(settings.MEDIA_ROOT, path)
|
|
|
|
if not os.path.exists(att_path):
|
|
|
|
os.makedirs(att_path, 0777)
|
2008-12-30 01:41:47 +01:00
|
|
|
return os.path.join(path, filename)
|
2008-08-19 10:50:38 +02:00
|
|
|
|
2008-02-08 01:19:58 +01:00
|
|
|
|
|
|
|
class Attachment(models.Model):
|
2008-08-19 10:50:38 +02:00
|
|
|
"""
|
|
|
|
Represents a file attached to a follow-up. This could come from an e-mail
|
|
|
|
attachment, or it could be uploaded via the web interface.
|
|
|
|
"""
|
|
|
|
|
2008-08-13 23:42:57 +02:00
|
|
|
followup = models.ForeignKey(FollowUp)
|
2008-08-19 10:50:38 +02:00
|
|
|
|
2008-12-30 01:41:47 +01:00
|
|
|
file = models.FileField(
|
2008-08-19 10:50:38 +02:00
|
|
|
_('File'),
|
2008-12-30 01:41:47 +01:00
|
|
|
upload_to=attachment_path,
|
2008-08-19 10:50:38 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
filename = models.CharField(
|
|
|
|
_('Filename'),
|
|
|
|
max_length=100,
|
|
|
|
)
|
|
|
|
|
|
|
|
mime_type = models.CharField(
|
|
|
|
_('MIME Type'),
|
|
|
|
max_length=30,
|
|
|
|
)
|
|
|
|
|
|
|
|
size = models.IntegerField(
|
|
|
|
_('Size'),
|
|
|
|
help_text=_('Size of this file in bytes'),
|
|
|
|
)
|
2008-01-15 05:00:19 +01:00
|
|
|
|
2008-02-08 01:19:58 +01:00
|
|
|
def get_upload_to(self, field_attname):
|
|
|
|
""" Get upload_to path specific to this item """
|
2008-10-28 11:24:59 +01:00
|
|
|
if not self.id:
|
|
|
|
return u''
|
2008-08-19 10:50:38 +02:00
|
|
|
return u'helpdesk/attachments/%s/%s' % (
|
|
|
|
self.followup.ticket.ticket_for_url,
|
|
|
|
self.followup.id
|
|
|
|
)
|
2008-02-08 01:19:58 +01:00
|
|
|
|
2008-01-15 05:00:19 +01:00
|
|
|
def __unicode__(self):
|
|
|
|
return u'%s' % self.filename
|
|
|
|
|
|
|
|
class Meta:
|
2008-02-08 01:19:58 +01:00
|
|
|
ordering = ['filename',]
|
|
|
|
|
2008-01-11 02:00:01 +01:00
|
|
|
|
|
|
|
class PreSetReply(models.Model):
|
2008-08-19 10:50:38 +02:00
|
|
|
"""
|
|
|
|
We can allow the admin to define a number of pre-set replies, used to
|
2008-01-15 01:20:00 +01:00
|
|
|
simplify the sending of updates and resolutions. These are basically Django
|
2008-08-19 10:50:38 +02:00
|
|
|
templates with a limited context - however if you wanted to get crafy it would
|
|
|
|
be easy to write a reply that displays ALL updates in hierarchical order etc
|
2008-01-15 01:20:00 +01:00
|
|
|
with use of for loops over {{ ticket.followup_set.all }} and friends.
|
2008-08-19 10:50:38 +02:00
|
|
|
|
2008-01-15 01:20:00 +01:00
|
|
|
When replying to a ticket, the user can select any reply set for the current
|
2008-08-19 10:50:38 +02:00
|
|
|
queue, and the body text is fetched via AJAX.
|
|
|
|
"""
|
|
|
|
|
|
|
|
queues = models.ManyToManyField(
|
|
|
|
Queue,
|
|
|
|
blank=True,
|
|
|
|
null=True,
|
|
|
|
help_text=_('Leave blank to allow this reply to be used for all '
|
|
|
|
'queues, or select those queues you wish to limit this reply to.'),
|
|
|
|
)
|
|
|
|
|
|
|
|
name = models.CharField(
|
|
|
|
_('Name'),
|
|
|
|
max_length=100,
|
|
|
|
help_text=_('Only used to assist users with selecting a reply - not '
|
|
|
|
'shown to the user.'),
|
|
|
|
)
|
|
|
|
|
|
|
|
body = models.TextField(
|
|
|
|
_('Body'),
|
|
|
|
help_text=_('Context available: {{ ticket }} - ticket object (eg '
|
|
|
|
'{{ ticket.title }}); {{ queue }} - The queue; and {{ user }} '
|
|
|
|
'- the current user.'),
|
|
|
|
)
|
2008-01-11 02:00:01 +01:00
|
|
|
|
|
|
|
class Meta:
|
|
|
|
ordering = ['name',]
|
2008-01-15 01:20:00 +01:00
|
|
|
|
|
|
|
def __unicode__(self):
|
|
|
|
return u'%s' % self.name
|
2008-01-22 06:54:22 +01:00
|
|
|
|
2008-08-19 10:50:38 +02:00
|
|
|
|
2008-01-22 06:54:22 +01:00
|
|
|
class EscalationExclusion(models.Model):
|
2008-08-19 10:50:38 +02:00
|
|
|
"""
|
|
|
|
An 'EscalationExclusion' lets us define a date on which escalation should
|
|
|
|
not happen, for example a weekend or public holiday.
|
2008-01-22 06:54:22 +01:00
|
|
|
|
2008-08-19 10:50:38 +02:00
|
|
|
You may also have a queue that is only used on one day per week.
|
|
|
|
|
|
|
|
To create these on a regular basis, check out the README file for an
|
|
|
|
example cronjob that runs 'create_escalation_exclusions.py'.
|
|
|
|
"""
|
|
|
|
|
|
|
|
queues = models.ManyToManyField(
|
|
|
|
Queue,
|
|
|
|
blank=True,
|
|
|
|
null=True,
|
|
|
|
help_text=_('Leave blank for this exclusion to be applied to all '
|
|
|
|
'queues, or select those queues you wish to exclude with this '
|
|
|
|
'entry.'),
|
|
|
|
)
|
|
|
|
|
|
|
|
name = models.CharField(
|
|
|
|
_('Name'),
|
|
|
|
max_length=100,
|
|
|
|
)
|
|
|
|
|
|
|
|
date = models.DateField(
|
|
|
|
_('Date'),
|
|
|
|
help_text=_('Date on which escalation should not happen'),
|
|
|
|
)
|
2008-01-22 06:54:22 +01:00
|
|
|
|
|
|
|
def __unicode__(self):
|
|
|
|
return u'%s' % self.name
|
2008-02-08 01:19:58 +01:00
|
|
|
|
2008-08-19 10:50:38 +02:00
|
|
|
|
2008-04-02 01:26:12 +02:00
|
|
|
class EmailTemplate(models.Model):
|
|
|
|
"""
|
|
|
|
Since these are more likely to be changed than other templates, we store
|
2008-08-19 10:50:38 +02:00
|
|
|
them in the database.
|
|
|
|
|
|
|
|
This means that an admin can change email templates without having to have
|
|
|
|
access to the filesystem.
|
2008-04-02 01:26:12 +02:00
|
|
|
"""
|
|
|
|
|
2008-08-19 10:50:38 +02:00
|
|
|
template_name = models.CharField(
|
|
|
|
_('Template Name'),
|
|
|
|
max_length=100,
|
|
|
|
unique=True,
|
|
|
|
)
|
|
|
|
|
|
|
|
subject = models.CharField(
|
|
|
|
_('Subject'),
|
|
|
|
max_length=100,
|
|
|
|
help_text=_('This will be prefixed with "[ticket.ticket] ticket.title"'
|
|
|
|
'. We recommend something simple such as "(Updated") or "(Closed)"'
|
|
|
|
' - the same context is available as in plain_text, below.'),
|
|
|
|
)
|
|
|
|
|
|
|
|
heading = models.CharField(
|
|
|
|
_('Heading'),
|
|
|
|
max_length=100,
|
|
|
|
help_text=_('In HTML e-mails, this will be the heading at the top of '
|
|
|
|
'the email - the same context is available as in plain_text, '
|
|
|
|
'below.'),
|
|
|
|
)
|
|
|
|
|
|
|
|
plain_text = models.TextField(
|
|
|
|
_('Plain Text'),
|
|
|
|
help_text=_('The context available to you includes {{ ticket }}, '
|
|
|
|
'{{ queue }}, and depending on the time of the call: '
|
|
|
|
'{{ resolution }} or {{ comment }}.'),
|
|
|
|
)
|
|
|
|
|
|
|
|
html = models.TextField(
|
|
|
|
_('HTML'),
|
|
|
|
help_text=_('The same context is available here as in plain_text, '
|
|
|
|
'above.'),
|
|
|
|
)
|
2008-04-02 01:26:12 +02:00
|
|
|
|
|
|
|
def __unicode__(self):
|
|
|
|
return u'%s' % self.template_name
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
ordering = ['template_name',]
|
2008-05-21 23:16:44 +02:00
|
|
|
|
2008-08-19 10:50:38 +02:00
|
|
|
|
2008-05-21 23:16:44 +02:00
|
|
|
class KBCategory(models.Model):
|
|
|
|
"""
|
2008-08-19 10:50:38 +02:00
|
|
|
Lets help users help themselves: the Knowledge Base is a categorised
|
2008-05-21 23:16:44 +02:00
|
|
|
listing of questions & answers.
|
|
|
|
"""
|
2008-08-19 10:50:38 +02:00
|
|
|
|
|
|
|
title = models.CharField(
|
|
|
|
_('Title'),
|
|
|
|
max_length=100,
|
|
|
|
)
|
|
|
|
|
|
|
|
slug = models.SlugField(
|
|
|
|
_('Slug'),
|
|
|
|
)
|
|
|
|
|
|
|
|
description = models.TextField(
|
|
|
|
_('Description'),
|
|
|
|
)
|
2008-05-21 23:16:44 +02:00
|
|
|
|
|
|
|
def __unicode__(self):
|
|
|
|
return u'%s' % self.title
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
ordering = ['title',]
|
2008-08-19 10:50:38 +02:00
|
|
|
|
2008-05-21 23:16:44 +02:00
|
|
|
def get_absolute_url(self):
|
2009-01-19 11:02:05 +01:00
|
|
|
return ('helpdesk_kb_category', (), {'slug': self.slug})
|
2008-05-21 23:16:44 +02:00
|
|
|
get_absolute_url = models.permalink(get_absolute_url)
|
|
|
|
|
2008-08-19 10:50:38 +02:00
|
|
|
|
2008-05-21 23:16:44 +02:00
|
|
|
class KBItem(models.Model):
|
|
|
|
"""
|
2008-08-19 10:50:38 +02:00
|
|
|
An item within the knowledgebase. Very straightforward question/answer
|
2008-05-21 23:16:44 +02:00
|
|
|
style system.
|
|
|
|
"""
|
|
|
|
category = models.ForeignKey(KBCategory)
|
|
|
|
|
2008-08-19 10:50:38 +02:00
|
|
|
title = models.CharField(
|
|
|
|
_('Title'),
|
|
|
|
max_length=100,
|
|
|
|
)
|
|
|
|
|
|
|
|
question = models.TextField(
|
|
|
|
_('Question'),
|
|
|
|
)
|
|
|
|
|
|
|
|
answer = models.TextField(
|
|
|
|
_('Answer'),
|
|
|
|
)
|
|
|
|
|
|
|
|
votes = models.IntegerField(
|
|
|
|
_('Votes'),
|
|
|
|
help_text=_('Total number of votes cast for this item'),
|
|
|
|
)
|
|
|
|
|
|
|
|
recommendations = models.IntegerField(
|
|
|
|
_('Positive Votes'),
|
|
|
|
help_text=_('Number of votes for this item which were POSITIVE.'),
|
|
|
|
)
|
|
|
|
|
|
|
|
last_updated = models.DateTimeField(
|
|
|
|
_('Last Updated'),
|
|
|
|
help_text=_('The date on which this question was most recently '
|
|
|
|
'changed.'),
|
2008-10-07 08:52:52 +02:00
|
|
|
blank=True,
|
2008-08-19 10:50:38 +02:00
|
|
|
)
|
2008-05-21 23:16:44 +02:00
|
|
|
|
2008-09-09 10:32:01 +02:00
|
|
|
def save(self, force_insert=False, force_update=False):
|
2008-10-07 08:52:52 +02:00
|
|
|
if not self.last_updated:
|
|
|
|
self.last_updated = datetime.now()
|
2008-09-09 10:32:01 +02:00
|
|
|
return super(KBItem, self).save(force_insert, force_update)
|
2008-05-21 23:16:44 +02:00
|
|
|
|
|
|
|
def _score(self):
|
|
|
|
if self.votes > 0:
|
|
|
|
return int(self.recommendations / self.votes)
|
|
|
|
else:
|
|
|
|
return _('Unrated')
|
|
|
|
score = property(_score)
|
2008-08-19 10:50:38 +02:00
|
|
|
|
2008-05-21 23:16:44 +02:00
|
|
|
def __unicode__(self):
|
|
|
|
return u'%s' % self.title
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
ordering = ['title',]
|
|
|
|
|
|
|
|
def get_absolute_url(self):
|
2009-01-19 11:02:05 +01:00
|
|
|
return ('helpdesk_kb_item', (self.id,))
|
2008-05-21 23:16:44 +02:00
|
|
|
get_absolute_url = models.permalink(get_absolute_url)
|
2008-08-19 10:50:38 +02:00
|
|
|
|
2008-08-28 11:06:24 +02:00
|
|
|
|
|
|
|
class SavedSearch(models.Model):
|
|
|
|
"""
|
|
|
|
Allow a user to save a ticket search, eg their filtering and sorting
|
|
|
|
options, and optionally share it with other users. This lets people
|
|
|
|
easily create a set of commonly-used filters, such as:
|
|
|
|
* My tickets waiting on me
|
|
|
|
* My tickets waiting on submitter
|
|
|
|
* My tickets in 'Priority Support' queue with priority of 1
|
|
|
|
* All tickets containing the word 'billing'.
|
|
|
|
etc...
|
|
|
|
"""
|
|
|
|
user = models.ForeignKey(User)
|
|
|
|
|
|
|
|
title = models.CharField(
|
|
|
|
_('Query Name'),
|
|
|
|
max_length=100,
|
|
|
|
help_text=_('User-provided name for this query'),
|
|
|
|
)
|
|
|
|
|
|
|
|
shared = models.BooleanField(
|
|
|
|
_('Shared With Other Users?'),
|
|
|
|
blank=True,
|
2009-05-24 07:26:12 +02:00
|
|
|
default=False,
|
2008-08-28 11:06:24 +02:00
|
|
|
help_text=_('Should other users see this query?'),
|
|
|
|
)
|
2009-01-23 11:36:41 +01:00
|
|
|
|
2008-08-28 11:06:24 +02:00
|
|
|
query = models.TextField(
|
|
|
|
_('Search Query'),
|
|
|
|
help_text=_('Pickled query object. Be wary changing this.'),
|
|
|
|
)
|
|
|
|
|
|
|
|
def __unicode__(self):
|
|
|
|
if self.shared:
|
|
|
|
return u'%s (*)' % self.title
|
|
|
|
else:
|
|
|
|
return u'%s' % self.title
|
2008-09-09 10:32:01 +02:00
|
|
|
|
|
|
|
class UserSettings(models.Model):
|
|
|
|
"""
|
|
|
|
A bunch of user-specific settings that we want to be able to define, such
|
|
|
|
as notification preferences and other things that should probably be
|
|
|
|
configurable.
|
|
|
|
|
|
|
|
We should always refer to user.usersettings.settings['setting_name'].
|
|
|
|
"""
|
2009-01-23 11:36:41 +01:00
|
|
|
|
2008-09-09 10:32:01 +02:00
|
|
|
user = models.OneToOneField(User)
|
|
|
|
|
|
|
|
settings_pickled = models.TextField(
|
|
|
|
_('Settings Dictionary'),
|
|
|
|
help_text=_('This is a base64-encoded representation of a pickled Python dictionary. Do not change this field via the admin.'),
|
|
|
|
blank=True,
|
|
|
|
null=True,
|
|
|
|
)
|
|
|
|
|
|
|
|
def _set_settings(self, data):
|
|
|
|
# data should always be a Python dictionary.
|
2008-11-18 01:14:36 +01:00
|
|
|
import cPickle
|
|
|
|
from helpdesk.lib import b64encode
|
|
|
|
self.settings_pickled = b64encode(cPickle.dumps(data))
|
2009-01-23 11:36:41 +01:00
|
|
|
|
2008-09-09 10:32:01 +02:00
|
|
|
def _get_settings(self):
|
|
|
|
# return a python dictionary representing the pickled data.
|
2008-11-18 01:14:36 +01:00
|
|
|
import cPickle
|
|
|
|
from helpdesk.lib import b64decode
|
2008-09-09 10:32:01 +02:00
|
|
|
try:
|
2008-11-18 01:14:36 +01:00
|
|
|
return cPickle.loads(b64decode(str(self.settings_pickled)))
|
2008-09-09 10:32:01 +02:00
|
|
|
except cPickle.UnpicklingError:
|
|
|
|
return {}
|
|
|
|
|
|
|
|
settings = property(_get_settings, _set_settings)
|
|
|
|
|
|
|
|
def __unicode__(self):
|
|
|
|
return u'Preferences for %s' % self.user
|
2009-01-23 11:36:41 +01:00
|
|
|
|
2008-09-09 10:32:01 +02:00
|
|
|
class Meta:
|
|
|
|
verbose_name = 'User Settings'
|
|
|
|
verbose_name_plural = 'User Settings'
|
|
|
|
|
|
|
|
|
|
|
|
def create_usersettings(sender, created_models=[], instance=None, created=False, **kwargs):
|
|
|
|
"""
|
|
|
|
Helper function to create UserSettings instances as
|
|
|
|
required, eg when we first create the UserSettings database
|
|
|
|
table via 'syncdb' or when we save a new user.
|
|
|
|
|
|
|
|
If we end up with users with no UserSettings, then we get horrible
|
|
|
|
'DoesNotExist: UserSettings matching query does not exist.' errors.
|
|
|
|
"""
|
|
|
|
if sender == User and created:
|
|
|
|
# This is a new user, so lets create their settings entry.
|
2008-11-18 01:03:12 +01:00
|
|
|
s, created = UserSettings.objects.get_or_create(user=instance)
|
2008-09-09 10:32:01 +02:00
|
|
|
s.save()
|
|
|
|
elif UserSettings in created_models:
|
|
|
|
# We just created the UserSettings model, lets create a UserSettings
|
|
|
|
# entry for each existing user. This will only happen once (at install
|
|
|
|
# time, or at upgrade) when the UserSettings model doesn't already
|
|
|
|
# exist.
|
|
|
|
for u in User.objects.all():
|
|
|
|
try:
|
|
|
|
s = UserSettings.objects.get(user=u)
|
|
|
|
except UserSettings.DoesNotExist:
|
|
|
|
s = UserSettings(user=u)
|
|
|
|
s.save()
|
|
|
|
|
|
|
|
models.signals.post_syncdb.connect(create_usersettings)
|
|
|
|
models.signals.post_save.connect(create_usersettings, sender=User)
|
2008-10-25 00:52:34 +02:00
|
|
|
|
|
|
|
class IgnoreEmail(models.Model):
|
|
|
|
"""
|
|
|
|
This model lets us easily ignore e-mails from certain senders when
|
|
|
|
processing IMAP and POP3 mailboxes, eg mails from postmaster or from
|
|
|
|
known trouble-makers.
|
|
|
|
"""
|
|
|
|
queues = models.ManyToManyField(
|
|
|
|
Queue,
|
|
|
|
blank=True,
|
|
|
|
null=True,
|
|
|
|
help_text=_('Leave blank for this e-mail to be ignored on all '
|
|
|
|
'queues, or select those queues you wish to ignore this e-mail '
|
|
|
|
'for.'),
|
|
|
|
)
|
|
|
|
|
|
|
|
name = models.CharField(
|
|
|
|
_('Name'),
|
|
|
|
max_length=100,
|
|
|
|
)
|
2009-01-23 11:36:41 +01:00
|
|
|
|
2008-10-25 00:52:34 +02:00
|
|
|
date = models.DateField(
|
|
|
|
_('Date'),
|
|
|
|
help_text=_('Date on which this e-mail address was added'),
|
|
|
|
blank=True,
|
|
|
|
editable=False
|
|
|
|
)
|
|
|
|
|
|
|
|
email_address = models.CharField(
|
|
|
|
_('E-Mail Address'),
|
|
|
|
max_length=150,
|
|
|
|
help_text=_('Enter a full e-mail address, or portions with '
|
|
|
|
'wildcards, eg *@domain.com or postmaster@*.'),
|
|
|
|
)
|
|
|
|
|
2009-01-23 11:36:41 +01:00
|
|
|
keep_in_mailbox = models.BooleanField(
|
|
|
|
_('Save Emails in Mailbox?'),
|
|
|
|
blank=True,
|
2009-05-24 07:26:12 +02:00
|
|
|
default=False,
|
2009-01-23 11:36:41 +01:00
|
|
|
help_text=_('Do you want to save emails from this address in the '
|
|
|
|
'mailbox? If this is unticked, emails from this address will '
|
|
|
|
'be deleted.'),
|
|
|
|
)
|
|
|
|
|
2008-10-25 00:52:34 +02:00
|
|
|
def __unicode__(self):
|
|
|
|
return u'%s' % self.name
|
2009-01-23 11:36:41 +01:00
|
|
|
|
2008-10-25 00:52:34 +02:00
|
|
|
def save(self):
|
|
|
|
if not self.date:
|
|
|
|
self.date = datetime.now()
|
|
|
|
return super(IgnoreEmail, self).save()
|
|
|
|
|
|
|
|
def test(self, email):
|
|
|
|
"""
|
|
|
|
Possible situations:
|
|
|
|
1. Username & Domain both match
|
|
|
|
2. Username is wildcard, domain matches
|
|
|
|
3. Username matches, domain is wildcard
|
|
|
|
4. username & domain are both wildcards
|
|
|
|
5. Other (no match)
|
|
|
|
|
|
|
|
1-4 return True, 5 returns False.
|
|
|
|
"""
|
2009-01-23 11:36:41 +01:00
|
|
|
|
2008-10-25 00:52:34 +02:00
|
|
|
own_parts = self.email_address.split("@")
|
|
|
|
email_parts = email.split("@")
|
|
|
|
|
|
|
|
if self.email_address == email \
|
|
|
|
or own_parts[0] == "*" and own_parts[1] == email_parts[1] \
|
|
|
|
or own_parts[1] == "*" and own_parts[0] == email_parts[0] \
|
|
|
|
or own_parts[0] == "*" and own_parts[1] == "*":
|
|
|
|
return True
|
|
|
|
else:
|
|
|
|
return False
|
2009-09-09 10:47:48 +02:00
|
|
|
|
|
|
|
class TicketCC(models.Model):
|
|
|
|
"""
|
|
|
|
Often, there are people who wish to follow a ticket who aren't the
|
|
|
|
person who originally submitted it. This model provides a way for those
|
|
|
|
people to follow a ticket.
|
|
|
|
|
|
|
|
In this circumstance, a 'person' could be either an e-mail address or
|
|
|
|
an existing system user.
|
|
|
|
"""
|
|
|
|
|
|
|
|
ticket = models.ForeignKey(Ticket)
|
|
|
|
|
|
|
|
user = models.ForeignKey(
|
|
|
|
User,
|
|
|
|
blank=True,
|
|
|
|
null=True,
|
|
|
|
help_text=_('User who wishes to receive updates for this ticket.'),
|
|
|
|
)
|
|
|
|
|
|
|
|
email = models.EmailField(
|
|
|
|
_('E-Mail Address'),
|
|
|
|
blank=True,
|
|
|
|
null=True,
|
|
|
|
help_text=_('For non-user followers, enter their e-mail address'),
|
|
|
|
)
|
|
|
|
|
|
|
|
can_view = models.BooleanField(
|
|
|
|
_('Can View Ticket?'),
|
|
|
|
blank=True,
|
|
|
|
help_text=_('Can this CC login to view the ticket details?'),
|
|
|
|
)
|
|
|
|
|
|
|
|
can_update = models.BooleanField(
|
|
|
|
_('Can Update Ticket?'),
|
|
|
|
blank=True,
|
|
|
|
help_text=_('Can this CC login and update the ticket?'),
|
|
|
|
)
|
|
|
|
|
|
|
|
def _email_address(self):
|
|
|
|
if self.user and self.user.email is not None:
|
|
|
|
return self.user.email
|
|
|
|
else:
|
|
|
|
return self.email
|
|
|
|
email_address = property(_email_address)
|
|
|
|
|
|
|
|
def _display(self):
|
|
|
|
if self.user:
|
|
|
|
return self.user
|
|
|
|
else:
|
|
|
|
return self.email
|
|
|
|
display = property(_display)
|
|
|
|
|
|
|
|
def __unicode__(self):
|
|
|
|
return u'%s for %s' % (self.display, self.ticket.title)
|