2008-02-08 06:29:51 +01:00
|
|
|
from django.contrib.auth.models import User
|
|
|
|
from django.contrib.syndication.feeds import Feed
|
|
|
|
from django.core.urlresolvers import reverse
|
|
|
|
from django.db.models import Q
|
2008-05-07 11:04:18 +02:00
|
|
|
from django.utils.translation import ugettext as _
|
2008-02-08 06:29:51 +01:00
|
|
|
|
2008-05-21 23:16:44 +02:00
|
|
|
from helpdesk.models import Ticket, FollowUp, Queue
|
2008-02-08 06:29:51 +01:00
|
|
|
|
|
|
|
|
|
|
|
class OpenTicketsByUser(Feed):
|
|
|
|
title_template = 'helpdesk/rss/ticket_title.html'
|
|
|
|
description_template = 'helpdesk/rss/ticket_description.html'
|
|
|
|
|
|
|
|
def get_object(self, bits):
|
|
|
|
if len(bits) < 1:
|
|
|
|
raise ObjectDoesNotExist
|
|
|
|
user = User.objects.get(username__exact=bits[0])
|
|
|
|
if len(bits) == 2:
|
|
|
|
queue = Queue.objects.get(slug__exact=bits[1])
|
|
|
|
else: queue = False
|
|
|
|
|
|
|
|
return {'user': user, 'queue': queue}
|
|
|
|
|
|
|
|
def title(self, obj):
|
|
|
|
if obj['queue']:
|
2008-05-07 11:04:18 +02:00
|
|
|
return _("Helpdesk: Open Tickets in queue %(queue)s for %(username)s") % {'queue': obj['queue'].title, 'username': obj['user'].username}
|
2008-02-08 06:29:51 +01:00
|
|
|
else:
|
2008-05-07 11:04:18 +02:00
|
|
|
return _("Helpdesk: Open Tickets for %(username)s") % {'username': obj['user'].username}
|
2008-02-08 06:29:51 +01:00
|
|
|
|
|
|
|
def description(self, obj):
|
|
|
|
if obj['queue']:
|
2008-05-07 11:04:18 +02:00
|
|
|
return _("Open and Reopened Tickets in queue %(queue)s for %(username)s") % {'queue': obj['queue'].title, 'username': obj['user'].username}
|
2008-02-08 06:29:51 +01:00
|
|
|
else:
|
2008-05-07 11:04:18 +02:00
|
|
|
return _("Open and Reopened Tickets for %(username)s") % {'username': obj['user'].username}
|
2008-02-08 06:29:51 +01:00
|
|
|
|
|
|
|
def link(self, obj):
|
|
|
|
if obj['queue']:
|
2008-05-07 11:04:18 +02:00
|
|
|
return u'%s?assigned_to=%s&queue=%s' % (reverse('helpdesk_list'), obj['user'].id, obj['queue'].id)
|
2008-02-08 06:29:51 +01:00
|
|
|
else:
|
2008-05-07 11:04:18 +02:00
|
|
|
return u'%s?assigned_to=%s' % (reverse('helpdesk_list'), obj['user'].id)
|
2008-02-08 06:29:51 +01:00
|
|
|
|
|
|
|
def items(self, obj):
|
|
|
|
if obj['queue']:
|
|
|
|
return Ticket.objects.filter(assigned_to=obj['user']).filter(queue=obj['queue']).filter(Q(status=Ticket.OPEN_STATUS) | Q(status=Ticket.REOPENED_STATUS))
|
|
|
|
else:
|
|
|
|
return Ticket.objects.filter(assigned_to=obj['user']).filter(Q(status=Ticket.OPEN_STATUS) | Q(status=Ticket.REOPENED_STATUS))
|
|
|
|
|
|
|
|
def item_pubdate(self, item):
|
|
|
|
return item.created
|
|
|
|
|
|
|
|
def item_author_name(self, item):
|
|
|
|
if item.assigned_to:
|
|
|
|
return item.assigned_to.username
|
|
|
|
else:
|
2008-05-07 11:04:18 +02:00
|
|
|
return _('Unassigned')
|
2008-02-08 06:29:51 +01:00
|
|
|
|
|
|
|
|
|
|
|
class UnassignedTickets(Feed):
|
|
|
|
title_template = 'helpdesk/rss/ticket_title.html'
|
|
|
|
description_template = 'helpdesk/rss/ticket_description.html'
|
|
|
|
|
2008-05-07 11:04:18 +02:00
|
|
|
title = _('Helpdesk: Unassigned Tickets')
|
|
|
|
description = _('Unassigned Open and Reopened tickets')
|
2008-02-08 06:29:51 +01:00
|
|
|
link = ''#%s?assigned_to=' % reverse('helpdesk_list')
|
|
|
|
|
|
|
|
def items(self, obj):
|
|
|
|
return Ticket.objects.filter(assigned_to__isnull=True).filter(Q(status=Ticket.OPEN_STATUS) | Q(status=Ticket.REOPENED_STATUS))
|
|
|
|
|
|
|
|
def item_pubdate(self, item):
|
|
|
|
return item.created
|
|
|
|
|
|
|
|
|
|
|
|
def item_author_name(self, item):
|
|
|
|
if item.assigned_to:
|
|
|
|
return item.assigned_to.username
|
|
|
|
else:
|
2008-05-07 11:04:18 +02:00
|
|
|
return _('Unassigned')
|
2008-02-08 06:29:51 +01:00
|
|
|
|
|
|
|
|
|
|
|
class RecentFollowUps(Feed):
|
|
|
|
title_template = 'helpdesk/rss/recent_activity_title.html'
|
|
|
|
description_template = 'helpdesk/rss/recent_activity_description.html'
|
|
|
|
|
2008-05-07 11:04:18 +02:00
|
|
|
title = _('Helpdesk: Recent Followups')
|
|
|
|
description = _('Recent FollowUps, such as e-mail replies, comments, attachments and resolutions')
|
2008-02-08 06:29:51 +01:00
|
|
|
link = '/tickets/' # reverse('helpdesk_list')
|
|
|
|
|
|
|
|
def items(self):
|
|
|
|
return FollowUp.objects.order_by('-date')[:20]
|
|
|
|
|
|
|
|
|
|
|
|
class OpenTicketsByQueue(Feed):
|
|
|
|
title_template = 'helpdesk/rss/ticket_title.html'
|
|
|
|
description_template = 'helpdesk/rss/ticket_description.html'
|
|
|
|
|
|
|
|
def get_object(self, bits):
|
|
|
|
if len(bits) != 1:
|
|
|
|
raise ObjectDoesNotExist
|
|
|
|
return Queue.objects.get(slug__exact=bits[0])
|
|
|
|
|
|
|
|
def title(self, obj):
|
2008-05-07 11:04:18 +02:00
|
|
|
return _('Helpdesk: Open Tickets in queue %(queue)s') % {'queue': obj.title}
|
2008-02-08 06:29:51 +01:00
|
|
|
|
|
|
|
def description(self, obj):
|
2008-05-07 11:04:18 +02:00
|
|
|
return _('Open and Reopened Tickets in queue %(queue)s') % {'queue': obj.title}
|
2008-02-08 06:29:51 +01:00
|
|
|
|
|
|
|
def link(self, obj):
|
|
|
|
return '%s?queue=%s' % (reverse('helpdesk_list'), obj.id)
|
|
|
|
|
|
|
|
def items(self, obj):
|
|
|
|
return Ticket.objects.filter(queue=obj).filter(Q(status=Ticket.OPEN_STATUS) | Q(status=Ticket.REOPENED_STATUS))
|
|
|
|
|
|
|
|
def item_pubdate(self, item):
|
|
|
|
return item.created
|
|
|
|
|
|
|
|
def item_author_name(self, item):
|
|
|
|
if item.assigned_to:
|
|
|
|
return item.assigned_to.username
|
|
|
|
else:
|
2008-05-07 11:04:18 +02:00
|
|
|
return _('Unassigned')
|
2008-02-08 06:29:51 +01:00
|
|
|
|
|
|
|
|
|
|
|
feed_setup = {
|
|
|
|
'user': OpenTicketsByUser,
|
|
|
|
'queue': OpenTicketsByQueue,
|
|
|
|
'recent_activity': RecentFollowUps,
|
|
|
|
'unassigned': UnassignedTickets,
|
|
|
|
}
|
|
|
|
|