2017-12-01 13:22:32 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
#
|
|
|
|
|
2019-07-03 14:28:20 +00:00
|
|
|
from django.views.generic import ListView, TemplateView
|
2017-12-01 13:22:32 +00:00
|
|
|
from django.views.generic.edit import SingleObjectMixin
|
|
|
|
from django.utils.translation import ugettext as _
|
|
|
|
from django.utils import timezone
|
|
|
|
from django.conf import settings
|
|
|
|
|
2019-09-12 10:56:26 +00:00
|
|
|
from common.permissions import PermissionsMixin, IsOrgAdmin, IsOrgAuditor
|
2017-12-26 17:29:23 +00:00
|
|
|
from common.mixins import DatetimeSearchMixin
|
2017-12-01 13:22:32 +00:00
|
|
|
from ..models import Session, Command, Terminal
|
2018-05-22 10:22:06 +00:00
|
|
|
from ..backends import get_multi_command_storage
|
2017-12-04 08:41:00 +00:00
|
|
|
from .. import utils
|
2017-12-01 13:22:32 +00:00
|
|
|
|
|
|
|
|
|
|
|
__all__ = [
|
|
|
|
'SessionOnlineListView', 'SessionOfflineListView',
|
2017-12-03 16:21:26 +00:00
|
|
|
'SessionDetailView',
|
2017-12-01 13:22:32 +00:00
|
|
|
]
|
|
|
|
|
2017-12-03 16:21:26 +00:00
|
|
|
|
2019-07-03 14:28:20 +00:00
|
|
|
class SessionListView(PermissionsMixin, TemplateView):
|
2017-12-01 13:22:32 +00:00
|
|
|
model = Session
|
2017-12-04 08:41:00 +00:00
|
|
|
template_name = 'terminal/session_list.html'
|
2017-12-26 17:29:23 +00:00
|
|
|
date_from = date_to = None
|
2019-09-12 10:56:26 +00:00
|
|
|
permission_classes = [IsOrgAdmin | IsOrgAuditor]
|
2019-07-03 14:28:20 +00:00
|
|
|
default_days_ago = 5
|
2017-12-01 13:22:32 +00:00
|
|
|
|
|
|
|
def get_context_data(self, **kwargs):
|
2019-07-03 14:28:20 +00:00
|
|
|
now = timezone.now()
|
2017-12-01 13:22:32 +00:00
|
|
|
context = {
|
2019-07-03 14:28:20 +00:00
|
|
|
'date_from': now - timezone.timedelta(days=self.default_days_ago),
|
|
|
|
'date_to': now,
|
2017-12-01 13:22:32 +00:00
|
|
|
}
|
|
|
|
kwargs.update(context)
|
|
|
|
return super().get_context_data(**kwargs)
|
|
|
|
|
|
|
|
|
|
|
|
class SessionOnlineListView(SessionListView):
|
|
|
|
def get_context_data(self, **kwargs):
|
|
|
|
context = {
|
2019-06-20 10:10:44 +00:00
|
|
|
'app': _('Sessions'),
|
2017-12-01 13:22:32 +00:00
|
|
|
'action': _('Session online list'),
|
2018-03-07 03:28:42 +00:00
|
|
|
'type': 'online',
|
2017-12-01 13:22:32 +00:00
|
|
|
}
|
|
|
|
kwargs.update(context)
|
|
|
|
return super().get_context_data(**kwargs)
|
|
|
|
|
|
|
|
|
|
|
|
class SessionOfflineListView(SessionListView):
|
|
|
|
def get_context_data(self, **kwargs):
|
|
|
|
context = {
|
2019-06-20 10:10:44 +00:00
|
|
|
'app': _('Sessions'),
|
|
|
|
'action': _('Session offline'),
|
2019-07-03 14:28:20 +00:00
|
|
|
'type': 'offline',
|
2017-12-01 13:22:32 +00:00
|
|
|
}
|
|
|
|
kwargs.update(context)
|
|
|
|
return super().get_context_data(**kwargs)
|
|
|
|
|
|
|
|
|
2019-06-19 02:47:26 +00:00
|
|
|
class SessionDetailView(SingleObjectMixin, PermissionsMixin, ListView):
|
2017-12-03 16:21:26 +00:00
|
|
|
template_name = 'terminal/session_detail.html'
|
|
|
|
model = Session
|
2017-12-14 13:27:14 +00:00
|
|
|
object = None
|
2019-09-12 10:56:26 +00:00
|
|
|
permission_classes = [IsOrgAdmin | IsOrgAuditor]
|
2017-12-03 16:21:26 +00:00
|
|
|
|
2017-12-15 09:07:52 +00:00
|
|
|
def get(self, request, *args, **kwargs):
|
|
|
|
self.object = self.get_object(queryset=self.model.objects.all())
|
|
|
|
return super().get(request, *args, **kwargs)
|
|
|
|
|
2017-12-03 16:21:26 +00:00
|
|
|
def get_queryset(self):
|
2019-05-22 02:25:53 +00:00
|
|
|
command_store = get_multi_command_storage()
|
2017-12-03 16:21:26 +00:00
|
|
|
return command_store.filter(session=self.object.id)
|
|
|
|
|
|
|
|
def get_context_data(self, **kwargs):
|
|
|
|
context = {
|
2019-06-20 10:10:44 +00:00
|
|
|
'app': _('Sessions'),
|
2017-12-03 16:21:26 +00:00
|
|
|
'action': _('Session detail'),
|
|
|
|
}
|
|
|
|
kwargs.update(context)
|
|
|
|
return super().get_context_data(**kwargs)
|
2017-12-01 13:22:32 +00:00
|
|
|
|