##// END OF EJS Templates
Post message by ctrl-enter on the text field
Post message by ctrl-enter on the text field

File last commit:

r995:64602f45 default
r1005:1df42bd8 default
Show More
settings.py
59 lines | 1.8 KiB | text/x-python | PythonLexer
from django.db import transaction
from django.shortcuts import render, redirect
from boards.abstracts.settingsmanager import get_settings_manager, \
SETTING_USERNAME, SETTING_LAST_NOTIFICATION_ID
from boards.views.base import BaseBoardView, CONTEXT_FORM
from boards.forms import SettingsForm, PlainErrorList
FORM_THEME = 'theme'
FORM_USERNAME = 'username'
CONTEXT_HIDDEN_TAGS = 'hidden_tags'
TEMPLATE = 'boards/settings.html'
class SettingsView(BaseBoardView):
def get(self, request):
params = dict()
settings_manager = get_settings_manager(request)
selected_theme = settings_manager.get_theme()
form = SettingsForm(
initial={
FORM_THEME: selected_theme,
FORM_USERNAME: settings_manager.get_setting(SETTING_USERNAME)},
error_class=PlainErrorList)
params[CONTEXT_FORM] = form
params[CONTEXT_HIDDEN_TAGS] = settings_manager.get_hidden_tags()
return render(request, TEMPLATE, params)
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]
username = form.cleaned_data[FORM_USERNAME]
settings_manager.set_theme(selected_theme)
settings_manager.set_setting(SETTING_USERNAME, username)
settings_manager.set_setting(SETTING_LAST_NOTIFICATION_ID, None)
return redirect('settings')
else:
params = dict()
params[CONTEXT_FORM] = form
params[CONTEXT_HIDDEN_TAGS] = settings_manager.get_hidden_tags()
return render(request, TEMPLATE, params)