2008-01-16 05:38:24 +01:00
|
|
|
""" ..
|
|
|
|
.,::;::::::
|
|
|
|
..,::::::::,,,,::: Jutda Helpdesk - A Django
|
|
|
|
.,,::::::,,,,,,,,,,,,,:: powered ticket tracker for
|
|
|
|
.,::::::,,,,,,,,,,,,,,,,,,:;r. small enterprise
|
|
|
|
.::::,,,,,,,,,,,,,,,,,,,,,,:;;rr.
|
|
|
|
.:::,,,,,,,,,,,,,,,,,,,,,,,:;;;;;rr (c) Copyright 2008
|
|
|
|
.:::,,,,,,,,,,,,,,,,,,,,,,,:;;;:::;;rr
|
|
|
|
.:::,,,,,,,,,,,,,,,,,,,,. ,;;;::::::;;rr Jutda
|
|
|
|
.:::,,,,,,,,,,,,,,,,,,. .:;;:::::::::;;rr
|
|
|
|
.:::,,,,,,,,,,,,,,,. .;r;::::::::::::;r; All Rights Reserved
|
|
|
|
.:::,,,,,,,,,,,,,,, .;r;;:::::::::::;;:.
|
|
|
|
.:::,,,,,,,,,,,,,,,. .;r;;::::::::::::;:.
|
|
|
|
.;:,,,,,,,,,,,,,,, .,;rr;::::::::::::;:. This software is released
|
|
|
|
.,:,,,,,,,,,,,,,. .,:;rrr;;::::::::::::;;. under a limited-use license that
|
|
|
|
:,,,,,,,,,,,,,..:;rrrrr;;;::::::::::::;;. allows you to freely download this
|
|
|
|
:,,,,,,,:::;;;rr;;;;;;:::::::::::::;;, software from it's manufacturer and
|
|
|
|
::::;;;;;;;;;;;:::::::::::::::::;;, use it yourself, however you may not
|
|
|
|
.r;;;;:::::::::::::::::::::::;;;, distribute it. For further details, see
|
|
|
|
.r;::::::::::::::::::::;;;;;:, the enclosed LICENSE file.
|
|
|
|
.;;::::::::::::::;;;;;:,.
|
|
|
|
.;;:::::::;;;;;;:,. Please direct people who wish to download this
|
|
|
|
.r;;;;;;;;:,. software themselves to www.jutda.com.au.
|
|
|
|
,,,..
|
|
|
|
|
|
|
|
$Id$
|
|
|
|
|
|
|
|
"""
|
2008-01-22 06:54:22 +01:00
|
|
|
from datetime import datetime, timedelta, date
|
2008-01-16 05:38:24 +01:00
|
|
|
from django.db.models import Q
|
2008-01-22 06:54:22 +01:00
|
|
|
from helpdesk.models import Queue, Ticket, FollowUp, EscalationExclusion, TicketChange
|
2008-01-16 05:38:24 +01:00
|
|
|
from helpdesk.lib import send_multipart_mail
|
2008-01-22 06:54:22 +01:00
|
|
|
import sys, getopt
|
2008-01-16 05:38:24 +01:00
|
|
|
|
2008-01-22 06:54:22 +01:00
|
|
|
def escalate_tickets(queues, verbose):
|
|
|
|
""" Only include queues with escalation configured """
|
|
|
|
queryset = Queue.objects.filter(escalate_days__isnull=False).exclude(escalate_days=0)
|
|
|
|
if queues:
|
|
|
|
queryset = queryset.filter(slug__in=queues)
|
|
|
|
|
|
|
|
for q in queryset:
|
|
|
|
last = date.today() - timedelta(days=q.escalate_days)
|
|
|
|
today = date.today()
|
|
|
|
workdate = last
|
2008-01-16 05:38:24 +01:00
|
|
|
|
2008-01-22 06:54:22 +01:00
|
|
|
days = 0
|
|
|
|
|
|
|
|
while workdate < today:
|
|
|
|
if EscalationExclusion.objects.filter(date=workdate).count() == 0:
|
|
|
|
days += 1
|
|
|
|
workdate = workdate + timedelta(days=1)
|
2008-01-16 05:38:24 +01:00
|
|
|
|
|
|
|
|
2008-01-22 06:54:22 +01:00
|
|
|
req_last_escl_date = date.today() - timedelta(days=days)
|
|
|
|
|
|
|
|
if verbose:
|
|
|
|
print "Processing: %s" % q
|
|
|
|
|
|
|
|
for t in q.ticket_set.filter(Q(status=Ticket.OPEN_STATUS) | Q(status=Ticket.REOPENED_STATUS)).exclude(priority=1).filter(Q(on_hold__isnull=True) | Q(on_hold=False)).filter(Q(last_escalation__lte=req_last_escl_date) | Q(last_escalation__isnull=True)):
|
|
|
|
t.last_escalation = datetime.now()
|
2008-01-16 05:38:24 +01:00
|
|
|
t.priority -= 1
|
|
|
|
t.save()
|
|
|
|
|
2008-01-22 06:54:22 +01:00
|
|
|
if verbose:
|
|
|
|
print " - Esclating %s from %s>%s" % (t.ticket, t.priority+1, t.priority)
|
|
|
|
|
2008-01-16 05:38:24 +01:00
|
|
|
f = FollowUp(
|
|
|
|
ticket = t,
|
|
|
|
title = 'Ticket Escalated',
|
2008-01-22 06:54:22 +01:00
|
|
|
date=datetime.now(),
|
2008-01-16 05:38:24 +01:00
|
|
|
public=True,
|
2008-01-22 06:54:22 +01:00
|
|
|
comment='Ticket escalated after %s days' % q.escalate_days,
|
2008-01-16 05:38:24 +01:00
|
|
|
)
|
|
|
|
f.save()
|
|
|
|
|
|
|
|
tc = TicketChange(
|
|
|
|
followup = f,
|
2008-01-22 06:54:22 +01:00
|
|
|
field = 'Priority',
|
2008-01-16 05:38:24 +01:00
|
|
|
old_value = t.priority + 1,
|
|
|
|
new_value = t.priority,
|
|
|
|
)
|
|
|
|
tc.save()
|
|
|
|
|
2008-01-22 06:54:22 +01:00
|
|
|
def usage():
|
|
|
|
print "Options:"
|
|
|
|
print " --queues, -q: Queues to include (default: all). Use queue slugs"
|
|
|
|
print " --verbose, -v: Display a list of dates excluded"
|
|
|
|
|
2008-01-16 05:38:24 +01:00
|
|
|
if __name__ == '__main__':
|
2008-01-22 06:54:22 +01:00
|
|
|
try:
|
|
|
|
opts, args = getopt.getopt(sys.argv[1:], 'q:v', ['queues=', 'verbose'])
|
|
|
|
except getopt.GetoptError:
|
|
|
|
usage()
|
|
|
|
sys.exit(2)
|
|
|
|
|
|
|
|
verbose = False
|
|
|
|
queue_slugs = None
|
|
|
|
queues = []
|
|
|
|
|
|
|
|
for o, a in opts:
|
|
|
|
if o in ('-v', '--verbose'):
|
|
|
|
verbose = True
|
|
|
|
if o in ('-q', '--queues'):
|
|
|
|
queue_slugs = a
|
|
|
|
|
|
|
|
if queue_slugs is not None:
|
|
|
|
queue_set = queue_slugs.split(',')
|
|
|
|
for queue in queue_set:
|
|
|
|
try:
|
|
|
|
q = Queue.objects.get(slug__exact=queue)
|
|
|
|
except:
|
|
|
|
print "Queue %s does not exist." % queue
|
|
|
|
sys.exit(2)
|
|
|
|
queues.append(queue)
|
|
|
|
|
|
|
|
escalate_tickets(queues=queues, verbose=verbose)
|