settings.py
39 lines
| 1.2 KiB
| text/x-python
|
PythonLexer
|
r547 | from django.db import transaction | ||
from django.shortcuts import render, redirect | ||||
|
r730 | from boards.abstracts.settingsmanager import get_settings_manager | ||
|
r722 | from boards.views.base import BaseBoardView, CONTEXT_FORM | ||
|
r729 | from boards.forms import SettingsForm, PlainErrorList | ||
|
r547 | |||
|
r733 | CONTEXT_HIDDEN_TAGS = 'hidden_tags' | ||
|
r561 | |||
|
r547 | class SettingsView(BaseBoardView): | ||
def get(self, request): | ||||
context = self.get_context_data(request=request) | ||||
|
r730 | settings_manager = get_settings_manager(request) | ||
|
r547 | |||
|
r728 | selected_theme = settings_manager.get_theme() | ||
|
r547 | |||
|
r729 | form = SettingsForm(initial={'theme': selected_theme}, | ||
error_class=PlainErrorList) | ||||
|
r547 | |||
|
r722 | context[CONTEXT_FORM] = form | ||
|
r733 | context[CONTEXT_HIDDEN_TAGS] = settings_manager.get_hidden_tags() | ||
|
r547 | |||
|
r872 | # TODO Use dict here | ||
return render(request, 'boards/settings.html', context_instance=context) | ||||
|
r547 | |||
def post(self, request): | ||||
|
r730 | settings_manager = get_settings_manager(request) | ||
|
r547 | |||
with transaction.atomic(): | ||||
|
r729 | form = SettingsForm(request.POST, error_class=PlainErrorList) | ||
|
r547 | |||
if form.is_valid(): | ||||
selected_theme = form.cleaned_data['theme'] | ||||
|
r728 | settings_manager.set_theme(selected_theme) | ||
|
r547 | |||
return redirect('settings') | ||||