2018-01-20 14:22:09 +00:00
|
|
|
from django.views.generic import TemplateView
|
2018-01-12 07:43:26 +00:00
|
|
|
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 _
|
2018-01-20 14:22:09 +00:00
|
|
|
from django.conf import settings
|
2016-09-03 11:05:50 +00:00
|
|
|
|
2018-01-20 14:22:09 +00:00
|
|
|
from .forms import EmailSettingForm, LDAPSettingForm, BasicSettingForm, \
|
|
|
|
TerminalSettingForm
|
2018-01-17 09:17:18 +00:00
|
|
|
from .models import Setting
|
2018-01-11 12:10:27 +00:00
|
|
|
from .mixins import AdminUserRequiredMixin
|
2018-01-12 07:43:26 +00:00
|
|
|
from .signals import ldap_auth_enable
|
2018-01-11 12:10:27 +00:00
|
|
|
|
|
|
|
|
2018-01-12 07:43:26 +00:00
|
|
|
class BasicSettingView(AdminUserRequiredMixin, TemplateView):
|
|
|
|
form_class = BasicSettingForm
|
|
|
|
template_name = "common/basic_setting.html"
|
|
|
|
|
|
|
|
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-01-15 05:54:19 +00:00
|
|
|
msg = _("Update setting successfully, please restart program")
|
|
|
|
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)
|
|
|
|
|
|
|
|
|
|
|
|
class EmailSettingView(AdminUserRequiredMixin, TemplateView):
|
2018-01-11 12:10:27 +00:00
|
|
|
form_class = EmailSettingForm
|
|
|
|
template_name = "common/email_setting.html"
|
|
|
|
|
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-01-15 05:54:19 +00:00
|
|
|
msg = _("Update setting successfully, please restart program")
|
|
|
|
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
|
|
|
|
2018-01-12 07:43:26 +00:00
|
|
|
class LDAPSettingView(AdminUserRequiredMixin, TemplateView):
|
|
|
|
form_class = LDAPSettingForm
|
|
|
|
template_name = "common/ldap_setting.html"
|
|
|
|
|
|
|
|
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-01-17 09:22:04 +00:00
|
|
|
if "AUTH_LDAP" in form.cleaned_data:
|
|
|
|
ldap_auth_enable.send(form.cleaned_data["AUTH_LDAP"])
|
2018-01-15 05:54:19 +00:00
|
|
|
msg = _("Update setting successfully, please restart program")
|
|
|
|
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
|
|
|
|
|
|
|
|
2018-01-20 14:22:09 +00:00
|
|
|
class TerminalSettingView(AdminUserRequiredMixin, TemplateView):
|
|
|
|
form_class = TerminalSettingForm
|
|
|
|
template_name = "common/terminal_setting.html"
|
2018-01-17 09:17:18 +00:00
|
|
|
|
|
|
|
def get_context_data(self, **kwargs):
|
2018-01-20 14:22:09 +00:00
|
|
|
command_storage = settings.TERMINAL_COMMAND_STORAGE
|
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-01-20 14:22:09 +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()
|
|
|
|
msg = _("Update setting successfully, please restart program")
|
|
|
|
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)
|