jumpserver/apps/tickets/views.py

42 lines
1.4 KiB
Python
Raw Normal View History

from django.views.generic import TemplateView, DetailView
from django.utils.translation import ugettext as _
2019-10-25 03:27:50 +00:00
2019-11-08 07:48:01 +00:00
from common.permissions import PermissionsMixin, IsValidUser
2019-11-15 10:55:35 +00:00
from .models import Ticket
2019-11-08 07:48:01 +00:00
from . import mixins
2019-11-15 10:55:35 +00:00
class TicketListView(PermissionsMixin, TemplateView):
template_name = 'tickets/ticket_list.html'
2019-11-08 07:48:01 +00:00
permission_classes = (IsValidUser,)
def get_context_data(self, **kwargs):
2019-11-15 10:55:35 +00:00
assign = self.request.GET.get('assign', '0') == '1'
context = super().get_context_data(**kwargs)
2019-11-18 10:44:21 +00:00
assigned_open_count = Ticket.get_assigned_tickets(self.request.user)\
.filter(status=Ticket.STATUS_OPEN).count()
context.update({
2019-11-07 10:06:58 +00:00
'app': _("Tickets"),
2019-11-15 10:55:35 +00:00
'action': _("Ticket list"),
'assign': assign,
2019-11-18 10:44:21 +00:00
'assigned_open_count': assigned_open_count
})
return context
2019-11-15 10:55:35 +00:00
class TicketDetailView(PermissionsMixin, mixins.TicketMixin, DetailView):
template_name = 'tickets/ticket_detail.html'
2019-11-08 07:48:01 +00:00
permission_classes = (IsValidUser,)
2019-11-15 10:55:35 +00:00
queryset = Ticket.objects.all()
def get_context_data(self, **kwargs):
2019-11-18 03:54:12 +00:00
ticket = self.get_object()
has_action_perm = ticket.is_assignee(self.request.user)
context = super().get_context_data(**kwargs)
context.update({
2019-11-07 10:06:58 +00:00
'app': _("Tickets"),
2019-11-18 03:54:12 +00:00
'action': _("Ticket detail"),
'has_action_perm': has_action_perm,
})
return context