|
|
from django.db import transaction
|
|
|
from django.shortcuts import render, redirect
|
|
|
|
|
|
from boards.abstracts.settingsmanager import get_settings_manager
|
|
|
from boards.views.base import BaseBoardView, CONTEXT_FORM
|
|
|
from boards.forms import SettingsForm, PlainErrorList
|
|
|
|
|
|
FORM_THEME = 'theme'
|
|
|
|
|
|
CONTEXT_HIDDEN_TAGS = 'hidden_tags'
|
|
|
|
|
|
|
|
|
class SettingsView(BaseBoardView):
|
|
|
|
|
|
def get(self, request):
|
|
|
context = self.get_context_data(request=request)
|
|
|
settings_manager = get_settings_manager(request)
|
|
|
|
|
|
selected_theme = settings_manager.get_theme()
|
|
|
|
|
|
form = SettingsForm(initial={FORM_THEME: selected_theme},
|
|
|
error_class=PlainErrorList)
|
|
|
|
|
|
context[CONTEXT_FORM] = form
|
|
|
context[CONTEXT_HIDDEN_TAGS] = settings_manager.get_hidden_tags()
|
|
|
|
|
|
# TODO Use dict here
|
|
|
return render(request, 'boards/settings.html', context_instance=context)
|
|
|
|
|
|
def post(self, request):
|
|
|
settings_manager = get_settings_manager(request)
|
|
|
|
|
|
with transaction.atomic():
|
|
|
form = SettingsForm(request.POST, error_class=PlainErrorList)
|
|
|
|
|
|
if form.is_valid():
|
|
|
selected_theme = form.cleaned_data[FORM_THEME]
|
|
|
|
|
|
settings_manager.set_theme(selected_theme)
|
|
|
|
|
|
return redirect('settings')
|
|
|
|