##// END OF EJS Templates
Update time only for processed nodes. Fixed space before id tag in form
Update time only for processed nodes. Fixed space before id tag in form

File last commit:

r1008:bbb4d5fd default
r1018:472deced 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].lower()
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)