Add support for YAML configuration files. Add support for editing setting options and saving them using the new YAML configuration file support. Add new revertsettings management command. Add new permission to edit setting via the UI.
Signed-off-by: Roberto Rosario <roberto.rosario.gonzalez@gmail.com>
This commit is contained in:
@@ -1,12 +1,15 @@
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django.contrib import messages
|
||||
from django.http import Http404
|
||||
from django.urls import reverse
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
|
||||
from common.views import SingleObjectListView
|
||||
from common.views import FormView, SingleObjectListView
|
||||
|
||||
from .classes import Namespace
|
||||
from .permissions import permission_settings_view
|
||||
from .classes import Namespace, Setting
|
||||
from .forms import SettingForm
|
||||
from .permissions import permission_settings_edit, permission_settings_view
|
||||
|
||||
|
||||
class NamespaceListView(SingleObjectListView):
|
||||
@@ -39,3 +42,35 @@ class NamespaceDetailView(SingleObjectListView):
|
||||
|
||||
def get_object_list(self):
|
||||
return self.get_namespace().settings
|
||||
|
||||
|
||||
class SettingEditView(FormView):
|
||||
form_class = SettingForm
|
||||
view_permission = permission_settings_edit
|
||||
|
||||
def form_valid(self, form):
|
||||
self.get_object().value = form.cleaned_data['value']
|
||||
Setting.save_configuration()
|
||||
messages.success(
|
||||
self.request, _('Setting updated successfully.')
|
||||
)
|
||||
return super(SettingEditView, self).form_valid(form=form)
|
||||
|
||||
def get_extra_context(self):
|
||||
return {
|
||||
'hide_link': True,
|
||||
'title': _('Edit setting: %s') % self.get_object(),
|
||||
}
|
||||
|
||||
def get_initial(self):
|
||||
return {'setting': self.get_object()}
|
||||
|
||||
def get_object(self):
|
||||
return Setting.get(self.kwargs['setting_global_name'])
|
||||
|
||||
def get_post_action_redirect(self):
|
||||
return reverse(
|
||||
'settings:namespace_detail', args=(
|
||||
self.get_object().namespace.name,
|
||||
)
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user