##// END OF EJS Templates
Refactored views
neko259 -
r1090:a66d091f default
parent child Browse files
Show More
@@ -1,42 +1,44
1 import pytz
1 import pytz
2
2
3 from django.shortcuts import redirect
3 from django.shortcuts import redirect
4 from django.utils import timezone
4 from django.utils import timezone
5
5
6 from boards import utils
6 from boards import utils
7 from boards.models import Ban
7 from boards.models import Ban
8
8
9 SESSION_TIMEZONE = 'django_timezone'
10
9 RESPONSE_CONTENT_TYPE = 'Content-Type'
11 RESPONSE_CONTENT_TYPE = 'Content-Type'
10
12
11 TYPE_HTML = 'text/html'
13 TYPE_HTML = 'text/html'
12
14
13
15
14 class BanMiddleware:
16 class BanMiddleware:
15 """
17 """
16 This is run before showing the thread. Banned users don't need to see
18 This is run before showing the thread. Banned users don't need to see
17 anything
19 anything
18 """
20 """
19
21
20 def __init__(self):
22 def __init__(self):
21 pass
23 pass
22
24
23 def process_view(self, request, view_func, view_args, view_kwargs):
25 def process_view(self, request, view_func, view_args, view_kwargs):
24
26
25 if request.path != '/banned/':
27 if request.path != '/banned/':
26 ip = utils.get_client_ip(request)
28 ip = utils.get_client_ip(request)
27 bans = Ban.objects.filter(ip=ip)
29 bans = Ban.objects.filter(ip=ip)
28
30
29 if bans.exists():
31 if bans.exists():
30 ban = bans[0]
32 ban = bans[0]
31 if not ban.can_read:
33 if not ban.can_read:
32 return redirect('banned')
34 return redirect('banned')
33
35
34
36
35 class TimezoneMiddleware(object):
37 class TimezoneMiddleware(object):
36 def process_request(self, request):
38 def process_request(self, request):
37 tzname = request.session.get('django_timezone')
39 tzname = request.session.get(SESSION_TIMEZONE)
38 if tzname:
40 if tzname:
39 timezone.activate(pytz.timezone(tzname))
41 timezone.activate(pytz.timezone(tzname))
40 else:
42 else:
41 timezone.deactivate()
43 timezone.deactivate()
42
44
@@ -1,81 +1,80
1 from django.conf.urls import patterns, url, include
1 from django.conf.urls import patterns, url
2 from django.contrib import admin
2
3 from boards import views
3 from boards import views
4 from boards.rss import AllThreadsFeed, TagThreadsFeed, ThreadPostsFeed
4 from boards.rss import AllThreadsFeed, TagThreadsFeed, ThreadPostsFeed
5 from boards.views import api, tag_threads, all_threads, \
5 from boards.views import api, tag_threads, all_threads, \
6 settings, all_tags
6 settings, all_tags
7 from boards.views.authors import AuthorsView
7 from boards.views.authors import AuthorsView
8 from boards.views.ban import BanUserView
9 from boards.views.notifications import NotificationView
8 from boards.views.notifications import NotificationView
10 from boards.views.search import BoardSearchView
9 from boards.views.search import BoardSearchView
11 from boards.views.static import StaticPageView
10 from boards.views.static import StaticPageView
12 from boards.views.preview import PostPreviewView
11 from boards.views.preview import PostPreviewView
13
12
13
14 js_info_dict = {
14 js_info_dict = {
15 'packages': ('boards',),
15 'packages': ('boards',),
16 }
16 }
17
17
18 urlpatterns = patterns('',
18 urlpatterns = patterns('',
19 # /boards/
19 # /boards/
20 url(r'^$', all_threads.AllThreadsView.as_view(), name='index'),
20 url(r'^$', all_threads.AllThreadsView.as_view(), name='index'),
21 # /boards/page/
21 # /boards/page/
22 url(r'^page/(?P<page>\w+)/$', all_threads.AllThreadsView.as_view(),
22 url(r'^page/(?P<page>\w+)/$', all_threads.AllThreadsView.as_view(),
23 name='index'),
23 name='index'),
24
24
25 # /boards/tag/tag_name/
25 # /boards/tag/tag_name/
26 url(r'^tag/(?P<tag_name>\w+)/$', tag_threads.TagView.as_view(),
26 url(r'^tag/(?P<tag_name>\w+)/$', tag_threads.TagView.as_view(),
27 name='tag'),
27 name='tag'),
28 # /boards/tag/tag_id/page/
28 # /boards/tag/tag_id/page/
29 url(r'^tag/(?P<tag_name>\w+)/page/(?P<page>\w+)/$',
29 url(r'^tag/(?P<tag_name>\w+)/page/(?P<page>\w+)/$',
30 tag_threads.TagView.as_view(), name='tag'),
30 tag_threads.TagView.as_view(), name='tag'),
31
31
32 # /boards/thread/
32 # /boards/thread/
33 url(r'^thread/(?P<post_id>\d+)/$', views.thread.normal.NormalThreadView.as_view(),
33 url(r'^thread/(?P<post_id>\d+)/$', views.thread.normal.NormalThreadView.as_view(),
34 name='thread'),
34 name='thread'),
35 url(r'^thread/(?P<post_id>\d+)/mode/gallery/$', views.thread.gallery.GalleryThreadView.as_view(),
35 url(r'^thread/(?P<post_id>\d+)/mode/gallery/$', views.thread.gallery.GalleryThreadView.as_view(),
36 name='thread_gallery'),
36 name='thread_gallery'),
37
37
38 url(r'^settings/$', settings.SettingsView.as_view(), name='settings'),
38 url(r'^settings/$', settings.SettingsView.as_view(), name='settings'),
39 url(r'^tags/(?P<query>\w+)?/?$', all_tags.AllTagsView.as_view(), name='tags'),
39 url(r'^tags/(?P<query>\w+)?/?$', all_tags.AllTagsView.as_view(), name='tags'),
40 url(r'^authors/$', AuthorsView.as_view(), name='authors'),
40 url(r'^authors/$', AuthorsView.as_view(), name='authors'),
41 url(r'^ban/(?P<post_id>\w+)/$', BanUserView.as_view(), name='ban'),
42
41
43 url(r'^banned/$', views.banned.BannedView.as_view(), name='banned'),
42 url(r'^banned/$', views.banned.BannedView.as_view(), name='banned'),
44 url(r'^staticpage/(?P<name>\w+)/$', StaticPageView.as_view(),
43 url(r'^staticpage/(?P<name>\w+)/$', StaticPageView.as_view(),
45 name='staticpage'),
44 name='staticpage'),
46
45
47 # RSS feeds
46 # RSS feeds
48 url(r'^rss/$', AllThreadsFeed()),
47 url(r'^rss/$', AllThreadsFeed()),
49 url(r'^page/(?P<page>\d+)/rss/$', AllThreadsFeed()),
48 url(r'^page/(?P<page>\d+)/rss/$', AllThreadsFeed()),
50 url(r'^tag/(?P<tag_name>\w+)/rss/$', TagThreadsFeed()),
49 url(r'^tag/(?P<tag_name>\w+)/rss/$', TagThreadsFeed()),
51 url(r'^tag/(?P<tag_name>\w+)/page/(?P<page>\w+)/rss/$', TagThreadsFeed()),
50 url(r'^tag/(?P<tag_name>\w+)/page/(?P<page>\w+)/rss/$', TagThreadsFeed()),
52 url(r'^thread/(?P<post_id>\d+)/rss/$', ThreadPostsFeed()),
51 url(r'^thread/(?P<post_id>\d+)/rss/$', ThreadPostsFeed()),
53
52
54 # i18n
53 # i18n
55 url(r'^jsi18n/$', 'boards.views.cached_js_catalog', js_info_dict,
54 url(r'^jsi18n/$', 'boards.views.cached_js_catalog', js_info_dict,
56 name='js_info_dict'),
55 name='js_info_dict'),
57
56
58 # API
57 # API
59 url(r'^api/post/(?P<post_id>\d+)/$', api.get_post, name="get_post"),
58 url(r'^api/post/(?P<post_id>\d+)/$', api.get_post, name="get_post"),
60 url(r'^api/diff_thread$',
59 url(r'^api/diff_thread$',
61 api.api_get_threaddiff, name="get_thread_diff"),
60 api.api_get_threaddiff, name="get_thread_diff"),
62 url(r'^api/threads/(?P<count>\w+)/$', api.api_get_threads,
61 url(r'^api/threads/(?P<count>\w+)/$', api.api_get_threads,
63 name='get_threads'),
62 name='get_threads'),
64 url(r'^api/tags/$', api.api_get_tags, name='get_tags'),
63 url(r'^api/tags/$', api.api_get_tags, name='get_tags'),
65 url(r'^api/thread/(?P<opening_post_id>\w+)/$', api.api_get_thread_posts,
64 url(r'^api/thread/(?P<opening_post_id>\w+)/$', api.api_get_thread_posts,
66 name='get_thread'),
65 name='get_thread'),
67 url(r'^api/add_post/(?P<opening_post_id>\w+)/$', api.api_add_post,
66 url(r'^api/add_post/(?P<opening_post_id>\w+)/$', api.api_add_post,
68 name='add_post'),
67 name='add_post'),
69 url(r'^api/notifications/(?P<username>\w+)/$', api.api_get_notifications,
68 url(r'^api/notifications/(?P<username>\w+)/$', api.api_get_notifications,
70 name='api_notifications'),
69 name='api_notifications'),
71
70
72 # Search
71 # Search
73 url(r'^search/$', BoardSearchView.as_view(), name='search'),
72 url(r'^search/$', BoardSearchView.as_view(), name='search'),
74
73
75 # Notifications
74 # Notifications
76 url(r'^notifications/(?P<username>\w+)$', NotificationView.as_view(), name='notifications'),
75 url(r'^notifications/(?P<username>\w+)$', NotificationView.as_view(), name='notifications'),
77
76
78 # Post preview
77 # Post preview
79 url(r'^preview/$', PostPreviewView.as_view(), name='preview')
78 url(r'^preview/$', PostPreviewView.as_view(), name='preview')
80
79
81 )
80 )
@@ -1,40 +1,21
1 PARAM_NEXT = 'next'
1 PARAM_NEXT = 'next'
2 PARAMETER_METHOD = 'method'
2 PARAMETER_METHOD = 'method'
3
3
4 from django.shortcuts import redirect
5 from django.http import HttpResponseRedirect
6
7
8 class RedirectNextMixin:
9
10 def redirect_to_next(self, request):
11 """
12 If a 'next' parameter was specified, redirect to the next page. This
13 is used when the user is required to return to some page after the
14 current view has finished its work.
15 """
16
17 if PARAM_NEXT in request.GET:
18 next_page = request.GET[PARAM_NEXT]
19 return HttpResponseRedirect(next_page)
20 else:
21 return redirect('index')
22
23
4
24 class DispatcherMixin:
5 class DispatcherMixin:
25 """
6 """
26 This class contains a dispather method that can run a method specified by
7 This class contains a dispather method that can run a method specified by
27 'method' request parameter.
8 'method' request parameter.
28 """
9 """
29
10
30 def dispatch_method(self, *args, **kwargs):
11 def dispatch_method(self, *args, **kwargs):
31 request = args[0]
12 request = args[0]
32
13
33 method_name = None
14 method_name = None
34 if PARAMETER_METHOD in request.GET:
15 if PARAMETER_METHOD in request.GET:
35 method_name = request.GET[PARAMETER_METHOD]
16 method_name = request.GET[PARAMETER_METHOD]
36 elif PARAMETER_METHOD in request.POST:
17 elif PARAMETER_METHOD in request.POST:
37 method_name = request.POST[PARAMETER_METHOD]
18 method_name = request.POST[PARAMETER_METHOD]
38
19
39 if method_name:
20 if method_name:
40 return getattr(self, method_name)(*args, **kwargs)
21 return getattr(self, method_name)(*args, **kwargs)
@@ -1,44 +1,46
1 from django.shortcuts import render
1 from django.shortcuts import render
2
2 from boards.abstracts.paginator import get_paginator
3 from boards.abstracts.paginator import get_paginator
3 from boards.abstracts.settingsmanager import get_settings_manager, \
4 from boards.abstracts.settingsmanager import get_settings_manager, \
4 SETTING_USERNAME, SETTING_LAST_NOTIFICATION_ID
5 SETTING_USERNAME, SETTING_LAST_NOTIFICATION_ID
5 from boards.models import Post
6 from boards.models.user import Notification
6 from boards.models.user import Notification
7 from boards.views.base import BaseBoardView
7 from boards.views.base import BaseBoardView
8
8
9 DEFAULT_PAGE = '1'
10
9 TEMPLATE = 'boards/notifications.html'
11 TEMPLATE = 'boards/notifications.html'
10 PARAM_PAGE = 'page'
12 PARAM_PAGE = 'page'
11 PARAM_USERNAME = 'notification_username'
13 PARAM_USERNAME = 'notification_username'
12 REQUEST_PAGE = 'page'
14 REQUEST_PAGE = 'page'
13 RESULTS_PER_PAGE = 10
15 RESULTS_PER_PAGE = 10
14
16
15
17
16 class NotificationView(BaseBoardView):
18 class NotificationView(BaseBoardView):
17
19
18 def get(self, request, username):
20 def get(self, request, username):
19 params = self.get_context_data()
21 params = self.get_context_data()
20
22
21 settings_manager = get_settings_manager(request)
23 settings_manager = get_settings_manager(request)
22
24
23 # If we open our notifications, reset the "new" count
25 # If we open our notifications, reset the "new" count
24 my_username = settings_manager.get_setting(SETTING_USERNAME)
26 my_username = settings_manager.get_setting(SETTING_USERNAME)
25
27
26 notification_username = username.lower()
28 notification_username = username.lower()
27
29
28 posts = Notification.objects.get_notification_posts(
30 posts = Notification.objects.get_notification_posts(
29 username=notification_username)
31 username=notification_username)
30 if notification_username == my_username:
32 if notification_username == my_username:
31 last = posts.first()
33 last = posts.first()
32 if last is not None:
34 if last is not None:
33 last_id = last.id
35 last_id = last.id
34 settings_manager.set_setting(SETTING_LAST_NOTIFICATION_ID,
36 settings_manager.set_setting(SETTING_LAST_NOTIFICATION_ID,
35 last_id)
37 last_id)
36
38
37 paginator = get_paginator(posts, RESULTS_PER_PAGE)
39 paginator = get_paginator(posts, RESULTS_PER_PAGE)
38
40
39 page = int(request.GET.get(REQUEST_PAGE, '1'))
41 page = int(request.GET.get(REQUEST_PAGE, DEFAULT_PAGE))
40
42
41 params[PARAM_PAGE] = paginator.page(page)
43 params[PARAM_PAGE] = paginator.page(page)
42 params[PARAM_USERNAME] = notification_username
44 params[PARAM_USERNAME] = notification_username
43
45
44 return render(request, TEMPLATE, params)
46 return render(request, TEMPLATE, params)
@@ -1,39 +1,38
1 from django.shortcuts import render
1 from django.shortcuts import render
2 from django.template import RequestContext
2 from django.template import RequestContext
3 from django.views.generic import View
3 from django.views.generic import View
4
4
5 from boards.mdx_neboard import Parser
5 from boards.mdx_neboard import Parser
6
6
7
7
8 FORM_QUERY = 'query'
8 FORM_QUERY = 'query'
9
9
10 CONTEXT_RESULT = 'result'
10 CONTEXT_RESULT = 'result'
11 CONTEXT_QUERY = 'query'
11 CONTEXT_QUERY = 'query'
12
12
13 __author__ = 'neko259'
13 __author__ = 'neko259'
14
14
15 TEMPLATE = 'boards/preview.html'
15 TEMPLATE = 'boards/preview.html'
16
16
17
17
18 class PostPreviewView(View):
18 class PostPreviewView(View):
19 def get(self, request):
19 def get(self, request):
20 context = RequestContext(request)
20 context = RequestContext(request)
21
21
22 # TODO Use dict here
22 # TODO Use dict here
23 return render(request, TEMPLATE, context_instance=context)
23 return render(request, TEMPLATE, context_instance=context)
24
24
25 def post(self, request):
25 def post(self, request):
26 context = RequestContext(request)
26 params = dict()
27
27
28 if FORM_QUERY in request.POST:
28 if FORM_QUERY in request.POST:
29 raw_text = request.POST[FORM_QUERY]
29 raw_text = request.POST[FORM_QUERY]
30
30
31 if len(raw_text) >= 0:
31 if len(raw_text) >= 0:
32 parser = Parser()
32 parser = Parser()
33 rendered_text = parser.parse(parser.preparse(raw_text))
33 rendered_text = parser.parse(parser.preparse(raw_text))
34
34
35 context[CONTEXT_RESULT] = rendered_text
35 params[CONTEXT_RESULT] = rendered_text
36 context[CONTEXT_QUERY] = raw_text
36 params[CONTEXT_QUERY] = raw_text
37
37
38 # TODO Use dict here
38 return render(request, TEMPLATE, params)
39 return render(request, TEMPLATE, context_instance=context)
@@ -1,69 +1,70
1 import pytz
2
3 from django.db import transaction
1 from django.db import transaction
4 from django.shortcuts import render, redirect
2 from django.shortcuts import render, redirect
5 from django.utils import timezone
3 from django.utils import timezone
6
4
7 from boards.abstracts.settingsmanager import get_settings_manager, \
5 from boards.abstracts.settingsmanager import get_settings_manager, \
8 SETTING_USERNAME, SETTING_LAST_NOTIFICATION_ID
6 SETTING_USERNAME, SETTING_LAST_NOTIFICATION_ID
7 from boards.middlewares import SESSION_TIMEZONE
9 from boards.views.base import BaseBoardView, CONTEXT_FORM
8 from boards.views.base import BaseBoardView, CONTEXT_FORM
10 from boards.forms import SettingsForm, PlainErrorList
9 from boards.forms import SettingsForm, PlainErrorList
11
10
11
12 FORM_THEME = 'theme'
12 FORM_THEME = 'theme'
13 FORM_USERNAME = 'username'
13 FORM_USERNAME = 'username'
14 FORM_TIMEZONE = 'timezone'
14 FORM_TIMEZONE = 'timezone'
15
15
16 CONTEXT_HIDDEN_TAGS = 'hidden_tags'
16 CONTEXT_HIDDEN_TAGS = 'hidden_tags'
17
17
18 TEMPLATE = 'boards/settings.html'
18 TEMPLATE = 'boards/settings.html'
19
19
20
20
21 class SettingsView(BaseBoardView):
21 class SettingsView(BaseBoardView):
22
22
23 def get(self, request):
23 def get(self, request):
24 params = dict()
24 params = dict()
25 settings_manager = get_settings_manager(request)
25 settings_manager = get_settings_manager(request)
26
26
27 selected_theme = settings_manager.get_theme()
27 selected_theme = settings_manager.get_theme()
28
28
29 form = SettingsForm(
29 form = SettingsForm(
30 initial={
30 initial={
31 FORM_THEME: selected_theme,
31 FORM_THEME: selected_theme,
32 FORM_USERNAME: settings_manager.get_setting(SETTING_USERNAME),
32 FORM_USERNAME: settings_manager.get_setting(SETTING_USERNAME),
33 FORM_TIMEZONE: request.session.get('django_timezone', timezone.get_current_timezone()),
33 FORM_TIMEZONE: request.session.get(
34 SESSION_TIMEZONE, timezone.get_current_timezone()),
34 },
35 },
35 error_class=PlainErrorList)
36 error_class=PlainErrorList)
36
37
37 params[CONTEXT_FORM] = form
38 params[CONTEXT_FORM] = form
38 params[CONTEXT_HIDDEN_TAGS] = settings_manager.get_hidden_tags()
39 params[CONTEXT_HIDDEN_TAGS] = settings_manager.get_hidden_tags()
39
40
40 return render(request, TEMPLATE, params)
41 return render(request, TEMPLATE, params)
41
42
42 def post(self, request):
43 def post(self, request):
43 settings_manager = get_settings_manager(request)
44 settings_manager = get_settings_manager(request)
44
45
45 with transaction.atomic():
46 with transaction.atomic():
46 form = SettingsForm(request.POST, error_class=PlainErrorList)
47 form = SettingsForm(request.POST, error_class=PlainErrorList)
47
48
48 if form.is_valid():
49 if form.is_valid():
49 selected_theme = form.cleaned_data[FORM_THEME]
50 selected_theme = form.cleaned_data[FORM_THEME]
50 username = form.cleaned_data[FORM_USERNAME].lower()
51 username = form.cleaned_data[FORM_USERNAME].lower()
51
52
52 settings_manager.set_theme(selected_theme)
53 settings_manager.set_theme(selected_theme)
53
54
54 old_username = settings_manager.get_setting(SETTING_USERNAME)
55 old_username = settings_manager.get_setting(SETTING_USERNAME)
55 if username != old_username:
56 if username != old_username:
56 settings_manager.set_setting(SETTING_USERNAME, username)
57 settings_manager.set_setting(SETTING_USERNAME, username)
57 settings_manager.set_setting(SETTING_LAST_NOTIFICATION_ID, None)
58 settings_manager.set_setting(SETTING_LAST_NOTIFICATION_ID, None)
58
59
59 request.session['django_timezone'] = form.cleaned_data[FORM_TIMEZONE]
60 request.session[SESSION_TIMEZONE] = form.cleaned_data[FORM_TIMEZONE]
60
61
61 return redirect('settings')
62 return redirect('settings')
62 else:
63 else:
63 params = dict()
64 params = dict()
64
65
65 params[CONTEXT_FORM] = form
66 params[CONTEXT_FORM] = form
66 params[CONTEXT_HIDDEN_TAGS] = settings_manager.get_hidden_tags()
67 params[CONTEXT_HIDDEN_TAGS] = settings_manager.get_hidden_tags()
67
68
68 return render(request, TEMPLATE, params)
69 return render(request, TEMPLATE, params)
69
70
@@ -1,107 +1,107
1 from django.shortcuts import get_object_or_404
1 from django.shortcuts import get_object_or_404
2
2
3 from boards.abstracts.settingsmanager import get_settings_manager, \
3 from boards.abstracts.settingsmanager import get_settings_manager, \
4 SETTING_FAVORITE_TAGS, SETTING_HIDDEN_TAGS
4 SETTING_FAVORITE_TAGS, SETTING_HIDDEN_TAGS
5 from boards.models import Tag
5 from boards.models import Tag
6 from boards.views.all_threads import AllThreadsView, DEFAULT_PAGE
6 from boards.views.all_threads import AllThreadsView, DEFAULT_PAGE
7 from boards.views.mixins import DispatcherMixin, RedirectNextMixin
7 from boards.views.mixins import DispatcherMixin
8 from boards.forms import ThreadForm, PlainErrorList
8 from boards.forms import ThreadForm, PlainErrorList
9
9
10 PARAM_HIDDEN_TAGS = 'hidden_tags'
10 PARAM_HIDDEN_TAGS = 'hidden_tags'
11 PARAM_TAG = 'tag'
11 PARAM_TAG = 'tag'
12 PARAM_IS_FAVORITE = 'is_favorite'
12 PARAM_IS_FAVORITE = 'is_favorite'
13 PARAM_IS_HIDDEN = 'is_hidden'
13 PARAM_IS_HIDDEN = 'is_hidden'
14
14
15 __author__ = 'neko259'
15 __author__ = 'neko259'
16
16
17
17
18 class TagView(AllThreadsView, DispatcherMixin, RedirectNextMixin):
18 class TagView(AllThreadsView, DispatcherMixin):
19
19
20 tag_name = None
20 tag_name = None
21
21
22 def get_threads(self):
22 def get_threads(self):
23 tag = get_object_or_404(Tag, name=self.tag_name)
23 tag = get_object_or_404(Tag, name=self.tag_name)
24
24
25 hidden_tags = self.settings_manager.get_hidden_tags()
25 hidden_tags = self.settings_manager.get_hidden_tags()
26
26
27 try:
27 try:
28 hidden_tags.remove(tag)
28 hidden_tags.remove(tag)
29 except ValueError:
29 except ValueError:
30 pass
30 pass
31
31
32 return tag.get_threads().exclude(
32 return tag.get_threads().exclude(
33 tags__in=hidden_tags)
33 tags__in=hidden_tags)
34
34
35 def get_context_data(self, **kwargs):
35 def get_context_data(self, **kwargs):
36 params = super(TagView, self).get_context_data(**kwargs)
36 params = super(TagView, self).get_context_data(**kwargs)
37
37
38 settings_manager = get_settings_manager(kwargs['request'])
38 settings_manager = get_settings_manager(kwargs['request'])
39
39
40 tag = get_object_or_404(Tag, name=self.tag_name)
40 tag = get_object_or_404(Tag, name=self.tag_name)
41 params[PARAM_TAG] = tag
41 params[PARAM_TAG] = tag
42
42
43 fav_tag_names = settings_manager.get_setting(SETTING_FAVORITE_TAGS)
43 fav_tag_names = settings_manager.get_setting(SETTING_FAVORITE_TAGS)
44 hidden_tag_names = settings_manager.get_setting(SETTING_HIDDEN_TAGS)
44 hidden_tag_names = settings_manager.get_setting(SETTING_HIDDEN_TAGS)
45
45
46 params[PARAM_IS_FAVORITE] = fav_tag_names is not None and tag.name in fav_tag_names
46 params[PARAM_IS_FAVORITE] = fav_tag_names is not None and tag.name in fav_tag_names
47 params[PARAM_IS_HIDDEN] = hidden_tag_names is not None and tag.name in hidden_tag_names
47 params[PARAM_IS_HIDDEN] = hidden_tag_names is not None and tag.name in hidden_tag_names
48
48
49 return params
49 return params
50
50
51 def get(self, request, tag_name, page=DEFAULT_PAGE, form=None):
51 def get(self, request, tag_name, page=DEFAULT_PAGE, form=None):
52 self.tag_name = tag_name
52 self.tag_name = tag_name
53
53
54 return super(TagView, self).get(request, page, form)
54 return super(TagView, self).get(request, page, form)
55
55
56
56
57 def post(self, request, tag_name, page=DEFAULT_PAGE):
57 def post(self, request, tag_name, page=DEFAULT_PAGE):
58 self.tag_name = tag_name
58 self.tag_name = tag_name
59
59
60 if 'method' in request.POST:
60 if 'method' in request.POST:
61 self.dispatch_method(request)
61 self.dispatch_method(request)
62 form = None
62 form = None
63 else:
63 else:
64 form = ThreadForm(request.POST, request.FILES,
64 form = ThreadForm(request.POST, request.FILES,
65 error_class=PlainErrorList)
65 error_class=PlainErrorList)
66 form.session = request.session
66 form.session = request.session
67
67
68 if form.is_valid():
68 if form.is_valid():
69 return self.create_thread(request, form)
69 return self.create_thread(request, form)
70 if form.need_to_ban:
70 if form.need_to_ban:
71 # Ban user because he is suspected to be a bot
71 # Ban user because he is suspected to be a bot
72 self._ban_current_user(request)
72 self._ban_current_user(request)
73
73
74 return self.get(request, tag_name, page, form)
74 return self.get(request, tag_name, page, form)
75
75
76 def subscribe(self, request):
76 def subscribe(self, request):
77 tag = get_object_or_404(Tag, name=self.tag_name)
77 tag = get_object_or_404(Tag, name=self.tag_name)
78
78
79 settings_manager = get_settings_manager(request)
79 settings_manager = get_settings_manager(request)
80 settings_manager.add_fav_tag(tag)
80 settings_manager.add_fav_tag(tag)
81
81
82 def unsubscribe(self, request):
82 def unsubscribe(self, request):
83 tag = get_object_or_404(Tag, name=self.tag_name)
83 tag = get_object_or_404(Tag, name=self.tag_name)
84
84
85 settings_manager = get_settings_manager(request)
85 settings_manager = get_settings_manager(request)
86 settings_manager.del_fav_tag(tag)
86 settings_manager.del_fav_tag(tag)
87
87
88 def hide(self, request):
88 def hide(self, request):
89 """
89 """
90 Adds tag to user's hidden tags. Threads with this tag will not be
90 Adds tag to user's hidden tags. Threads with this tag will not be
91 shown.
91 shown.
92 """
92 """
93
93
94 tag = get_object_or_404(Tag, name=self.tag_name)
94 tag = get_object_or_404(Tag, name=self.tag_name)
95
95
96 settings_manager = get_settings_manager(request)
96 settings_manager = get_settings_manager(request)
97 settings_manager.add_hidden_tag(tag)
97 settings_manager.add_hidden_tag(tag)
98
98
99 def unhide(self, request):
99 def unhide(self, request):
100 """
100 """
101 Removed tag from user's hidden tags.
101 Removed tag from user's hidden tags.
102 """
102 """
103
103
104 tag = get_object_or_404(Tag, name=self.tag_name)
104 tag = get_object_or_404(Tag, name=self.tag_name)
105
105
106 settings_manager = get_settings_manager(request)
106 settings_manager = get_settings_manager(request)
107 settings_manager.del_hidden_tag(tag)
107 settings_manager.del_hidden_tag(tag)
1 NO CONTENT: file was removed
NO CONTENT: file was removed
1 NO CONTENT: file was removed
NO CONTENT: file was removed
General Comments 0
You need to be logged in to leave comments. Login now