##// END OF EJS Templates
Show reply count in OP along with the images count
Show reply count in OP along with the images count

File last commit:

r690:a8dffe47 1.8-dev
r695:865d0253 1.8-dev
Show More
settings.py
53 lines | 1.8 KiB | text/x-python | PythonLexer
neko259
Made settings view class-based
r547 from django.db import transaction
from django.shortcuts import render, redirect
neko259
Implemented search over posts. Moved get_user and get_theme to utils module. Use context processors instead of creating context in the base view. Removed unused imports in some modules
r690 from boards import utils
neko259
Made settings view class-based
r547
from boards.views.base import BaseBoardView, PARAMETER_FORM
from boards.forms import SettingsForm, ModeratorSettingsForm, PlainErrorList
neko259
Moved static page view to the class-based. Removed old methods from the view...
r565 from boards.models.post import SETTING_MODERATE
neko259
Made settings view class-based
r547
neko259
Minor style fixes to view classes. Fixed ban view
r561
neko259
Made settings view class-based
r547 class SettingsView(BaseBoardView):
def get(self, request):
context = self.get_context_data(request=request)
neko259
Implemented search over posts. Moved get_user and get_theme to utils module. Use context processors instead of creating context in the base view. Removed unused imports in some modules
r690 user = utils.get_user(request)
neko259
Made settings view class-based
r547 is_moderator = user.is_moderator()
neko259
Implemented search over posts. Moved get_user and get_theme to utils module. Use context processors instead of creating context in the base view. Removed unused imports in some modules
r690 selected_theme = utils.get_theme(request, user)
neko259
Made settings view class-based
r547
if is_moderator:
neko259
Minor style fixes to view classes. Fixed ban view
r561 form = ModeratorSettingsForm(initial={
'theme': selected_theme,
neko259
Implemented search over posts. Moved get_user and get_theme to utils module. Use context processors instead of creating context in the base view. Removed unused imports in some modules
r690 'moderate': user.get_setting(SETTING_MODERATE) and \
user.is_moderator()
neko259
Minor style fixes to view classes. Fixed ban view
r561 }, error_class=PlainErrorList)
neko259
Made settings view class-based
r547 else:
form = SettingsForm(initial={'theme': selected_theme},
error_class=PlainErrorList)
context[PARAMETER_FORM] = form
return render(request, 'boards/settings.html', context)
def post(self, request):
neko259
Implemented search over posts. Moved get_user and get_theme to utils module. Use context processors instead of creating context in the base view. Removed unused imports in some modules
r690 user = utils.get_user(request)
neko259
Made settings view class-based
r547 is_moderator = user.is_moderator()
with transaction.atomic():
if is_moderator:
form = ModeratorSettingsForm(request.POST,
error_class=PlainErrorList)
else:
form = SettingsForm(request.POST, error_class=PlainErrorList)
if form.is_valid():
selected_theme = form.cleaned_data['theme']
user.save_setting('theme', selected_theme)
if is_moderator:
moderate = form.cleaned_data['moderate']
user.save_setting(SETTING_MODERATE, moderate)
return redirect('settings')