Show More
@@ -0,0 +1,33 b'' | |||||
|
1 | PARAMETER_METHOD = 'method' | |||
|
2 | ||||
|
3 | from django.shortcuts import redirect | |||
|
4 | from django.http import HttpResponseRedirect | |||
|
5 | ||||
|
6 | ||||
|
7 | class RedirectNextMixin: | |||
|
8 | ||||
|
9 | def redirect_to_next(self, request): | |||
|
10 | """ | |||
|
11 | If a 'next' parameter was specified, redirect to the next page. This | |||
|
12 | is used when the user is required to return to some page after the | |||
|
13 | current view has finished its work. | |||
|
14 | """ | |||
|
15 | ||||
|
16 | if 'next' in request.GET: | |||
|
17 | next_page = request.GET['next'] | |||
|
18 | return HttpResponseRedirect(next_page) | |||
|
19 | else: | |||
|
20 | return redirect('index') | |||
|
21 | ||||
|
22 | ||||
|
23 | class DispatcherMixin: | |||
|
24 | """ | |||
|
25 | This class contains a dispather method that can run a method specified by | |||
|
26 | 'method' request parameter. | |||
|
27 | """ | |||
|
28 | ||||
|
29 | def dispatch_method(self, request): | |||
|
30 | if PARAMETER_METHOD in request.GET: | |||
|
31 | method_name = request.GET[PARAMETER_METHOD] | |||
|
32 | return getattr(self, method_name)(request) | |||
|
33 |
@@ -4,7 +4,7 b'' | |||||
4 |
|
4 | |||
5 | {% get_current_language as LANGUAGE_CODE %} |
|
5 | {% get_current_language as LANGUAGE_CODE %} | |
6 |
|
6 | |||
7 |
{% cache |
|
7 | {% cache 600 post post.id post.thread_new.last_edit_time truncated moderator LANGUAGE_CODE need_open_link %} | |
8 | {% spaceless %} |
|
8 | {% spaceless %} | |
9 | {% with thread=post.thread_new %} |
|
9 | {% with thread=post.thread_new %} | |
10 | {% if thread.archived %} |
|
10 | {% if thread.archived %} |
@@ -41,10 +41,10 b'' | |||||
41 | <div class="tag_info"> |
|
41 | <div class="tag_info"> | |
42 | <h2> |
|
42 | <h2> | |
43 | {% if tag in user.fav_tags.all %} |
|
43 | {% if tag in user.fav_tags.all %} | |
44 |
<a href="{% url 'tag |
|
44 | <a href="{% url 'tag' tag.name %}?method=unsubscribe&next={{ request.path }}" | |
45 | class="fav">★</a> |
|
45 | class="fav">★</a> | |
46 | {% else %} |
|
46 | {% else %} | |
47 |
<a href="{% url 'tag |
|
47 | <a href="{% url 'tag' tag.name %}?method=subscribe&next={{ request.path }}" | |
48 | class="not_fav">★</a> |
|
48 | class="not_fav">★</a> | |
49 | {% endif %} |
|
49 | {% endif %} | |
50 | #{{ tag.name }} |
|
50 | #{{ tag.name }} |
@@ -13,10 +13,10 b'' | |||||
13 | {% for tag in all_tags %} |
|
13 | {% for tag in all_tags %} | |
14 | <div class="tag_item" style="font-size: {{ tag.get_font_value }}em"> |
|
14 | <div class="tag_item" style="font-size: {{ tag.get_font_value }}em"> | |
15 | {% if tag in user.fav_tags.all %} |
|
15 | {% if tag in user.fav_tags.all %} | |
16 |
<a href="{% url 'tag |
|
16 | <a href="{% url 'tag' tag.name %}?method=unsubscribe&next={{ request.path }}" | |
17 | class="fav">★</a> |
|
17 | class="fav">★</a> | |
18 | {% else %} |
|
18 | {% else %} | |
19 |
<a href="{% url 'tag |
|
19 | <a href="{% url 'tag' tag.name %}?method=subscribe&next={{ request.path }}" | |
20 | class="not_fav">★</a> |
|
20 | class="not_fav">★</a> | |
21 | {% endif %} |
|
21 | {% endif %} | |
22 | <a class="tag" href="{% url 'tag' tag.name %}"> |
|
22 | <a class="tag" href="{% url 'tag' tag.name %}"> |
@@ -33,13 +33,6 b" urlpatterns = patterns(''," | |||||
33 | url(r'^tag/(?P<tag_name>\w+)/page/(?P<page>\w+)/$', |
|
33 | url(r'^tag/(?P<tag_name>\w+)/page/(?P<page>\w+)/$', | |
34 | tag_threads.TagView.as_view(), name='tag'), |
|
34 | tag_threads.TagView.as_view(), name='tag'), | |
35 |
|
35 | |||
36 | # /boards/tag/tag_name/unsubscribe/ |
|
|||
37 | url(r'^tag/(?P<tag_name>\w+)/subscribe/$', views.tag_subscribe, |
|
|||
38 | name='tag_subscribe'), |
|
|||
39 | # /boards/tag/tag_name/unsubscribe/ |
|
|||
40 | url(r'^tag/(?P<tag_name>\w+)/unsubscribe/$', views.tag_unsubscribe, |
|
|||
41 | name='tag_unsubscribe'), |
|
|||
42 |
|
||||
43 | # /boards/thread/ |
|
36 | # /boards/thread/ | |
44 | url(r'^thread/(?P<post_id>\w+)/$', views.thread.ThreadView.as_view(), |
|
37 | url(r'^thread/(?P<post_id>\w+)/$', views.thread.ThreadView.as_view(), | |
45 | name='thread'), |
|
38 | name='thread'), |
@@ -22,32 +22,6 b' from boards import authors' | |||||
22 | import neboard |
|
22 | import neboard | |
23 |
|
23 | |||
24 |
|
24 | |||
25 | @transaction.atomic |
|
|||
26 | def tag_subscribe(request, tag_name): |
|
|||
27 | """Add tag to favorites""" |
|
|||
28 |
|
||||
29 | user = _get_user(request) |
|
|||
30 | tag = get_object_or_404(Tag, name=tag_name) |
|
|||
31 |
|
||||
32 | if not tag in user.fav_tags.all(): |
|
|||
33 | user.add_tag(tag) |
|
|||
34 |
|
||||
35 | return _redirect_to_next(request) |
|
|||
36 |
|
||||
37 |
|
||||
38 | @transaction.atomic |
|
|||
39 | def tag_unsubscribe(request, tag_name): |
|
|||
40 | """Remove tag from favorites""" |
|
|||
41 |
|
||||
42 | user = _get_user(request) |
|
|||
43 | tag = get_object_or_404(Tag, name=tag_name) |
|
|||
44 |
|
||||
45 | if tag in user.fav_tags.all(): |
|
|||
46 | user.remove_tag(tag) |
|
|||
47 |
|
||||
48 | return _redirect_to_next(request) |
|
|||
49 |
|
||||
50 |
|
||||
51 | def static_page(request, name): |
|
25 | def static_page(request, name): | |
52 | """Show a static page that needs only tags list and a CSS""" |
|
26 | """Show a static page that needs only tags list and a CSS""" | |
53 |
|
27 |
@@ -3,9 +3,10 b' from django.shortcuts import get_object_' | |||||
3 |
|
3 | |||
4 | from boards.views.base import BaseBoardView |
|
4 | from boards.views.base import BaseBoardView | |
5 | from boards.models import Post, Ban |
|
5 | from boards.models import Post, Ban | |
|
6 | from boards.views.mixins import RedirectNextMixin | |||
6 |
|
7 | |||
7 |
|
8 | |||
8 | class BanUserView(BaseBoardView): |
|
9 | class BanUserView(BaseBoardView, RedirectNextMixin): | |
9 |
|
10 | |||
10 | @transaction.atomic |
|
11 | @transaction.atomic | |
11 | def get(self, request, post_id): |
|
12 | def get(self, request, post_id): |
@@ -2,7 +2,7 b' from django.shortcuts import redirect, g' | |||||
2 | from django.db import transaction |
|
2 | from django.db import transaction | |
3 |
|
3 | |||
4 | from boards.views.base import BaseBoardView |
|
4 | from boards.views.base import BaseBoardView | |
5 |
from boards.views. |
|
5 | from boards.views.mixins import RedirectNextMixin | |
6 | from boards.models import Post |
|
6 | from boards.models import Post | |
7 |
|
7 | |||
8 |
|
8 |
@@ -1,11 +1,12 b'' | |||||
1 | from django.shortcuts import get_object_or_404 |
|
1 | from django.shortcuts import get_object_or_404 | |
2 | from boards.models import Tag, Post |
|
2 | from boards.models import Tag, Post | |
3 | from boards.views.all_threads import AllThreadsView, DEFAULT_PAGE |
|
3 | from boards.views.all_threads import AllThreadsView, DEFAULT_PAGE | |
|
4 | from boards.views.mixins import DispatcherMixin, RedirectNextMixin | |||
4 |
|
5 | |||
5 | __author__ = 'neko259' |
|
6 | __author__ = 'neko259' | |
6 |
|
7 | |||
7 |
|
8 | |||
8 | class TagView(AllThreadsView): |
|
9 | class TagView(AllThreadsView, DispatcherMixin, RedirectNextMixin): | |
9 |
|
10 | |||
10 | tag_name = None |
|
11 | tag_name = None | |
11 |
|
12 | |||
@@ -25,4 +26,26 b' class TagView(AllThreadsView):' | |||||
25 | def get(self, request, tag_name, page=DEFAULT_PAGE): |
|
26 | def get(self, request, tag_name, page=DEFAULT_PAGE): | |
26 | self.tag_name = tag_name |
|
27 | self.tag_name = tag_name | |
27 |
|
28 | |||
28 | return super(TagView, self).get(request, page) |
|
29 | dispatch_result = self.dispatch_method(request) | |
|
30 | if dispatch_result: | |||
|
31 | return dispatch_result | |||
|
32 | else: | |||
|
33 | return super(TagView, self).get(request, page) | |||
|
34 | ||||
|
35 | def subscribe(self, request): | |||
|
36 | user = self._get_user(request) | |||
|
37 | tag = get_object_or_404(Tag, name=self.tag_name) | |||
|
38 | ||||
|
39 | if not tag in user.fav_tags.all(): | |||
|
40 | user.add_tag(tag) | |||
|
41 | ||||
|
42 | return self.redirect_to_next(request) | |||
|
43 | ||||
|
44 | def unsubscribe(self, request): | |||
|
45 | user = self._get_user(request) | |||
|
46 | tag = get_object_or_404(Tag, name=self.tag_name) | |||
|
47 | ||||
|
48 | if tag in user.fav_tags.all(): | |||
|
49 | user.remove_tag(tag) | |||
|
50 | ||||
|
51 | return self.redirect_to_next(request) |
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