##// END OF EJS Templates
Merged in bodqhrohro/neboard/mirrors_stamps (pull request #28)...
Merged in bodqhrohro/neboard/mirrors_stamps (pull request #28) Some more marochkas

File last commit:

r2088:09f03b4f default
r2107:d2d9582c merge default
Show More
settings.py
84 lines | 3.2 KiB | text/x-python | PythonLexer
neko259
Made settings view class-based
r547 from django.db import transaction
from django.shortcuts import render, redirect
neko259
Added timezone support (time zone is selected in settings)
r1065 from django.utils import timezone
neko259
Added CSRF protection to settings. Fixed favorite tags switch from different pages
r1693 from django.utils.decorators import method_decorator
from django.views.decorators.csrf import csrf_protect
neko259
Made settings view class-based
r547
neko259
User notifications (BB-59)
r990 from boards.abstracts.settingsmanager import get_settings_manager, \
neko259
Option to subscribe to threads by default
r2088 SETTING_USERNAME, SETTING_LAST_NOTIFICATION_ID, SETTING_IMAGE_VIEWER, \
SETTING_SUBSCRIBE_BY_DEFAULT
neko259
Refactored views
r1090 from boards.middlewares import SESSION_TIMEZONE
neko259
Code cleanup part 2
r722 from boards.views.base import BaseBoardView, CONTEXT_FORM
neko259
Added login and logout for moderators
r729 from boards.forms import SettingsForm, PlainErrorList
neko259
Setting for image view mode: in post (simple) or in popup
r1122 from boards import settings
neko259
Store images as regular attachments instead of separate model
r1590 from boards.models import Attachment
neko259
Made settings view class-based
r547
neko259
Views refactoring
r900 FORM_THEME = 'theme'
neko259
User notifications (BB-59)
r990 FORM_USERNAME = 'username'
neko259
Added timezone support (time zone is selected in settings)
r1065 FORM_TIMEZONE = 'timezone'
neko259
Setting for image view mode: in post (simple) or in popup
r1122 FORM_IMAGE_VIEWER = 'image_viewer'
neko259
Option to subscribe to threads by default
r2088 FORM_SUBSCRIBE = 'subscribe_by_default'
neko259
Views refactoring
r900
neko259
Fixed hidden tags list in the settings
r733 CONTEXT_HIDDEN_TAGS = 'hidden_tags'
neko259
Don't allow characters in username that we cannot use as a URL
r995 TEMPLATE = 'boards/settings.html'
neko259
Minor style fixes to view classes. Fixed ban view
r561
neko259
Made settings view class-based
r547 class SettingsView(BaseBoardView):
neko259
Added CSRF protection to settings. Fixed favorite tags switch from different pages
r1693 @method_decorator(csrf_protect)
neko259
Made settings view class-based
r547 def get(self, request):
neko259
Don't allow characters in username that we cannot use as a URL
r995 params = dict()
neko259
Divided settings manager into base settings manager class and session-based settings manager. This allowes to add other backends to the settings manager
r730 settings_manager = get_settings_manager(request)
neko259
Made settings view class-based
r547
neko259
Removed user and settings mode. Added settings manager to manage settings and keep them in the session (or any other backend like cookie in the future
r728 selected_theme = settings_manager.get_theme()
neko259
Made settings view class-based
r547
neko259
User notifications (BB-59)
r990 form = SettingsForm(
initial={
FORM_THEME: selected_theme,
neko259
Setting for image view mode: in post (simple) or in popup
r1122 FORM_IMAGE_VIEWER: settings_manager.get_setting(
neko259
Implemented ini settings parser
r1153 SETTING_IMAGE_VIEWER,
default=settings.get('View', 'DefaultImageViewer')),
neko259
Added timezone support (time zone is selected in settings)
r1065 FORM_USERNAME: settings_manager.get_setting(SETTING_USERNAME),
neko259
Refactored views
r1090 FORM_TIMEZONE: request.session.get(
SESSION_TIMEZONE, timezone.get_current_timezone()),
neko259
Option to subscribe to threads by default
r2088 FORM_SUBSCRIBE: settings_manager.get_setting(SETTING_SUBSCRIBE_BY_DEFAULT, False)
neko259
Added timezone support (time zone is selected in settings)
r1065 },
neko259
User notifications (BB-59)
r990 error_class=PlainErrorList)
neko259
Made settings view class-based
r547
neko259
Fixed tag threads view
r919 params[CONTEXT_FORM] = form
params[CONTEXT_HIDDEN_TAGS] = settings_manager.get_hidden_tags()
neko259
Made settings view class-based
r547
neko259
Don't allow characters in username that we cannot use as a URL
r995 return render(request, TEMPLATE, params)
neko259
Made settings view class-based
r547
neko259
Added CSRF protection to settings. Fixed favorite tags switch from different pages
r1693 @method_decorator(csrf_protect)
neko259
Made settings view class-based
r547 def post(self, request):
neko259
Divided settings manager into base settings manager class and session-based settings manager. This allowes to add other backends to the settings manager
r730 settings_manager = get_settings_manager(request)
neko259
Made settings view class-based
r547
with transaction.atomic():
neko259
Added login and logout for moderators
r729 form = SettingsForm(request.POST, error_class=PlainErrorList)
neko259
Made settings view class-based
r547
if form.is_valid():
neko259
Views refactoring
r900 selected_theme = form.cleaned_data[FORM_THEME]
neko259
Use only lowercase name in notifications. Refactored post manager and refmap...
r1008 username = form.cleaned_data[FORM_USERNAME].lower()
neko259
Made settings view class-based
r547
neko259
Removed user and settings mode. Added settings manager to manage settings and keep them in the session (or any other backend like cookie in the future
r728 settings_manager.set_theme(selected_theme)
neko259
Setting for image view mode: in post (simple) or in popup
r1122 settings_manager.set_setting(SETTING_IMAGE_VIEWER,
form.cleaned_data[FORM_IMAGE_VIEWER])
neko259
Option to subscribe to threads by default
r2088 settings_manager.set_setting(SETTING_SUBSCRIBE_BY_DEFAULT, form.cleaned_data[SETTING_SUBSCRIBE_BY_DEFAULT])
neko259
Made settings view class-based
r547
neko259
If the username was not changed during settings form saving, don't reset...
r1051 old_username = settings_manager.get_setting(SETTING_USERNAME)
if username != old_username:
settings_manager.set_setting(SETTING_USERNAME, username)
settings_manager.set_setting(SETTING_LAST_NOTIFICATION_ID, None)
neko259
Refactored views
r1090 request.session[SESSION_TIMEZONE] = form.cleaned_data[FORM_TIMEZONE]
neko259
Added timezone support (time zone is selected in settings)
r1065
neko259
Don't allow characters in username that we cannot use as a URL
r995 return redirect('settings')
else:
params = dict()
neko259
User notifications (BB-59)
r990
neko259
Don't allow characters in username that we cannot use as a URL
r995 params[CONTEXT_FORM] = form
params[CONTEXT_HIDDEN_TAGS] = settings_manager.get_hidden_tags()
return render(request, TEMPLATE, params)