Show More
@@ -0,0 +1,49 b'' | |||||
|
1 | from django.db import transaction | |||
|
2 | from django.shortcuts import render, redirect | |||
|
3 | ||||
|
4 | from boards.views.base import BaseBoardView, PARAMETER_FORM | |||
|
5 | from boards.forms import SettingsForm, ModeratorSettingsForm, PlainErrorList | |||
|
6 | ||||
|
7 | class SettingsView(BaseBoardView): | |||
|
8 | ||||
|
9 | def get(self, request): | |||
|
10 | context = self.get_context_data(request=request) | |||
|
11 | user = context['user'] | |||
|
12 | is_moderator = user.is_moderator() | |||
|
13 | ||||
|
14 | selected_theme = context['theme'] | |||
|
15 | ||||
|
16 | if is_moderator: | |||
|
17 | form = ModeratorSettingsForm(initial={'theme': selected_theme, | |||
|
18 | 'moderate': context['moderator']}, | |||
|
19 | error_class=PlainErrorList) | |||
|
20 | else: | |||
|
21 | form = SettingsForm(initial={'theme': selected_theme}, | |||
|
22 | error_class=PlainErrorList) | |||
|
23 | ||||
|
24 | context[PARAMETER_FORM] = form | |||
|
25 | ||||
|
26 | return render(request, 'boards/settings.html', context) | |||
|
27 | ||||
|
28 | def post(self, request): | |||
|
29 | context = self.get_context_data(request=request) | |||
|
30 | user = context['user'] | |||
|
31 | is_moderator = user.is_moderator() | |||
|
32 | ||||
|
33 | with transaction.atomic(): | |||
|
34 | if is_moderator: | |||
|
35 | form = ModeratorSettingsForm(request.POST, | |||
|
36 | error_class=PlainErrorList) | |||
|
37 | else: | |||
|
38 | form = SettingsForm(request.POST, error_class=PlainErrorList) | |||
|
39 | ||||
|
40 | if form.is_valid(): | |||
|
41 | selected_theme = form.cleaned_data['theme'] | |||
|
42 | ||||
|
43 | user.save_setting('theme', selected_theme) | |||
|
44 | ||||
|
45 | if is_moderator: | |||
|
46 | moderate = form.cleaned_data['moderate'] | |||
|
47 | user.save_setting(SETTING_MODERATE, moderate) | |||
|
48 | ||||
|
49 | return redirect('settings') |
@@ -1,7 +1,8 b'' | |||||
1 | from django.conf.urls import patterns, url, include |
|
1 | from django.conf.urls import patterns, url, include | |
2 | from boards import views |
|
2 | from boards import views | |
3 | from boards.rss import AllThreadsFeed, TagThreadsFeed, ThreadPostsFeed |
|
3 | from boards.rss import AllThreadsFeed, TagThreadsFeed, ThreadPostsFeed | |
4 |
from boards.views import api, tag_threads, all_threads, archived_threads, |
|
4 | from boards.views import api, tag_threads, all_threads, archived_threads, \ | |
|
5 | login, settings | |||
5 |
|
6 | |||
6 | js_info_dict = { |
|
7 | js_info_dict = { | |
7 | 'packages': ('boards',), |
|
8 | 'packages': ('boards',), | |
@@ -41,7 +42,7 b" urlpatterns = patterns(''," | |||||
41 | name='thread'), |
|
42 | name='thread'), | |
42 | url(r'^thread/(?P<post_id>\w+)/(?P<mode>\w+)/$', views.thread.ThreadView |
|
43 | url(r'^thread/(?P<post_id>\w+)/(?P<mode>\w+)/$', views.thread.ThreadView | |
43 | .as_view(), name='thread_mode'), |
|
44 | .as_view(), name='thread_mode'), | |
44 |
url(r'^settings/$', |
|
45 | url(r'^settings/$', settings.SettingsView.as_view(), name='settings'), | |
45 | url(r'^tags/$', views.all_tags, name='tags'), |
|
46 | url(r'^tags/$', views.all_tags, name='tags'), | |
46 | url(r'^captcha/', include('captcha.urls')), |
|
47 | url(r'^captcha/', include('captcha.urls')), | |
47 | url(r'^jump/(?P<post_id>\w+)/$', views.jump_to_post, name='jumper'), |
|
48 | url(r'^jump/(?P<post_id>\w+)/$', views.jump_to_post, name='jumper'), |
@@ -14,14 +14,12 b' from django.views.decorators.cache impor' | |||||
14 | from django.views.i18n import javascript_catalog |
|
14 | from django.views.i18n import javascript_catalog | |
15 |
|
15 | |||
16 | import boards |
|
16 | import boards | |
17 |
from boards.forms import |
|
17 | from boards.forms import PlainErrorList | |
18 | ModeratorSettingsForm |
|
|||
19 | from boards.models import Post, Tag, Ban, User |
|
18 | from boards.models import Post, Tag, Ban, User | |
20 | from boards.models.post import SETTING_MODERATE |
|
19 | from boards.models.post import SETTING_MODERATE | |
21 | from boards.models.user import RANK_USER |
|
20 | from boards.models.user import RANK_USER | |
22 | from boards import authors |
|
21 | from boards import authors | |
23 | import neboard |
|
22 | import neboard | |
24 | import all_threads |
|
|||
25 |
|
23 | |||
26 |
|
24 | |||
27 | BAN_REASON_SPAM = 'Autoban: spam bot' |
|
25 | BAN_REASON_SPAM = 'Autoban: spam bot' | |
@@ -29,47 +27,6 b" BAN_REASON_SPAM = 'Autoban: spam bot'" | |||||
29 | DEFAULT_PAGE = 1 |
|
27 | DEFAULT_PAGE = 1 | |
30 |
|
28 | |||
31 |
|
29 | |||
32 | def settings(request): |
|
|||
33 | """User's settings""" |
|
|||
34 |
|
||||
35 | context = _init_default_context(request) |
|
|||
36 | user = _get_user(request) |
|
|||
37 | is_moderator = user.is_moderator() |
|
|||
38 |
|
||||
39 | if request.method == 'POST': |
|
|||
40 | with transaction.atomic(): |
|
|||
41 | if is_moderator: |
|
|||
42 | form = ModeratorSettingsForm(request.POST, |
|
|||
43 | error_class=PlainErrorList) |
|
|||
44 | else: |
|
|||
45 | form = SettingsForm(request.POST, error_class=PlainErrorList) |
|
|||
46 |
|
||||
47 | if form.is_valid(): |
|
|||
48 | selected_theme = form.cleaned_data['theme'] |
|
|||
49 |
|
||||
50 | user.save_setting('theme', selected_theme) |
|
|||
51 |
|
||||
52 | if is_moderator: |
|
|||
53 | moderate = form.cleaned_data['moderate'] |
|
|||
54 | user.save_setting(SETTING_MODERATE, moderate) |
|
|||
55 |
|
||||
56 | return redirect(settings) |
|
|||
57 | else: |
|
|||
58 | selected_theme = _get_theme(request) |
|
|||
59 |
|
||||
60 | if is_moderator: |
|
|||
61 | form = ModeratorSettingsForm(initial={'theme': selected_theme, |
|
|||
62 | 'moderate': context['moderator']}, |
|
|||
63 | error_class=PlainErrorList) |
|
|||
64 | else: |
|
|||
65 | form = SettingsForm(initial={'theme': selected_theme}, |
|
|||
66 | error_class=PlainErrorList) |
|
|||
67 |
|
||||
68 | context['form'] = form |
|
|||
69 |
|
||||
70 | return render(request, 'boards/settings.html', context) |
|
|||
71 |
|
||||
72 |
|
||||
73 | def all_tags(request): |
|
30 | def all_tags(request): | |
74 | """All tags list""" |
|
31 | """All tags list""" | |
75 |
|
32 |
General Comments 0
You need to be logged in to leave comments.
Login now