jumpserver/apps/applications/views.py

77 lines
2.2 KiB
Python
Raw Normal View History

2016-10-16 14:12:13 +00:00
# ~*~ coding: utf-8 ~*~
#
2016-12-26 16:59:52 +00:00
from django.views.generic import ListView, UpdateView, DeleteView, FormView
2016-12-29 16:19:47 +00:00
from django.views.generic.edit import BaseUpdateView
2016-10-16 14:12:13 +00:00
from django.utils.translation import ugettext as _
2016-10-19 10:33:14 +00:00
from django.urls import reverse_lazy
2016-10-16 14:12:13 +00:00
from .models import Terminal
2016-12-26 16:59:52 +00:00
from users.utils import AdminUserRequiredMixin
from common.mixins import JSONResponseMixin
2016-10-19 10:33:14 +00:00
from .forms import TerminalForm
2016-10-16 14:12:13 +00:00
class TerminalListView(ListView):
model = Terminal
template_name = 'applications/terminal_list.html'
2016-12-26 16:59:52 +00:00
form_class = TerminalForm
2016-10-16 14:12:13 +00:00
def get_context_data(self, **kwargs):
context = super(TerminalListView, self).get_context_data(**kwargs)
2016-12-26 16:59:52 +00:00
context.update({
'app': _('Terminal'),
'action': _('Terminal list'),
'form': self.form_class()
})
2016-10-16 14:12:13 +00:00
return context
2016-10-19 10:33:14 +00:00
class TerminalUpdateView(UpdateView):
model = Terminal
form_class = TerminalForm
template_name = 'applications/terminal_update.html'
success_url = reverse_lazy('applications:applications-list')
2016-10-19 10:33:14 +00:00
def get_context_data(self, **kwargs):
context = super(TerminalUpdateView, self).get_context_data(**kwargs)
context.update({'app': _('Terminal'), 'action': _('Update applications')})
2016-10-19 10:33:14 +00:00
return context
2016-10-24 11:32:53 +00:00
class TerminalDeleteView(DeleteView):
model = Terminal
template_name = 'assets/delete_confirm.html'
2016-12-26 16:59:52 +00:00
success_url = reverse_lazy('applications:applications-list')
2016-12-30 14:21:50 +00:00
class TerminalModelAccept(AdminUserRequiredMixin, JSONResponseMixin, UpdateView):
2016-12-26 16:59:52 +00:00
model = Terminal
form_class = TerminalForm
2016-12-30 14:21:50 +00:00
template_name = 'applications/terminal_modal_test.html'
2016-12-26 16:59:52 +00:00
2016-12-29 16:19:47 +00:00
def post(self, request, *args, **kwargs):
print(request.POST)
return super(TerminalModelAccept, self).post(request, *args, **kwargs)
2016-12-26 16:59:52 +00:00
def form_valid(self, form):
terminal = form.save()
terminal.is_accepted = True
2016-12-27 16:28:52 +00:00
terminal.is_active = True
2016-12-26 16:59:52 +00:00
terminal.save()
data = {
'success': True,
'msg': 'success'
}
return self.render_json_response(data)
def form_invalid(self, form):
2016-12-29 16:19:47 +00:00
print('form.data')
2016-12-26 16:59:52 +00:00
data = {
'success': False,
2016-12-29 16:19:47 +00:00
'msg': str(form.errors),
2016-12-26 16:59:52 +00:00
}
return self.render_json_response(data)