##// END OF EJS Templates
Form reset should be a button just like anything else
Form reset should be a button just like anything else

File last commit:

r2056:dcf7666c default
r2060:04bf83ec default
Show More
notifications.py
48 lines | 1.5 KiB | text/x-python | PythonLexer
from django.shortcuts import render
from boards.abstracts.constants import PARAM_PAGE
from boards.abstracts.paginator import get_paginator
from boards.abstracts.settingsmanager import get_settings_manager, \
SETTING_LAST_NOTIFICATION_ID
from boards.models.user import Notification
from boards.views.base import BaseBoardView
DEFAULT_PAGE = '1'
TEMPLATE = 'boards/notifications.html'
PARAM_USERNAMES = 'notification_usernames'
RESULTS_PER_PAGE = 10
class NotificationView(BaseBoardView):
def get(self, request, username=None):
params = self.get_context_data()
settings_manager = get_settings_manager(request)
# If we open our notifications, reset the "new" count
if username is None:
notification_usernames = settings_manager.get_notification_usernames()
else:
notification_usernames = [username]
posts = Notification.objects.get_notification_posts(
usernames=notification_usernames, user_settings=settings_manager.get_user_settings())
if username is None:
last = posts.first()
if last is not None:
last_id = last.id
settings_manager.set_setting(SETTING_LAST_NOTIFICATION_ID,
last_id)
paginator = get_paginator(posts, RESULTS_PER_PAGE)
page = int(request.GET.get(PARAM_PAGE, DEFAULT_PAGE))
params[PARAM_PAGE] = paginator.page(page)
params[PARAM_USERNAMES] = notification_usernames
return render(request, TEMPLATE, params)