2018-07-23 04:55:13 +00:00
|
|
|
from django.views.generic import TemplateView
|
|
|
|
from django.shortcuts import render, redirect
|
2018-01-11 12:10:27 +00:00
|
|
|
from django.contrib import messages
|
|
|
|
from django.utils.translation import ugettext as _
|
2016-09-03 11:05:50 +00:00
|
|
|
|
2019-06-19 02:47:26 +00:00
|
|
|
from common.permissions import PermissionsMixin, IsSuperUser
|
2019-02-26 04:38:20 +00:00
|
|
|
from common import utils
|
2018-01-20 14:22:09 +00:00
|
|
|
from .forms import EmailSettingForm, LDAPSettingForm, BasicSettingForm, \
|
2019-05-24 10:12:58 +00:00
|
|
|
TerminalSettingForm, SecuritySettingForm, EmailContentSettingForm
|
2018-01-11 12:10:27 +00:00
|
|
|
|
|
|
|
|
2019-06-19 02:47:26 +00:00
|
|
|
class BasicSettingView(PermissionsMixin, TemplateView):
|
2018-01-12 07:43:26 +00:00
|
|
|
form_class = BasicSettingForm
|
2019-02-26 04:38:20 +00:00
|
|
|
template_name = "settings/basic_setting.html"
|
2019-06-19 02:47:26 +00:00
|
|
|
permission_classes = [IsSuperUser]
|
2018-01-12 07:43:26 +00:00
|
|
|
|
|
|
|
def get_context_data(self, **kwargs):
|
|
|
|
context = {
|
|
|
|
'app': _('Settings'),
|
|
|
|
'action': _('Basic setting'),
|
|
|
|
'form': self.form_class(),
|
|
|
|
}
|
|
|
|
kwargs.update(context)
|
|
|
|
return super().get_context_data(**kwargs)
|
|
|
|
|
|
|
|
def post(self, request):
|
|
|
|
form = self.form_class(request.POST)
|
|
|
|
if form.is_valid():
|
|
|
|
form.save()
|
2018-11-22 10:02:12 +00:00
|
|
|
msg = _("Update setting successfully")
|
2018-01-15 05:54:19 +00:00
|
|
|
messages.success(request, msg)
|
2018-01-12 07:43:26 +00:00
|
|
|
return redirect('settings:basic-setting')
|
|
|
|
else:
|
|
|
|
context = self.get_context_data()
|
|
|
|
context.update({"form": form})
|
|
|
|
return render(request, self.template_name, context)
|
|
|
|
|
|
|
|
|
2019-06-19 02:47:26 +00:00
|
|
|
class EmailSettingView(PermissionsMixin, TemplateView):
|
2018-01-11 12:10:27 +00:00
|
|
|
form_class = EmailSettingForm
|
2019-02-26 04:38:20 +00:00
|
|
|
template_name = "settings/email_setting.html"
|
2019-06-19 02:47:26 +00:00
|
|
|
permission_classes = [IsSuperUser]
|
2018-01-11 12:10:27 +00:00
|
|
|
|
2018-01-12 07:43:26 +00:00
|
|
|
def get_context_data(self, **kwargs):
|
2018-01-11 12:10:27 +00:00
|
|
|
context = {
|
2018-01-12 07:43:26 +00:00
|
|
|
'app': _('Settings'),
|
|
|
|
'action': _('Email setting'),
|
|
|
|
'form': self.form_class(),
|
2018-01-11 12:10:27 +00:00
|
|
|
}
|
2018-01-12 07:43:26 +00:00
|
|
|
kwargs.update(context)
|
|
|
|
return super().get_context_data(**kwargs)
|
2018-01-11 12:10:27 +00:00
|
|
|
|
|
|
|
def post(self, request):
|
|
|
|
form = self.form_class(request.POST)
|
|
|
|
if form.is_valid():
|
|
|
|
form.save()
|
2018-11-23 09:00:35 +00:00
|
|
|
msg = _("Update setting successfully")
|
2018-01-15 05:54:19 +00:00
|
|
|
messages.success(request, msg)
|
2018-01-12 07:43:26 +00:00
|
|
|
return redirect('settings:email-setting')
|
|
|
|
else:
|
|
|
|
context = self.get_context_data()
|
|
|
|
context.update({"form": form})
|
|
|
|
return render(request, self.template_name, context)
|
|
|
|
|
2018-01-11 12:10:27 +00:00
|
|
|
|
2019-06-19 02:47:26 +00:00
|
|
|
class LDAPSettingView(PermissionsMixin, TemplateView):
|
2018-01-12 07:43:26 +00:00
|
|
|
form_class = LDAPSettingForm
|
2019-02-26 04:38:20 +00:00
|
|
|
template_name = "settings/ldap_setting.html"
|
2019-06-19 02:47:26 +00:00
|
|
|
permission_classes = [IsSuperUser]
|
2018-01-12 07:43:26 +00:00
|
|
|
|
|
|
|
def get_context_data(self, **kwargs):
|
2018-01-11 12:10:27 +00:00
|
|
|
context = {
|
2018-01-12 07:43:26 +00:00
|
|
|
'app': _('Settings'),
|
|
|
|
'action': _('LDAP setting'),
|
|
|
|
'form': self.form_class(),
|
2018-01-11 12:10:27 +00:00
|
|
|
}
|
2018-01-12 07:43:26 +00:00
|
|
|
kwargs.update(context)
|
|
|
|
return super().get_context_data(**kwargs)
|
|
|
|
|
|
|
|
def post(self, request):
|
|
|
|
form = self.form_class(request.POST)
|
|
|
|
if form.is_valid():
|
|
|
|
form.save()
|
2018-11-22 10:02:12 +00:00
|
|
|
msg = _("Update setting successfully")
|
2018-01-15 05:54:19 +00:00
|
|
|
messages.success(request, msg)
|
2018-01-12 07:43:26 +00:00
|
|
|
return redirect('settings:ldap-setting')
|
|
|
|
else:
|
|
|
|
context = self.get_context_data()
|
|
|
|
context.update({"form": form})
|
|
|
|
return render(request, self.template_name, context)
|
2018-01-17 09:17:18 +00:00
|
|
|
|
|
|
|
|
2019-06-19 02:47:26 +00:00
|
|
|
class TerminalSettingView(PermissionsMixin, TemplateView):
|
2018-01-20 14:22:09 +00:00
|
|
|
form_class = TerminalSettingForm
|
2019-02-26 04:38:20 +00:00
|
|
|
template_name = "settings/terminal_setting.html"
|
2019-06-19 02:47:26 +00:00
|
|
|
permission_classes = [IsSuperUser]
|
2018-01-17 09:17:18 +00:00
|
|
|
|
|
|
|
def get_context_data(self, **kwargs):
|
2018-11-19 04:18:52 +00:00
|
|
|
command_storage = utils.get_command_storage_setting()
|
|
|
|
replay_storage = utils.get_replay_storage_setting()
|
2018-10-23 11:22:18 +00:00
|
|
|
|
2018-01-17 09:17:18 +00:00
|
|
|
context = {
|
|
|
|
'app': _('Settings'),
|
2018-01-20 14:22:09 +00:00
|
|
|
'action': _('Terminal setting'),
|
2018-01-17 09:17:18 +00:00
|
|
|
'form': self.form_class(),
|
2018-02-26 07:06:00 +00:00
|
|
|
'replay_storage': replay_storage,
|
2018-10-23 11:22:18 +00:00
|
|
|
'command_storage': command_storage
|
2018-01-17 09:17:18 +00:00
|
|
|
}
|
|
|
|
kwargs.update(context)
|
|
|
|
return super().get_context_data(**kwargs)
|
|
|
|
|
|
|
|
def post(self, request):
|
|
|
|
form = self.form_class(request.POST)
|
|
|
|
if form.is_valid():
|
|
|
|
form.save()
|
2018-11-22 10:02:12 +00:00
|
|
|
msg = _("Update setting successfully")
|
2018-01-17 09:17:18 +00:00
|
|
|
messages.success(request, msg)
|
2018-01-20 14:22:09 +00:00
|
|
|
return redirect('settings:terminal-setting')
|
2018-01-17 09:17:18 +00:00
|
|
|
else:
|
|
|
|
context = self.get_context_data()
|
|
|
|
context.update({"form": form})
|
|
|
|
return render(request, self.template_name, context)
|
2018-02-26 07:06:00 +00:00
|
|
|
|
2018-04-01 15:45:37 +00:00
|
|
|
|
2019-06-19 02:47:26 +00:00
|
|
|
class ReplayStorageCreateView(PermissionsMixin, TemplateView):
|
2019-02-26 04:38:20 +00:00
|
|
|
template_name = 'settings/replay_storage_create.html'
|
2019-06-19 02:47:26 +00:00
|
|
|
permission_classes = [IsSuperUser]
|
2018-10-23 11:22:18 +00:00
|
|
|
|
|
|
|
def get_context_data(self, **kwargs):
|
|
|
|
context = {
|
|
|
|
'app': _('Settings'),
|
|
|
|
'action': _('Create replay storage')
|
|
|
|
}
|
|
|
|
kwargs.update(context)
|
|
|
|
return super().get_context_data(**kwargs)
|
|
|
|
|
|
|
|
|
2019-06-19 02:47:26 +00:00
|
|
|
class CommandStorageCreateView(PermissionsMixin, TemplateView):
|
2019-02-26 04:38:20 +00:00
|
|
|
template_name = 'settings/command_storage_create.html'
|
2019-06-19 02:47:26 +00:00
|
|
|
permission_classes = [IsSuperUser]
|
2018-10-23 11:22:18 +00:00
|
|
|
|
|
|
|
def get_context_data(self, **kwargs):
|
|
|
|
context = {
|
|
|
|
'app': _('Settings'),
|
|
|
|
'action': _('Create command storage')
|
|
|
|
}
|
|
|
|
kwargs.update(context)
|
|
|
|
return super().get_context_data(**kwargs)
|
|
|
|
|
|
|
|
|
2019-06-19 02:47:26 +00:00
|
|
|
class SecuritySettingView(PermissionsMixin, TemplateView):
|
2018-06-05 09:26:31 +00:00
|
|
|
form_class = SecuritySettingForm
|
2019-02-26 04:38:20 +00:00
|
|
|
template_name = "settings/security_setting.html"
|
2019-06-19 02:47:26 +00:00
|
|
|
permission_classes = [IsSuperUser]
|
2018-06-05 09:26:31 +00:00
|
|
|
|
|
|
|
def get_context_data(self, **kwargs):
|
|
|
|
context = {
|
|
|
|
'app': _('Settings'),
|
|
|
|
'action': _('Security setting'),
|
|
|
|
'form': self.form_class(),
|
|
|
|
}
|
|
|
|
kwargs.update(context)
|
|
|
|
return super().get_context_data(**kwargs)
|
|
|
|
|
|
|
|
def post(self, request):
|
|
|
|
form = self.form_class(request.POST)
|
|
|
|
if form.is_valid():
|
|
|
|
form.save()
|
2018-11-22 10:02:12 +00:00
|
|
|
msg = _("Update setting successfully")
|
2018-06-05 09:26:31 +00:00
|
|
|
messages.success(request, msg)
|
|
|
|
return redirect('settings:security-setting')
|
|
|
|
else:
|
|
|
|
context = self.get_context_data()
|
|
|
|
context.update({"form": form})
|
|
|
|
return render(request, self.template_name, context)
|
2019-05-24 10:12:58 +00:00
|
|
|
|
|
|
|
|
2019-06-19 02:47:26 +00:00
|
|
|
class EmailContentSettingView(PermissionsMixin, TemplateView):
|
2019-05-24 10:12:58 +00:00
|
|
|
template_name = "settings/email_content_setting.html"
|
|
|
|
form_class = EmailContentSettingForm
|
2019-06-19 02:47:26 +00:00
|
|
|
permission_classes = [IsSuperUser]
|
2019-05-24 10:12:58 +00:00
|
|
|
|
|
|
|
def get_context_data(self, **kwargs):
|
|
|
|
context = {
|
|
|
|
'app': _('Settings'),
|
|
|
|
'action': _('Email content setting'),
|
|
|
|
'form': self.form_class(),
|
|
|
|
}
|
|
|
|
kwargs.update(context)
|
|
|
|
return super().get_context_data(**kwargs)
|
|
|
|
|
|
|
|
def post(self, request):
|
|
|
|
form = self.form_class(request.POST)
|
|
|
|
if form.is_valid():
|
|
|
|
form.save()
|
|
|
|
msg = _("Update setting successfully")
|
|
|
|
messages.success(request, msg)
|
|
|
|
return redirect('settings:email-content-setting')
|
|
|
|
else:
|
|
|
|
context = self.get_context_data()
|
|
|
|
context.update({"form": form})
|
|
|
|
return render(request, self.template_name, context)
|