Show More
@@ -2,4 +2,6 b' import re' | |||||
2 |
|
2 | |||
3 | FILE_DIRECTORY = 'files/' |
|
3 | FILE_DIRECTORY = 'files/' | |
4 | REGEX_TAGS = re.compile(r'^[\w\s\d\']+$', re.UNICODE) |
|
4 | REGEX_TAGS = re.compile(r'^[\w\s\d\']+$', re.UNICODE) | |
5 | REGEX_REPLY = re.compile(r'\[post\](\d+)\[/post\]') No newline at end of file |
|
5 | REGEX_REPLY = re.compile(r'\[post\](\d+)\[/post\]') | |
|
6 | ||||
|
7 | PARAM_PAGE = 'page' No newline at end of file |
@@ -6,6 +6,7 b' from django.utils.decorators import meth' | |||||
6 | from django.views.decorators.csrf import csrf_protect |
|
6 | from django.views.decorators.csrf import csrf_protect | |
7 |
|
7 | |||
8 | from boards import settings |
|
8 | from boards import settings | |
|
9 | from boards.abstracts.constants import PARAM_PAGE | |||
9 | from boards.abstracts.paginator import get_paginator |
|
10 | from boards.abstracts.paginator import get_paginator | |
10 | from boards.abstracts.settingsmanager import get_settings_manager, \ |
|
11 | from boards.abstracts.settingsmanager import get_settings_manager, \ | |
11 | SETTING_ONLY_FAVORITES |
|
12 | SETTING_ONLY_FAVORITES | |
@@ -16,6 +17,10 b' from boards.views.mixins import FileUplo' | |||||
16 | DispatcherMixin, PARAMETER_METHOD |
|
17 | DispatcherMixin, PARAMETER_METHOD | |
17 | from boards.settings import SECTION_VIEW, SECTION_FORMS |
|
18 | from boards.settings import SECTION_VIEW, SECTION_FORMS | |
18 |
|
19 | |||
|
20 | ORDER_BUMP = 'bump' | |||
|
21 | ||||
|
22 | PARAM_ORDER = 'order' | |||
|
23 | ||||
19 | FORM_TAGS = 'tags' |
|
24 | FORM_TAGS = 'tags' | |
20 | FORM_TEXT = 'text' |
|
25 | FORM_TEXT = 'text' | |
21 | FORM_TITLE = 'title' |
|
26 | FORM_TITLE = 'title' | |
@@ -47,29 +52,28 b' class AllThreadsView(FileUploadMixin, Ba' | |||||
47 |
|
52 | |||
48 | @method_decorator(csrf_protect) |
|
53 | @method_decorator(csrf_protect) | |
49 | def get(self, request, form: ThreadForm=None): |
|
54 | def get(self, request, form: ThreadForm=None): | |
50 |
page = request.GET.get( |
|
55 | page = request.GET.get(PARAM_PAGE, DEFAULT_PAGE) | |
51 |
|
56 | |||
52 | params = self.get_context_data(request=request) |
|
57 | params = self.get_context_data(request=request) | |
53 |
|
58 | |||
54 | if not form: |
|
59 | if not form: | |
55 | form = ThreadForm(error_class=PlainErrorList, |
|
60 | form = ThreadForm(error_class=PlainErrorList, | |
56 | initial={FORM_TAGS: self.tag_name}) |
|
61 | initial={FORM_TAGS: self.tag_name}) | |
57 |
|
62 | |||
58 | self.settings_manager = get_settings_manager(request) |
|
63 | self.settings_manager = get_settings_manager(request) | |
59 |
|
64 | |||
60 | threads = self.get_threads() |
|
65 | threads = self.get_threads() | |
61 |
|
66 | |||
62 |
order = request.GET.get( |
|
67 | order = request.GET.get(PARAM_ORDER, ORDER_BUMP) | |
63 |
if order == |
|
68 | if order == ORDER_BUMP: | |
64 | threads = threads.order_by('-bump_time') |
|
69 | threads = threads.order_by('-bump_time') | |
65 | else: |
|
70 | else: | |
66 | threads = threads.filter(replies__opening=True)\ |
|
71 | threads = threads.filter(replies__opening=True)\ | |
67 | .order_by('-replies__pub_time') |
|
72 | .order_by('-replies__pub_time') | |
68 | filter = request.GET.get('filter') |
|
|||
69 | threads = threads.distinct() |
|
73 | threads = threads.distinct() | |
70 |
|
74 | |||
71 | paginator = get_paginator(threads, |
|
75 | paginator = get_paginator(threads, settings.get_int( | |
72 |
|
|
76 | SECTION_VIEW, 'ThreadsPerPage')) | |
73 | paginator.current_page = int(page) |
|
77 | paginator.current_page = int(page) | |
74 |
|
78 | |||
75 | try: |
|
79 | try: | |
@@ -93,7 +97,7 b' class AllThreadsView(FileUploadMixin, Ba' | |||||
93 | if PARAMETER_METHOD in request.POST: |
|
97 | if PARAMETER_METHOD in request.POST: | |
94 | self.dispatch_method(request) |
|
98 | self.dispatch_method(request) | |
95 |
|
99 | |||
96 | return redirect('index') # FIXME Different for different modes |
|
100 | return self.get_reverse_url() | |
97 |
|
101 | |||
98 | form = ThreadForm(request.POST, request.FILES, |
|
102 | form = ThreadForm(request.POST, request.FILES, | |
99 | error_class=PlainErrorList) |
|
103 | error_class=PlainErrorList) |
@@ -2,6 +2,7 b' from django.urls import reverse' | |||||
2 | from django.shortcuts import render |
|
2 | from django.shortcuts import render | |
3 |
|
3 | |||
4 | from boards import settings |
|
4 | from boards import settings | |
|
5 | from boards.abstracts.constants import PARAM_PAGE | |||
5 | from boards.abstracts.paginator import get_paginator |
|
6 | from boards.abstracts.paginator import get_paginator | |
6 | from boards.abstracts.settingsmanager import get_settings_manager |
|
7 | from boards.abstracts.settingsmanager import get_settings_manager | |
7 | from boards.models import Post |
|
8 | from boards.models import Post | |
@@ -101,7 +102,7 b' class FeedView(PaginatedMixin, BaseBoard' | |||||
101 | ) |
|
102 | ) | |
102 |
|
103 | |||
103 | def get(self, request): |
|
104 | def get(self, request): | |
104 |
page = request.GET.get( |
|
105 | page = request.GET.get(PARAM_PAGE, DEFAULT_PAGE) | |
105 |
|
106 | |||
106 | params = self.get_context_data(request=request) |
|
107 | params = self.get_context_data(request=request) | |
107 |
|
108 |
@@ -1,4 +1,5 b'' | |||||
1 | import boards |
|
1 | import boards | |
|
2 | from boards.settings import SECTION_FORMS | |||
2 |
|
3 | |||
3 | PARAM_NEXT = 'next' |
|
4 | PARAM_NEXT = 'next' | |
4 | PARAMETER_METHOD = 'method' |
|
5 | PARAMETER_METHOD = 'method' | |
@@ -36,7 +37,7 b' class DispatcherMixin:' | |||||
36 |
|
37 | |||
37 | class FileUploadMixin: |
|
38 | class FileUploadMixin: | |
38 | def get_max_upload_size(self): |
|
39 | def get_max_upload_size(self): | |
39 |
return boards.settings.get_int( |
|
40 | return boards.settings.get_int(SECTION_FORMS, 'MaxFileSize') | |
40 |
|
41 | |||
41 |
|
42 | |||
42 | class PaginatedMixin: |
|
43 | class PaginatedMixin: |
@@ -1,17 +1,16 b'' | |||||
1 | from django.shortcuts import render |
|
1 | from django.shortcuts import render | |
2 |
|
2 | |||
|
3 | from boards.abstracts.constants import PARAM_PAGE | |||
3 | from boards.abstracts.paginator import get_paginator |
|
4 | from boards.abstracts.paginator import get_paginator | |
4 | from boards.abstracts.settingsmanager import get_settings_manager, \ |
|
5 | from boards.abstracts.settingsmanager import get_settings_manager, \ | |
5 |
|
|
6 | SETTING_LAST_NOTIFICATION_ID | |
6 | from boards.models.user import Notification |
|
7 | from boards.models.user import Notification | |
7 | from boards.views.base import BaseBoardView |
|
8 | from boards.views.base import BaseBoardView | |
8 |
|
9 | |||
9 | DEFAULT_PAGE = '1' |
|
10 | DEFAULT_PAGE = '1' | |
10 |
|
11 | |||
11 | TEMPLATE = 'boards/notifications.html' |
|
12 | TEMPLATE = 'boards/notifications.html' | |
12 | PARAM_PAGE = 'page' |
|
|||
13 | PARAM_USERNAMES = 'notification_usernames' |
|
13 | PARAM_USERNAMES = 'notification_usernames' | |
14 | REQUEST_PAGE = 'page' |
|
|||
15 | RESULTS_PER_PAGE = 10 |
|
14 | RESULTS_PER_PAGE = 10 | |
16 |
|
15 | |||
17 |
|
16 | |||
@@ -41,7 +40,7 b' class NotificationView(BaseBoardView):' | |||||
41 |
|
40 | |||
42 | paginator = get_paginator(posts, RESULTS_PER_PAGE) |
|
41 | paginator = get_paginator(posts, RESULTS_PER_PAGE) | |
43 |
|
42 | |||
44 |
page = int(request.GET.get( |
|
43 | page = int(request.GET.get(PARAM_PAGE, DEFAULT_PAGE)) | |
45 |
|
44 | |||
46 | params[PARAM_PAGE] = paginator.page(page) |
|
45 | params[PARAM_PAGE] = paginator.page(page) | |
47 | params[PARAM_USERNAMES] = notification_usernames |
|
46 | params[PARAM_USERNAMES] = notification_usernames |
@@ -2,6 +2,7 b' from django.shortcuts import get_object_' | |||||
2 | from django.urls import reverse |
|
2 | from django.urls import reverse | |
3 |
|
3 | |||
4 | from boards import settings |
|
4 | from boards import settings | |
|
5 | from boards.abstracts.constants import PARAM_PAGE | |||
5 | from boards.abstracts.paginator import get_paginator |
|
6 | from boards.abstracts.paginator import get_paginator | |
6 | from boards.models import TagAlias |
|
7 | from boards.models import TagAlias | |
7 | from boards.settings import SECTION_VIEW |
|
8 | from boards.settings import SECTION_VIEW | |
@@ -16,7 +17,7 b" TEMPLATE = 'boards/tag_gallery.html'" | |||||
16 | class TagGalleryView(BaseBoardView, PaginatedMixin): |
|
17 | class TagGalleryView(BaseBoardView, PaginatedMixin): | |
17 |
|
18 | |||
18 | def get(self, request, tag_name): |
|
19 | def get(self, request, tag_name): | |
19 |
page = int(request.GET.get( |
|
20 | page = int(request.GET.get(PARAM_PAGE, 1)) | |
20 |
|
21 | |||
21 | params = dict() |
|
22 | params = dict() | |
22 | tag_alias = get_object_or_404(TagAlias, name=tag_name) |
|
23 | tag_alias = get_object_or_404(TagAlias, name=tag_name) |
@@ -1,11 +1,11 b'' | |||||
|
1 | from django.contrib.auth.decorators import permission_required | |||
1 | from django.shortcuts import redirect |
|
2 | from django.shortcuts import redirect | |
2 | from django.utils.decorators import method_decorator |
|
3 | from django.utils.decorators import method_decorator | |
3 | from django.views.decorators.csrf import csrf_protect |
|
4 | from django.views.decorators.csrf import csrf_protect | |
4 | from django.contrib.auth.decorators import permission_required |
|
|||
5 |
|
5 | |||
6 | from boards.views.base import BaseBoardView, CONTEXT_FORM |
|
|||
7 | from boards.views.mixins import DispatcherMixin, PARAMETER_METHOD |
|
|||
8 | from boards.models import Post, Ban |
|
6 | from boards.models import Post, Ban | |
|
7 | from boards.views.base import BaseBoardView | |||
|
8 | from boards.views.mixins import DispatcherMixin | |||
9 |
|
9 | |||
10 |
|
10 | |||
11 | class UtilsView(BaseBoardView, DispatcherMixin): |
|
11 | class UtilsView(BaseBoardView, DispatcherMixin): |
General Comments 0
You need to be logged in to leave comments.
Login now