jumpserver/apps/assets/views.py

107 lines
3.0 KiB
Python
Raw Normal View History

2016-09-04 10:06:14 +00:00
# coding:utf-8
2016-09-04 08:02:51 +00:00
from __future__ import absolute_import, unicode_literals
2016-08-14 14:10:10 +00:00
2016-09-04 11:05:47 +00:00
from django.utils.translation import ugettext as _
2016-09-05 16:49:42 +00:00
from django.shortcuts import get_object_or_404
2016-09-04 09:43:03 +00:00
from django.views.generic import TemplateView, ListView
2016-08-14 14:10:10 +00:00
from django.urls import reverse_lazy
2016-09-04 09:43:03 +00:00
from django.views.generic.edit import CreateView, DeleteView, FormView, UpdateView
2016-09-04 08:02:51 +00:00
from django.views.generic import TemplateView, ListView
from django.views.generic.edit import CreateView, DeleteView, FormView, UpdateView
2016-08-14 14:10:10 +00:00
from django.urls import reverse_lazy
2016-09-04 08:02:51 +00:00
from django.views.generic.detail import DetailView
2016-09-05 16:49:42 +00:00
2016-09-04 08:02:51 +00:00
from .models import Asset, AssetGroup, IDC, AssetExtend
2016-09-04 11:05:47 +00:00
from .forms import AssetForm, AssetGroupForm
2016-09-04 09:43:03 +00:00
from .utils import AdminUserRequiredMixin
2016-08-14 14:10:10 +00:00
class AssetCreateView(CreateView):
2016-08-14 14:10:10 +00:00
model = Asset
form_class = AssetForm
template_name = 'assets/asset_create.html'
2016-08-14 14:10:10 +00:00
success_url = reverse_lazy('assets:asset-list')
2016-09-04 09:43:03 +00:00
def form_invalid(self, form):
print(form.errors)
return super(AssetCreateView, self).form_invalid(form)
2016-09-04 09:43:03 +00:00
2016-08-14 14:10:10 +00:00
class AssetUpdateView(UpdateView):
2016-08-14 14:10:10 +00:00
pass
class AssetDeleteView(DeleteView):
model = Asset
success_url = reverse_lazy('assets:asset-list')
class AssetListView(ListView):
model = Asset
context_object_name = 'assets'
template_name = 'assets/asset_list.html'
class AssetDetailView(DetailView):
model = Asset
context_object_name = 'asset'
template_name = 'assets/asset_detail.html'
2016-08-08 16:43:11 +00:00
2016-09-04 08:02:51 +00:00
class AssetGroupCreateView(CreateView):
2016-09-04 10:07:15 +00:00
model = AssetGroup
2016-09-04 11:05:47 +00:00
form_class = AssetGroupForm
template_name = 'assets/asset_group_create.html'
success_url = reverse_lazy('assets:asset-group-list')
2016-09-04 08:02:51 +00:00
2016-09-04 11:05:47 +00:00
def get_context_data(self, **kwargs):
context = {
'app': _('Assets'),
'action': _('Create asset group'),
'assets': Asset.objects.all(),
}
kwargs.update(context)
return super(AssetGroupCreateView, self).get_context_data(**kwargs)
def form_valid(self, form):
print(form.data)
return super(AssetGroupCreateView, self).form_valid(form)
2016-09-04 11:05:47 +00:00
2016-09-04 08:02:51 +00:00
class AssetGroupListView(ListView):
2016-09-04 11:05:47 +00:00
model = AssetGroup
context_object_name = 'asset_group_list'
template_name = 'assets/asset_group_list.html'
2016-09-04 11:05:47 +00:00
def get_context_data(self, **kwargs):
context = {
'app': _('Assets'),
'action': _('Asset group list')
}
kwargs.update(context)
return super(AssetGroupListView, self).get_context_data(**kwargs)
2016-09-04 08:02:51 +00:00
class AssetGroupDetailView(DetailView):
pass
class AssetGroupUpdateView(UpdateView):
2016-09-05 16:49:42 +00:00
model = AssetGroup
form_class = AssetGroupForm
template_name = 'assets/asset_group_create.html'
success_url = reverse_lazy('assets:asset-group-list')
2016-09-05 16:49:42 +00:00
def get_context_data(self, **kwargs):
context = {
'app': _('Assets'),
'action': _('Create asset group'),
'assets': Asset.objects.all(),
}
kwargs.update(context)
return super(AssetGroupUpdateView, self).get_context_data(**kwargs)
2016-09-04 08:02:51 +00:00
class AssetGroupDeleteView(DeleteView):
pass