Show More
@@ -1,51 +1,52 | |||||
1 | from django.shortcuts import render |
|
1 | from django.shortcuts import render | |
2 | from django.urls import reverse |
|
2 | from django.urls import reverse | |
3 |
|
3 | |||
4 | from boards.abstracts.constants import PARAM_PAGE |
|
4 | from boards.abstracts.constants import PARAM_PAGE | |
5 | from boards.abstracts.paginator import get_paginator |
|
5 | from boards.abstracts.paginator import get_paginator | |
6 | from boards.abstracts.settingsmanager import get_settings_manager, \ |
|
6 | from boards.abstracts.settingsmanager import get_settings_manager, \ | |
7 | SETTING_LAST_NOTIFICATION_ID |
|
7 | SETTING_LAST_NOTIFICATION_ID | |
8 | from boards.models.user import Notification |
|
8 | from boards.models.user import Notification | |
9 | from boards.views.base import BaseBoardView |
|
9 | from boards.views.base import BaseBoardView | |
10 | from boards.views.mixins import PaginatedMixin |
|
10 | from boards.views.mixins import PaginatedMixin | |
11 |
|
11 | |||
12 | DEFAULT_PAGE = '1' |
|
12 | DEFAULT_PAGE = '1' | |
13 |
|
13 | |||
14 | TEMPLATE = 'boards/notifications.html' |
|
14 | TEMPLATE = 'boards/notifications.html' | |
15 | PARAM_USERNAMES = 'notification_usernames' |
|
15 | PARAM_USERNAMES = 'notification_usernames' | |
16 | RESULTS_PER_PAGE = 10 |
|
16 | RESULTS_PER_PAGE = 10 | |
17 |
|
17 | |||
18 |
|
18 | |||
19 | class NotificationView(BaseBoardView, PaginatedMixin): |
|
19 | class NotificationView(BaseBoardView, PaginatedMixin): | |
20 |
|
20 | |||
21 | def get(self, request, username=None): |
|
21 | def get(self, request, username=None): | |
22 | params = self.get_context_data() |
|
22 | params = self.get_context_data() | |
23 |
|
23 | |||
24 | settings_manager = get_settings_manager(request) |
|
24 | settings_manager = get_settings_manager(request) | |
25 |
|
25 | |||
26 | # If we open our notifications, reset the "new" count |
|
26 | # If we open our notifications, reset the "new" count | |
27 | if username is None: |
|
27 | if username is None: | |
28 | notification_usernames = settings_manager.get_notification_usernames() |
|
28 | notification_usernames = settings_manager.get_notification_usernames() | |
29 | else: |
|
29 | else: | |
30 | notification_usernames = [username] |
|
30 | notification_usernames = [username] | |
31 |
|
31 | |||
32 | posts = Notification.objects.get_notification_posts( |
|
32 | posts = Notification.objects.get_notification_posts( | |
33 | usernames=notification_usernames, user_settings=settings_manager.get_user_settings()) |
|
33 | usernames=notification_usernames, user_settings=settings_manager.get_user_settings()) | |
34 |
|
34 | |||
35 | if username is None: |
|
35 | if username is None: | |
36 | last = posts.first() |
|
36 | last = posts.first() | |
37 | if last is not None: |
|
37 | if last is not None: | |
38 | last_id = last.id |
|
38 | last_id = last.id | |
39 | settings_manager.set_setting(SETTING_LAST_NOTIFICATION_ID, |
|
39 | settings_manager.set_setting(SETTING_LAST_NOTIFICATION_ID, | |
40 | last_id) |
|
40 | last_id) | |
41 |
|
41 | |||
42 | page = int(request.GET.get(PARAM_PAGE, DEFAULT_PAGE)) |
|
42 | page = int(request.GET.get(PARAM_PAGE, DEFAULT_PAGE)) | |
43 | paginator = get_paginator(posts, RESULTS_PER_PAGE, |
|
43 | paginator = get_paginator(posts, RESULTS_PER_PAGE, | |
44 | link=reverse('notifications'), |
|
44 | link=reverse('notifications'), | |
45 | params=request.GET.dict()) |
|
45 | params=request.GET.dict()) | |
|
46 | paginator.current_page = page | |||
46 |
|
47 | |||
47 | params[PARAM_PAGE] = paginator.page(page) |
|
48 | params[PARAM_PAGE] = paginator.page(page) | |
48 | params[PARAM_USERNAMES] = notification_usernames |
|
49 | params[PARAM_USERNAMES] = notification_usernames | |
49 | params.update(self.get_page_context(paginator, page)) |
|
50 | params.update(self.get_page_context(paginator, page)) | |
50 |
|
51 | |||
51 | return render(request, TEMPLATE, params) |
|
52 | return render(request, TEMPLATE, params) |
@@ -1,55 +1,55 | |||||
1 | from django.shortcuts import render |
|
1 | from django.shortcuts import render | |
2 | from django.views.generic import View |
|
2 | from django.views.generic import View | |
3 | from django.db.models import Q |
|
3 | from django.db.models import Q | |
4 | from django.urls import reverse |
|
4 | from django.urls import reverse | |
5 |
|
5 | |||
6 | from boards.abstracts.paginator import get_paginator |
|
6 | from boards.abstracts.paginator import get_paginator | |
7 | from boards.forms import SearchForm, PlainErrorList |
|
7 | from boards.forms import SearchForm, PlainErrorList | |
8 | from boards.models import Post, Tag |
|
8 | from boards.models import Post, Tag | |
9 | from boards.views.mixins import PaginatedMixin |
|
9 | from boards.views.mixins import PaginatedMixin | |
10 |
|
10 | |||
11 |
|
11 | |||
12 | MIN_QUERY_LENGTH = 3 |
|
12 | MIN_QUERY_LENGTH = 3 | |
13 | RESULTS_PER_PAGE = 10 |
|
13 | RESULTS_PER_PAGE = 10 | |
14 |
|
14 | |||
15 | FORM_QUERY = 'query' |
|
15 | FORM_QUERY = 'query' | |
16 |
|
16 | |||
17 | CONTEXT_QUERY = 'query' |
|
17 | CONTEXT_QUERY = 'query' | |
18 | CONTEXT_FORM = 'form' |
|
18 | CONTEXT_FORM = 'form' | |
19 | CONTEXT_PAGE = 'page' |
|
|||
20 | CONTEXT_TAGS = 'tags' |
|
19 | CONTEXT_TAGS = 'tags' | |
21 |
|
20 | |||
22 | REQUEST_PAGE = 'page' |
|
21 | REQUEST_PAGE = 'page' | |
23 |
|
22 | |||
24 | __author__ = 'neko259' |
|
23 | __author__ = 'neko259' | |
25 |
|
24 | |||
26 | TEMPLATE = 'search/search.html' |
|
25 | TEMPLATE = 'search/search.html' | |
27 |
|
26 | |||
28 |
|
27 | |||
29 | class BoardSearchView(View, PaginatedMixin): |
|
28 | class BoardSearchView(View, PaginatedMixin): | |
30 | def get(self, request): |
|
29 | def get(self, request): | |
31 | params = dict() |
|
30 | params = dict() | |
32 |
|
31 | |||
33 | form = SearchForm(request.GET, error_class=PlainErrorList) |
|
32 | form = SearchForm(request.GET, error_class=PlainErrorList) | |
34 | params[CONTEXT_FORM] = form |
|
33 | params[CONTEXT_FORM] = form | |
35 |
|
34 | |||
36 | if form.is_valid(): |
|
35 | if form.is_valid(): | |
37 | query = form.cleaned_data[FORM_QUERY] |
|
36 | query = form.cleaned_data[FORM_QUERY] | |
38 | if len(query) >= MIN_QUERY_LENGTH: |
|
37 | if len(query) >= MIN_QUERY_LENGTH: | |
|
38 | page = int(request.GET.get(REQUEST_PAGE, '1')) | |||
|
39 | ||||
39 | results = Post.objects.filter(Q(text__icontains=query) |
|
40 | results = Post.objects.filter(Q(text__icontains=query) | |
40 | | Q(title__icontains=query) | Q(opening=True, |
|
41 | | Q(title__icontains=query) | Q(opening=True, | |
41 | thread__tags__aliases__name__icontains=query) |
|
42 | thread__tags__aliases__name__icontains=query) | |
42 | | Q(attachments__url__icontains=query)).order_by('-id').distinct() |
|
43 | | Q(attachments__url__icontains=query)).order_by('-id').distinct() | |
43 | paginator = get_paginator(results, RESULTS_PER_PAGE, |
|
44 | paginator = get_paginator(results, RESULTS_PER_PAGE, | |
44 | link=reverse('search'), |
|
45 | link=reverse('search'), | |
45 | params=request.GET.dict()) |
|
46 | params=request.GET.dict()) | |
46 |
|
47 | paginator.current_page = page | ||
47 | page = int(request.GET.get(REQUEST_PAGE, '1')) |
|
|||
48 |
|
48 | |||
49 | params[CONTEXT_QUERY] = query |
|
49 | params[CONTEXT_QUERY] = query | |
50 | params.update(self.get_page_context(paginator, page)) |
|
50 | params.update(self.get_page_context(paginator, page)) | |
51 |
|
51 | |||
52 | tags = Tag.objects.get_tag_url_list(Tag.objects.filter(aliases__name__icontains=query)) |
|
52 | tags = Tag.objects.get_tag_url_list(Tag.objects.filter(aliases__name__icontains=query)) | |
53 | params[CONTEXT_TAGS] = tags |
|
53 | params[CONTEXT_TAGS] = tags | |
54 |
|
54 | |||
55 | return render(request, TEMPLATE, params) |
|
55 | return render(request, TEMPLATE, params) |
General Comments 0
You need to be logged in to leave comments.
Login now