##// END OF EJS Templates
Simplify paginator page list building and unified it between different views
Simplify paginator page list building and unified it between different views

File last commit:

r2061:b31844e6 default
r2061:b31844e6 default
Show More
notifications.py
51 lines | 1.8 KiB | text/x-python | PythonLexer
neko259
User notifications (BB-59)
r990 from django.shortcuts import render
neko259
Simplify paginator page list building and unified it between different views
r2061 from django.urls import reverse
neko259
Refactored views
r1090
neko259
Even more refactoring
r2005 from boards.abstracts.constants import PARAM_PAGE
neko259
User notifications (BB-59)
r990 from boards.abstracts.paginator import get_paginator
from boards.abstracts.settingsmanager import get_settings_manager, \
neko259
Even more refactoring
r2005 SETTING_LAST_NOTIFICATION_ID
neko259
User notifications (BB-59)
r990 from boards.models.user import Notification
from boards.views.base import BaseBoardView
neko259
Simplify paginator page list building and unified it between different views
r2061 from boards.views.mixins import PaginatedMixin
neko259
User notifications (BB-59)
r990
neko259
Refactored views
r1090 DEFAULT_PAGE = '1'
neko259
User notifications (BB-59)
r990 TEMPLATE = 'boards/notifications.html'
neko259
Subscribe to a multiple of users for notifications
r1429 PARAM_USERNAMES = 'notification_usernames'
neko259
User notifications (BB-59)
r990 RESULTS_PER_PAGE = 10
neko259
Simplify paginator page list building and unified it between different views
r2061 class NotificationView(BaseBoardView, PaginatedMixin):
neko259
User notifications (BB-59)
r990
neko259
Subscribe to a multiple of users for notifications
r1429 def get(self, request, username=None):
neko259
User notifications (BB-59)
r990 params = self.get_context_data()
settings_manager = get_settings_manager(request)
# If we open our notifications, reset the "new" count
neko259
Subscribe to a multiple of users for notifications
r1429 if username is None:
notification_usernames = settings_manager.get_notification_usernames()
else:
notification_usernames = [username]
neko259
Use only lowercase name in notifications. Refactored post manager and refmap...
r1008
posts = Notification.objects.get_notification_posts(
neko259
Do not load fav tags when need to only check notifications
r2056 usernames=notification_usernames, user_settings=settings_manager.get_user_settings())
neko259
Subscribe to a multiple of users for notifications
r1429
if username is None:
neko259
Added notification API
r994 last = posts.first()
neko259
User notifications (BB-59)
r990 if last is not None:
last_id = last.id
settings_manager.set_setting(SETTING_LAST_NOTIFICATION_ID,
last_id)
neko259
Even more refactoring
r2005 page = int(request.GET.get(PARAM_PAGE, DEFAULT_PAGE))
neko259
Simplify paginator page list building and unified it between different views
r2061 paginator = get_paginator(posts, RESULTS_PER_PAGE,
link=reverse('notifications'),
params=request.GET.dict())
neko259
User notifications (BB-59)
r990
params[PARAM_PAGE] = paginator.page(page)
neko259
Subscribe to a multiple of users for notifications
r1429 params[PARAM_USERNAMES] = notification_usernames
neko259
Simplify paginator page list building and unified it between different views
r2061 params.update(self.get_page_context(paginator, page))
neko259
User notifications (BB-59)
r990
return render(request, TEMPLATE, params)