Show More
@@ -1,6 +1,6 b'' | |||
|
1 | from django.core.paginator import Paginator | |
|
1 | __author__ = 'neko259' | |
|
2 | 2 | |
|
3 | __author__ = 'neko259' | |
|
3 | from django.core.paginator import Paginator | |
|
4 | 4 | |
|
5 | 5 | PAGINATOR_LOOKAROUND_SIZE = 3 |
|
6 | 6 |
@@ -8,9 +8,14 b' from boards.abstracts.paginator import g' | |||
|
8 | 8 | from boards.forms import ThreadForm, PlainErrorList |
|
9 | 9 | from boards.models import Post, Thread, Ban, Tag |
|
10 | 10 | from boards.views.banned import BannedView |
|
11 |
from boards.views.base import BaseBoardView, |
|
|
11 | from boards.views.base import BaseBoardView, CONTEXT_FORM | |
|
12 | 12 | from boards.views.posting_mixin import PostMixin |
|
13 | 13 | |
|
14 | FORM_TAGS = 'tags' | |
|
15 | FORM_TEXT = 'text' | |
|
16 | FORM_TITLE = 'title' | |
|
17 | FORM_IMAGE = 'image' | |
|
18 | ||
|
14 | 19 | TAG_DELIMITER = ' ' |
|
15 | 20 | |
|
16 | 21 | PARAMETER_CURRENT_PAGE = 'current_page' |
@@ -40,7 +45,7 b' class AllThreadsView(PostMixin, BaseBoar' | |||
|
40 | 45 | threads = paginator.page(page).object_list |
|
41 | 46 | |
|
42 | 47 | context[PARAMETER_THREADS] = threads |
|
43 |
context[ |
|
|
48 | context[CONTEXT_FORM] = form | |
|
44 | 49 | |
|
45 | 50 | self._get_page_context(paginator, context, page) |
|
46 | 51 | |
@@ -103,17 +108,17 b' class AllThreadsView(PostMixin, BaseBoar' | |||
|
103 | 108 | |
|
104 | 109 | data = form.cleaned_data |
|
105 | 110 | |
|
106 |
title = data[ |
|
|
107 |
text = data[ |
|
|
111 | title = data[FORM_TITLE] | |
|
112 | text = data[FORM_TEXT] | |
|
108 | 113 | |
|
109 | 114 | text = self._remove_invalid_links(text) |
|
110 | 115 | |
|
111 |
if |
|
|
112 |
image = data[ |
|
|
116 | if FORM_IMAGE in data.keys(): | |
|
117 | image = data[FORM_IMAGE] | |
|
113 | 118 | else: |
|
114 | 119 | image = None |
|
115 | 120 | |
|
116 |
tag_strings = data[ |
|
|
121 | tag_strings = data[FORM_TAGS] | |
|
117 | 122 | |
|
118 | 123 | tags = self.parse_tags_string(tag_strings) |
|
119 | 124 |
@@ -8,7 +8,7 b' from boards.models.user import Ban' | |||
|
8 | 8 | |
|
9 | 9 | BAN_REASON_SPAM = 'Autoban: spam bot' |
|
10 | 10 | |
|
11 |
|
|
|
11 | CONTEXT_FORM = 'form' | |
|
12 | 12 | |
|
13 | 13 | |
|
14 | 14 | class BaseBoardView(View): |
@@ -1,7 +1,7 b'' | |||
|
1 | 1 | from django.shortcuts import render, redirect |
|
2 | 2 | from boards.forms import LoginForm, PlainErrorList |
|
3 | 3 | from boards.models import User |
|
4 |
from boards.views.base import BaseBoardView, |
|
|
4 | from boards.views.base import BaseBoardView, CONTEXT_FORM | |
|
5 | 5 | |
|
6 | 6 | __author__ = 'neko259' |
|
7 | 7 | |
@@ -13,7 +13,7 b' class LoginView(BaseBoardView):' | |||
|
13 | 13 | |
|
14 | 14 | if not form: |
|
15 | 15 | form = LoginForm() |
|
16 |
context[ |
|
|
16 | context[CONTEXT_FORM] = form | |
|
17 | 17 | |
|
18 | 18 | return render(request, 'boards/login.html', context) |
|
19 | 19 |
@@ -2,7 +2,7 b' from django.db import transaction' | |||
|
2 | 2 | from django.shortcuts import render, redirect |
|
3 | 3 | from boards import utils |
|
4 | 4 | |
|
5 |
from boards.views.base import BaseBoardView, |
|
|
5 | from boards.views.base import BaseBoardView, CONTEXT_FORM | |
|
6 | 6 | from boards.forms import SettingsForm, ModeratorSettingsForm, PlainErrorList |
|
7 | 7 | from boards.models.post import SETTING_MODERATE |
|
8 | 8 | |
@@ -26,7 +26,7 b' class SettingsView(BaseBoardView):' | |||
|
26 | 26 | form = SettingsForm(initial={'theme': selected_theme}, |
|
27 | 27 | error_class=PlainErrorList) |
|
28 | 28 | |
|
29 |
context[ |
|
|
29 | context[CONTEXT_FORM] = form | |
|
30 | 30 | |
|
31 | 31 | return render(request, 'boards/settings.html', context) |
|
32 | 32 |
@@ -8,17 +8,28 b' from boards import utils, settings' | |||
|
8 | 8 | from boards.forms import PostForm, PlainErrorList |
|
9 | 9 | from boards.models import Post, Ban |
|
10 | 10 | from boards.views.banned import BannedView |
|
11 |
from boards.views.base import BaseBoardView, |
|
|
11 | from boards.views.base import BaseBoardView, CONTEXT_FORM | |
|
12 | 12 | from boards.views.posting_mixin import PostMixin |
|
13 | 13 | |
|
14 | TEMPLATE_GALLERY = 'boards/thread_gallery.html' | |
|
15 | TEMPLATE_NORMAL = 'boards/thread.html' | |
|
16 | ||
|
17 | CONTEXT_POSTS = 'posts' | |
|
18 | CONTEXT_OP = 'opening_post' | |
|
19 | CONTEXT_BUMPLIMIT_PRG = 'bumplimit_progress' | |
|
20 | CONTEXT_POSTS_LEFT = 'posts_left' | |
|
21 | CONTEXT_LASTUPDATE = "last_update" | |
|
22 | CONTEXT_MAX_REPLIES = 'max_replies' | |
|
23 | CONTEXT_THREAD = 'thread' | |
|
24 | CONTEXT_BUMPABLE = 'bumpable' | |
|
25 | ||
|
26 | FORM_TITLE = 'title' | |
|
27 | FORM_TEXT = 'text' | |
|
28 | FORM_IMAGE = 'image' | |
|
14 | 29 | |
|
15 | 30 | MODE_GALLERY = 'gallery' |
|
16 | 31 | MODE_NORMAL = 'normal' |
|
17 | 32 | |
|
18 | PARAMETER_MAX_REPLIES = 'max_replies' | |
|
19 | PARAMETER_THREAD = 'thread' | |
|
20 | PARAMETER_BUMPABLE = 'bumpable' | |
|
21 | ||
|
22 | 33 | |
|
23 | 34 | class ThreadView(BaseBoardView, PostMixin, FormMixin): |
|
24 | 35 | |
@@ -39,29 +50,30 b' class ThreadView(BaseBoardView, PostMixi' | |||
|
39 | 50 | |
|
40 | 51 | context = self.get_context_data(request=request) |
|
41 | 52 | |
|
42 |
context[ |
|
|
43 |
context[ |
|
|
53 | context[CONTEXT_FORM] = form | |
|
54 | context[CONTEXT_LASTUPDATE] = utils.datetime_to_epoch( | |
|
44 | 55 | thread_to_show.last_edit_time) |
|
45 |
context[ |
|
|
46 |
context[ |
|
|
56 | context[CONTEXT_THREAD] = thread_to_show | |
|
57 | context[CONTEXT_MAX_REPLIES] = settings.MAX_POSTS_PER_THREAD | |
|
47 | 58 | |
|
48 | 59 | if MODE_NORMAL == mode: |
|
49 |
|
|
|
50 |
|
|
|
51 | context['posts_left'] = settings.MAX_POSTS_PER_THREAD \ | |
|
60 | bumpable = thread_to_show.can_bump() | |
|
61 | context[CONTEXT_BUMPABLE] = bumpable | |
|
62 | if bumpable: | |
|
63 | left_posts = settings.MAX_POSTS_PER_THREAD \ | |
|
52 | 64 | - thread_to_show.get_reply_count() |
|
53 | context['bumplimit_progress'] = str( | |
|
54 | float(context['posts_left']) / | |
|
55 | settings.MAX_POSTS_PER_THREAD * 100) | |
|
65 | context[CONTEXT_POSTS_LEFT] = left_posts | |
|
66 | context[CONTEXT_BUMPLIMIT_PRG] = str( | |
|
67 | float(left_posts) / settings.MAX_POSTS_PER_THREAD * 100) | |
|
56 | 68 | |
|
57 |
context[ |
|
|
69 | context[CONTEXT_OP] = opening_post | |
|
58 | 70 | |
|
59 | document = 'boards/thread.html' | |
|
71 | document = TEMPLATE_NORMAL | |
|
60 | 72 | elif MODE_GALLERY == mode: |
|
61 |
context[ |
|
|
73 | context[CONTEXT_POSTS] = thread_to_show.get_replies_with_images( | |
|
62 | 74 | view_fields_only=True) |
|
63 | 75 | |
|
64 | document = 'boards/thread_gallery.html' | |
|
76 | document = TEMPLATE_GALLERY | |
|
65 | 77 | else: |
|
66 | 78 | raise Http404 |
|
67 | 79 | |
@@ -102,13 +114,13 b' class ThreadView(BaseBoardView, PostMixi' | |||
|
102 | 114 | |
|
103 | 115 | data = form.cleaned_data |
|
104 | 116 | |
|
105 |
title = data[ |
|
|
106 |
text = data[ |
|
|
117 | title = data[FORM_TITLE] | |
|
118 | text = data[FORM_TEXT] | |
|
107 | 119 | |
|
108 | 120 | text = self._remove_invalid_links(text) |
|
109 | 121 | |
|
110 |
if |
|
|
111 |
image = data[ |
|
|
122 | if FORM_IMAGE in data.keys(): | |
|
123 | image = data[FORM_IMAGE] | |
|
112 | 124 | else: |
|
113 | 125 | image = None |
|
114 | 126 | |
@@ -125,8 +137,8 b' class ThreadView(BaseBoardView, PostMixi' | |||
|
125 | 137 | |
|
126 | 138 | if html_response: |
|
127 | 139 | if opening_post: |
|
128 |
return redirect( |
|
|
129 | 'thread', | |
|
130 |
|
|
|
140 | return redirect( | |
|
141 | reverse('thread', kwargs={'post_id': thread_to_show}) | |
|
142 | + '#' + str(post.id)) | |
|
131 | 143 | else: |
|
132 | 144 | return post |
General Comments 0
You need to be logged in to leave comments.
Login now