Show More
@@ -0,0 +1,20 b'' | |||
|
1 | from django.db import transaction | |
|
2 | ||
|
3 | from boards.views.base import BaseBoardView | |
|
4 | from boards.models import Post, Ban | |
|
5 | ||
|
6 | class BanUserView(BaseBoardView): | |
|
7 | ||
|
8 | @transaction.atomic | |
|
9 | def get(self, request, post_id): | |
|
10 | user = self._get_user(request) | |
|
11 | post = get_object_or_404(Post, id=post_id) | |
|
12 | ||
|
13 | if user.is_moderator(): | |
|
14 | # TODO Show confirmation page before ban | |
|
15 | ban, created = Ban.objects.get_or_create(ip=post.poster_ip) | |
|
16 | if created: | |
|
17 | ban.reason = 'Banned for post ' + str(post_id) | |
|
18 | ban.save() | |
|
19 | ||
|
20 | return self.redirect_to_next(request) |
@@ -5,6 +5,7 b' from boards.views import api, tag_thread' | |||
|
5 | 5 | login, settings, all_tags |
|
6 | 6 | from boards.views.authors import AuthorsView |
|
7 | 7 | from boards.views.delete_post import DeletePostView |
|
8 | from boards.views.ban import BanUserView | |
|
8 | 9 | |
|
9 | 10 | js_info_dict = { |
|
10 | 11 | 'packages': ('boards',), |
@@ -52,7 +53,7 b" urlpatterns = patterns(''," | |||
|
52 | 53 | url(r'^authors/$', AuthorsView.as_view(), name='authors'), |
|
53 | 54 | url(r'^delete/(?P<post_id>\w+)/$', DeletePostView.as_view(), |
|
54 | 55 | name='delete'), |
|
55 |
url(r'^ban/(?P<post_id>\w+)/$', |
|
|
56 | url(r'^ban/(?P<post_id>\w+)/$', BanUserView.as_view(), name='ban'), | |
|
56 | 57 | |
|
57 | 58 | url(r'^banned/$', views.banned.BannedView.as_view(), name='banned'), |
|
58 | 59 | url(r'^staticpage/(?P<name>\w+)/$', views.static_page, name='staticpage'), |
@@ -43,40 +43,6 b' def jump_to_post(request, post_id):' | |||
|
43 | 43 | |
|
44 | 44 | |
|
45 | 45 | |
|
46 | @transaction.atomic | |
|
47 | def delete(request, post_id): | |
|
48 | """Delete post""" | |
|
49 | ||
|
50 | user = _get_user(request) | |
|
51 | post = get_object_or_404(Post, id=post_id) | |
|
52 | ||
|
53 | if user.is_moderator(): | |
|
54 | # TODO Show confirmation page before deletion | |
|
55 | Post.objects.delete_post(post) | |
|
56 | ||
|
57 | if not post.thread: | |
|
58 | return _redirect_to_next(request) | |
|
59 | else: | |
|
60 | return redirect('thread', post_id=post.thread.id) | |
|
61 | ||
|
62 | ||
|
63 | @transaction.atomic | |
|
64 | def ban(request, post_id): | |
|
65 | """Ban user""" | |
|
66 | ||
|
67 | user = _get_user(request) | |
|
68 | post = get_object_or_404(Post, id=post_id) | |
|
69 | ||
|
70 | if user.is_moderator(): | |
|
71 | # TODO Show confirmation page before ban | |
|
72 | ban, created = Ban.objects.get_or_create(ip=post.poster_ip) | |
|
73 | if created: | |
|
74 | ban.reason = 'Banned for post ' + str(post_id) | |
|
75 | ban.save() | |
|
76 | ||
|
77 | return _redirect_to_next(request) | |
|
78 | ||
|
79 | ||
|
80 | 46 | def page_404(request): |
|
81 | 47 | """Show page 404 (not found error)""" |
|
82 | 48 |
General Comments 0
You need to be logged in to leave comments.
Login now