2016-11-16 06:20:44 +00:00
|
|
|
# ~*~ coding: utf-8 ~*~
|
2017-03-13 16:58:25 +00:00
|
|
|
|
2017-12-20 03:30:15 +00:00
|
|
|
from django.utils.translation import ugettext as _
|
2016-11-16 06:20:44 +00:00
|
|
|
from django.conf import settings
|
2019-09-19 13:21:05 +00:00
|
|
|
from django.views.generic import ListView, DetailView, TemplateView
|
2016-11-16 06:20:44 +00:00
|
|
|
|
2017-12-26 17:29:23 +00:00
|
|
|
from common.mixins import DatetimeSearchMixin
|
2019-06-19 02:47:26 +00:00
|
|
|
from common.permissions import PermissionsMixin, IsOrgAdmin
|
2018-12-10 02:11:54 +00:00
|
|
|
from orgs.utils import current_org
|
|
|
|
from ..models import Task, AdHoc, AdHocRunHistory
|
2016-11-16 06:20:44 +00:00
|
|
|
|
|
|
|
|
2018-12-10 02:11:54 +00:00
|
|
|
__all__ = [
|
|
|
|
'TaskListView', 'TaskDetailView', 'TaskHistoryView',
|
|
|
|
'TaskAdhocView', 'AdHocDetailView', 'AdHocHistoryDetailView',
|
|
|
|
'AdHocHistoryView'
|
|
|
|
]
|
|
|
|
|
|
|
|
|
2019-09-19 13:21:05 +00:00
|
|
|
class TaskListView(PermissionsMixin, TemplateView):
|
2018-01-12 07:43:26 +00:00
|
|
|
paginate_by = settings.DISPLAY_PER_PAGE
|
2017-12-10 16:29:25 +00:00
|
|
|
model = Task
|
|
|
|
ordering = ('-date_created',)
|
2017-03-22 13:57:05 +00:00
|
|
|
context_object_name = 'task_list'
|
|
|
|
template_name = 'ops/task_list.html'
|
2017-12-26 17:29:23 +00:00
|
|
|
keyword = ''
|
2019-06-19 02:47:26 +00:00
|
|
|
permission_classes = [IsOrgAdmin]
|
2017-03-22 13:57:05 +00:00
|
|
|
|
2016-12-19 06:07:21 +00:00
|
|
|
def get_context_data(self, **kwargs):
|
|
|
|
context = {
|
2018-01-01 07:08:33 +00:00
|
|
|
'app': _('Ops'),
|
2017-12-20 03:30:15 +00:00
|
|
|
'action': _('Task list'),
|
2016-12-19 06:07:21 +00:00
|
|
|
}
|
|
|
|
kwargs.update(context)
|
2017-12-26 17:29:23 +00:00
|
|
|
return super().get_context_data(**kwargs)
|
2017-03-13 16:58:25 +00:00
|
|
|
|
|
|
|
|
2019-06-19 02:47:26 +00:00
|
|
|
class TaskDetailView(PermissionsMixin, DetailView):
|
2017-12-10 16:29:25 +00:00
|
|
|
model = Task
|
2017-03-22 13:57:05 +00:00
|
|
|
template_name = 'ops/task_detail.html'
|
2019-06-19 02:47:26 +00:00
|
|
|
permission_classes = [IsOrgAdmin]
|
2016-12-19 06:07:21 +00:00
|
|
|
|
2018-12-10 02:11:54 +00:00
|
|
|
def get_queryset(self):
|
|
|
|
queryset = super().get_queryset()
|
2018-12-17 03:44:43 +00:00
|
|
|
# Todo: 需要整理默认组织等东西
|
|
|
|
if current_org.is_real():
|
2018-12-10 02:11:54 +00:00
|
|
|
queryset = queryset.filter(created_by=current_org.id)
|
2018-12-17 03:44:43 +00:00
|
|
|
else:
|
|
|
|
queryset = queryset.filter(created_by='')
|
2018-12-10 02:11:54 +00:00
|
|
|
return queryset
|
|
|
|
|
2017-03-13 16:58:25 +00:00
|
|
|
def get_context_data(self, **kwargs):
|
|
|
|
context = {
|
2018-01-01 07:08:33 +00:00
|
|
|
'app': _('Ops'),
|
|
|
|
'action': _('Task detail'),
|
2017-03-13 16:58:25 +00:00
|
|
|
}
|
|
|
|
kwargs.update(context)
|
2017-12-10 16:29:25 +00:00
|
|
|
return super().get_context_data(**kwargs)
|
|
|
|
|
|
|
|
|
2019-06-19 02:47:26 +00:00
|
|
|
class TaskAdhocView(PermissionsMixin, DetailView):
|
2017-12-10 16:29:25 +00:00
|
|
|
model = Task
|
|
|
|
template_name = 'ops/task_adhoc.html'
|
2019-06-19 02:47:26 +00:00
|
|
|
permission_classes = [IsOrgAdmin]
|
2017-12-10 16:29:25 +00:00
|
|
|
|
|
|
|
def get_context_data(self, **kwargs):
|
|
|
|
context = {
|
2018-01-01 07:08:33 +00:00
|
|
|
'app': _('Ops'),
|
|
|
|
'action': _('Task versions'),
|
2017-12-10 16:29:25 +00:00
|
|
|
}
|
|
|
|
kwargs.update(context)
|
|
|
|
return super().get_context_data(**kwargs)
|
|
|
|
|
|
|
|
|
2019-06-19 02:47:26 +00:00
|
|
|
class TaskHistoryView(PermissionsMixin, DetailView):
|
2017-12-10 16:29:25 +00:00
|
|
|
model = Task
|
|
|
|
template_name = 'ops/task_history.html'
|
2019-06-19 02:47:26 +00:00
|
|
|
permission_classes = [IsOrgAdmin]
|
2017-12-10 16:29:25 +00:00
|
|
|
|
|
|
|
def get_context_data(self, **kwargs):
|
|
|
|
context = {
|
2018-01-01 07:08:33 +00:00
|
|
|
'app': _('Ops'),
|
|
|
|
'action': _('Task run history'),
|
2017-12-10 16:29:25 +00:00
|
|
|
}
|
|
|
|
kwargs.update(context)
|
|
|
|
return super().get_context_data(**kwargs)
|
2017-03-22 13:57:05 +00:00
|
|
|
|
|
|
|
|
2019-06-19 02:47:26 +00:00
|
|
|
class AdHocDetailView(PermissionsMixin, DetailView):
|
2017-12-20 03:30:15 +00:00
|
|
|
model = AdHoc
|
|
|
|
template_name = 'ops/adhoc_detail.html'
|
2019-06-19 02:47:26 +00:00
|
|
|
permission_classes = [IsOrgAdmin]
|
2017-12-20 03:30:15 +00:00
|
|
|
|
|
|
|
def get_context_data(self, **kwargs):
|
|
|
|
context = {
|
2018-01-01 07:08:33 +00:00
|
|
|
'app': _('Ops'),
|
2017-12-20 03:30:15 +00:00
|
|
|
'action': 'Task version detail',
|
|
|
|
}
|
|
|
|
kwargs.update(context)
|
|
|
|
return super().get_context_data(**kwargs)
|
|
|
|
|
|
|
|
|
2019-06-19 02:47:26 +00:00
|
|
|
class AdHocHistoryView(PermissionsMixin, DetailView):
|
2017-12-20 03:30:15 +00:00
|
|
|
model = AdHoc
|
|
|
|
template_name = 'ops/adhoc_history.html'
|
2019-06-19 02:47:26 +00:00
|
|
|
permission_classes = [IsOrgAdmin]
|
2017-12-20 03:30:15 +00:00
|
|
|
|
|
|
|
def get_context_data(self, **kwargs):
|
|
|
|
context = {
|
2018-01-01 07:08:33 +00:00
|
|
|
'app': _('Ops'),
|
|
|
|
'action': _('Version run history'),
|
2017-12-20 03:30:15 +00:00
|
|
|
}
|
|
|
|
kwargs.update(context)
|
|
|
|
return super().get_context_data(**kwargs)
|
|
|
|
|
|
|
|
|
2019-06-19 02:47:26 +00:00
|
|
|
class AdHocHistoryDetailView(PermissionsMixin, DetailView):
|
2017-12-20 03:30:15 +00:00
|
|
|
model = AdHocRunHistory
|
|
|
|
template_name = 'ops/adhoc_history_detail.html'
|
2019-06-19 02:47:26 +00:00
|
|
|
permission_classes = [IsOrgAdmin]
|
2017-12-20 03:30:15 +00:00
|
|
|
|
2018-03-30 14:03:43 +00:00
|
|
|
def get_context_data(self, **kwargs):
|
|
|
|
context = {
|
|
|
|
'app': _('Ops'),
|
|
|
|
'action': _('Run history detail'),
|
|
|
|
}
|
|
|
|
kwargs.update(context)
|
|
|
|
return super().get_context_data(**kwargs)
|
|
|
|
|
|
|
|
|
2018-12-10 02:11:54 +00:00
|
|
|
|
|
|
|
|