Show More
@@ -1,12 +1,13 | |||
|
1 | 1 | from django.shortcuts import render |
|
2 | 2 | |
|
3 | 3 | from boards.authors import authors |
|
4 | 4 | from boards.views.base import BaseBoardView |
|
5 | 5 | |
|
6 | ||
|
6 | 7 | class AuthorsView(BaseBoardView): |
|
7 | 8 | |
|
8 | 9 | def get(self, request): |
|
9 | 10 | context = self.get_context_data(request=request) |
|
10 | 11 | context['authors'] = authors |
|
11 | 12 | |
|
12 | 13 | return render(request, 'boards/authors.html', context) |
@@ -1,20 +1,22 | |||
|
1 | 1 | from django.db import transaction |
|
2 | from django.shortcuts import get_object_or_404 | |
|
2 | 3 | |
|
3 | 4 | from boards.views.base import BaseBoardView |
|
4 | 5 | from boards.models import Post, Ban |
|
5 | 6 | |
|
7 | ||
|
6 | 8 | class BanUserView(BaseBoardView): |
|
7 | 9 | |
|
8 | 10 | @transaction.atomic |
|
9 | 11 | def get(self, request, post_id): |
|
10 | 12 | user = self._get_user(request) |
|
11 | 13 | post = get_object_or_404(Post, id=post_id) |
|
12 | 14 | |
|
13 | 15 | if user.is_moderator(): |
|
14 | 16 | # TODO Show confirmation page before ban |
|
15 | 17 | ban, created = Ban.objects.get_or_create(ip=post.poster_ip) |
|
16 | 18 | if created: |
|
17 | 19 | ban.reason = 'Banned for post ' + str(post_id) |
|
18 | 20 | ban.save() |
|
19 | 21 | |
|
20 | 22 | return self.redirect_to_next(request) |
@@ -1,25 +1,26 | |||
|
1 | 1 | from django.shortcuts import redirect, get_object_or_404 |
|
2 | 2 | from django.db import transaction |
|
3 | 3 | |
|
4 | 4 | from boards.views.base import BaseBoardView |
|
5 | 5 | from boards.views.redirect_next_mixin import RedirectNextMixin |
|
6 | 6 | from boards.models import Post |
|
7 | 7 | |
|
8 | ||
|
8 | 9 | class DeletePostView(BaseBoardView, RedirectNextMixin): |
|
9 | 10 | |
|
10 | 11 | @transaction.atomic |
|
11 | 12 | def get(self, request, post_id): |
|
12 | 13 | user = self._get_user(request) |
|
13 | 14 | post = get_object_or_404(Post, id=post_id) |
|
14 | 15 | |
|
15 | 16 | opening_post = post.is_opening() |
|
16 | 17 | |
|
17 | 18 | if user.is_moderator(): |
|
18 | 19 | # TODO Show confirmation page before deletion |
|
19 | 20 | Post.objects.delete_post(post) |
|
20 | 21 | |
|
21 | 22 | if not opening_post: |
|
22 | 23 | thread = post.thread_new |
|
23 | 24 | return redirect('thread', post_id=thread.get_opening_post().id) |
|
24 | 25 | else: |
|
25 | 26 | return self.redirect_to_next(request) |
@@ -1,12 +1,13 | |||
|
1 | 1 | from django.shortcuts import render |
|
2 | 2 | |
|
3 | 3 | from boards.views.base import BaseBoardView |
|
4 | 4 | |
|
5 | ||
|
5 | 6 | class NotFoundView(BaseBoardView): |
|
6 | ''' | |
|
7 | """ | |
|
7 | 8 | Page 404 (not found) |
|
8 | ''' | |
|
9 | """ | |
|
9 | 10 | |
|
10 | 11 | def get(self, request): |
|
11 | 12 | context = self.get_context_data(request=request) |
|
12 | 13 | return render(request, 'boards/404.html', context) |
@@ -1,17 +1,18 | |||
|
1 | 1 | from django.shortcuts import redirect |
|
2 | 2 | from django.http import HttpResponseRedirect |
|
3 | 3 | |
|
4 | ||
|
4 | 5 | class RedirectNextMixin: |
|
5 | 6 | |
|
6 | 7 | def redirect_to_next(self, request): |
|
7 | 8 | """ |
|
8 | 9 | If a 'next' parameter was specified, redirect to the next page. This |
|
9 | 10 | is used when the user is required to return to some page after the |
|
10 | 11 | current view has finished its work. |
|
11 | 12 | """ |
|
12 | 13 | |
|
13 | 14 | if 'next' in request.GET: |
|
14 | 15 | next_page = request.GET['next'] |
|
15 | 16 | return HttpResponseRedirect(next_page) |
|
16 | 17 | else: |
|
17 | 18 | return redirect('index') |
@@ -1,50 +1,52 | |||
|
1 | 1 | from django.db import transaction |
|
2 | 2 | from django.shortcuts import render, redirect |
|
3 | 3 | |
|
4 | 4 | from boards.views.base import BaseBoardView, PARAMETER_FORM |
|
5 | 5 | from boards.forms import SettingsForm, ModeratorSettingsForm, PlainErrorList |
|
6 | 6 | from boards.views import SETTING_MODERATE |
|
7 | 7 | |
|
8 | ||
|
8 | 9 | class SettingsView(BaseBoardView): |
|
9 | 10 | |
|
10 | 11 | def get(self, request): |
|
11 | 12 | context = self.get_context_data(request=request) |
|
12 | 13 | user = context['user'] |
|
13 | 14 | is_moderator = user.is_moderator() |
|
14 | 15 | |
|
15 | 16 | selected_theme = context['theme'] |
|
16 | 17 | |
|
17 | 18 | if is_moderator: |
|
18 |
form = ModeratorSettingsForm(initial={ |
|
|
19 | 'moderate': context['moderator']}, | |
|
20 | error_class=PlainErrorList) | |
|
19 | form = ModeratorSettingsForm(initial={ | |
|
20 | 'theme': selected_theme, | |
|
21 | 'moderate': context['moderator'] | |
|
22 | }, error_class=PlainErrorList) | |
|
21 | 23 | else: |
|
22 | 24 | form = SettingsForm(initial={'theme': selected_theme}, |
|
23 | 25 | error_class=PlainErrorList) |
|
24 | 26 | |
|
25 | 27 | context[PARAMETER_FORM] = form |
|
26 | 28 | |
|
27 | 29 | return render(request, 'boards/settings.html', context) |
|
28 | 30 | |
|
29 | 31 | def post(self, request): |
|
30 | 32 | context = self.get_context_data(request=request) |
|
31 | 33 | user = context['user'] |
|
32 | 34 | is_moderator = user.is_moderator() |
|
33 | 35 | |
|
34 | 36 | with transaction.atomic(): |
|
35 | 37 | if is_moderator: |
|
36 | 38 | form = ModeratorSettingsForm(request.POST, |
|
37 | 39 | error_class=PlainErrorList) |
|
38 | 40 | else: |
|
39 | 41 | form = SettingsForm(request.POST, error_class=PlainErrorList) |
|
40 | 42 | |
|
41 | 43 | if form.is_valid(): |
|
42 | 44 | selected_theme = form.cleaned_data['theme'] |
|
43 | 45 | |
|
44 | 46 | user.save_setting('theme', selected_theme) |
|
45 | 47 | |
|
46 | 48 | if is_moderator: |
|
47 | 49 | moderate = form.cleaned_data['moderate'] |
|
48 | 50 | user.save_setting(SETTING_MODERATE, moderate) |
|
49 | 51 | |
|
50 | 52 | return redirect('settings') |
@@ -1,121 +1,121 | |||
|
1 | 1 | import string |
|
2 | 2 | from django.core.urlresolvers import reverse |
|
3 | 3 | from django.db import transaction |
|
4 | 4 | from django.http import Http404 |
|
5 | 5 | from django.shortcuts import get_object_or_404, render, redirect |
|
6 | 6 | from boards import utils |
|
7 | 7 | from boards.forms import PostForm, PlainErrorList |
|
8 | 8 | from boards.models import Post, Ban, Tag |
|
9 | 9 | from boards.views.banned import BannedView |
|
10 | 10 | from boards.views.base import BaseBoardView, PARAMETER_FORM |
|
11 | 11 | from boards.views.posting_mixin import PostMixin |
|
12 | 12 | import neboard |
|
13 | 13 | |
|
14 | 14 | MODE_GALLERY = 'gallery' |
|
15 | 15 | MODE_NORMAL = 'normal' |
|
16 | 16 | |
|
17 | 17 | |
|
18 | 18 | class ThreadView(BaseBoardView, PostMixin): |
|
19 | 19 | |
|
20 | 20 | def get(self, request, post_id, mode=MODE_NORMAL, form=None): |
|
21 | 21 | opening_post = get_object_or_404(Post, id=post_id) |
|
22 | 22 | |
|
23 | 23 | # If this is not OP, don't show it as it is |
|
24 | 24 | if not opening_post.is_opening(): |
|
25 | 25 | raise Http404 |
|
26 | 26 | |
|
27 | 27 | if not form: |
|
28 | 28 | form = PostForm(error_class=PlainErrorList) |
|
29 | 29 | |
|
30 | 30 | thread_to_show = opening_post.thread_new |
|
31 | 31 | |
|
32 | 32 | context = self.get_context_data(request=request) |
|
33 | 33 | |
|
34 | 34 | posts = thread_to_show.get_replies() |
|
35 | 35 | context[PARAMETER_FORM] = form |
|
36 | 36 | context["last_update"] = utils.datetime_to_epoch( |
|
37 | 37 | thread_to_show.last_edit_time) |
|
38 | 38 | context["thread"] = thread_to_show |
|
39 | 39 | |
|
40 | 40 | if MODE_NORMAL == mode: |
|
41 | 41 | context['bumpable'] = thread_to_show.can_bump() |
|
42 | 42 | if context['bumpable']: |
|
43 | 43 | context['posts_left'] = neboard.settings.MAX_POSTS_PER_THREAD - posts \ |
|
44 | 44 | .count() |
|
45 | 45 | context['bumplimit_progress'] = str( |
|
46 | 46 | float(context['posts_left']) / |
|
47 | 47 | neboard.settings.MAX_POSTS_PER_THREAD * 100) |
|
48 | 48 | |
|
49 | 49 | context['posts'] = posts |
|
50 | 50 | |
|
51 | 51 | document = 'boards/thread.html' |
|
52 | 52 | elif MODE_GALLERY == mode: |
|
53 | 53 | context['posts'] = posts.filter(image_width__gt=0) |
|
54 | 54 | |
|
55 | 55 | document = 'boards/thread_gallery.html' |
|
56 | 56 | else: |
|
57 | 57 | raise Http404 |
|
58 | 58 | |
|
59 | 59 | return render(request, document, context) |
|
60 | 60 | |
|
61 | 61 | def post(self, request, post_id, mode=MODE_NORMAL): |
|
62 | 62 | opening_post = get_object_or_404(Post, id=post_id) |
|
63 | 63 | |
|
64 | 64 | # If this is not OP, don't show it as it is |
|
65 | 65 | if not opening_post.is_opening(): |
|
66 | 66 | raise Http404 |
|
67 | 67 | |
|
68 | 68 | if not opening_post.thread_new.archived: |
|
69 | 69 | form = PostForm(request.POST, request.FILES, |
|
70 | 70 | error_class=PlainErrorList) |
|
71 | 71 | form.session = request.session |
|
72 | 72 | |
|
73 | 73 | if form.is_valid(): |
|
74 | 74 | return self.new_post(request, form, opening_post) |
|
75 | 75 | if form.need_to_ban: |
|
76 | 76 | # Ban user because he is suspected to be a bot |
|
77 | 77 | self._ban_current_user(request) |
|
78 | 78 | |
|
79 | 79 | return self.get(request, post_id, mode, form) |
|
80 | 80 | |
|
81 | 81 | @transaction.atomic |
|
82 | 82 | def new_post(self, request, form, opening_post=None, html_response=True): |
|
83 | 83 | """Add a new post (in thread or as a reply).""" |
|
84 | 84 | |
|
85 | 85 | ip = utils.get_client_ip(request) |
|
86 | 86 | is_banned = Ban.objects.filter(ip=ip).exists() |
|
87 | 87 | |
|
88 | 88 | if is_banned: |
|
89 | 89 | if html_response: |
|
90 | 90 | return redirect(BannedView().as_view()) |
|
91 | 91 | else: |
|
92 | 92 | return |
|
93 | 93 | |
|
94 | 94 | data = form.cleaned_data |
|
95 | 95 | |
|
96 | 96 | title = data['title'] |
|
97 | 97 | text = data['text'] |
|
98 | 98 | |
|
99 | 99 | text = self._remove_invalid_links(text) |
|
100 | 100 | |
|
101 | 101 | if 'image' in data.keys(): |
|
102 | 102 | image = data['image'] |
|
103 | 103 | else: |
|
104 | 104 | image = None |
|
105 | 105 | |
|
106 | 106 | tags = [] |
|
107 | 107 | |
|
108 | 108 | post_thread = opening_post.thread_new |
|
109 | 109 | |
|
110 | 110 | post = Post.objects.create_post(title=title, text=text, ip=ip, |
|
111 | 111 | thread=post_thread, image=image, |
|
112 | 112 | tags=tags, |
|
113 | 113 | user=self._get_user(request)) |
|
114 | 114 | |
|
115 | 115 | thread_to_show = (opening_post.id if opening_post else post.id) |
|
116 | 116 | |
|
117 | 117 | if html_response: |
|
118 | 118 | if opening_post: |
|
119 |
return redirect(reverse( |
|
|
120 | kwargs={'post_id': thread_to_show}) + '#' | |
|
121 |
|
|
|
119 | return redirect(reverse( | |
|
120 | 'thread', | |
|
121 | kwargs={'post_id': thread_to_show}) + '#' + str(post.id)) |
General Comments 0
You need to be logged in to leave comments.
Login now