|
|
from boards.abstracts.settingsmanager import get_settings_manager, \
|
|
|
SETTING_USERNAME, SETTING_LAST_NOTIFICATION_ID
|
|
|
from boards.models.user import Notification
|
|
|
|
|
|
__author__ = 'neko259'
|
|
|
|
|
|
from boards import settings
|
|
|
from boards.models import Post
|
|
|
|
|
|
CONTEXT_SITE_NAME = 'site_name'
|
|
|
CONTEXT_VERSION = 'version'
|
|
|
CONTEXT_MODERATOR = 'moderator'
|
|
|
CONTEXT_THEME_CSS = 'theme_css'
|
|
|
CONTEXT_THEME = 'theme'
|
|
|
CONTEXT_PPD = 'posts_per_day'
|
|
|
CONTEXT_TAGS = 'tags'
|
|
|
CONTEXT_USER = 'user'
|
|
|
CONTEXT_NEW_NOTIFICATIONS_COUNT = 'new_notifications_count'
|
|
|
CONTEXT_USERNAME = 'username'
|
|
|
|
|
|
PERMISSION_MODERATE = 'moderation'
|
|
|
|
|
|
|
|
|
def get_notifications(context, request):
|
|
|
settings_manager = get_settings_manager(request)
|
|
|
username = settings_manager.get_setting(SETTING_USERNAME)
|
|
|
new_notifications_count = 0
|
|
|
if username is not None and len(username) > 0:
|
|
|
last_notification_id = settings_manager.get_setting(
|
|
|
SETTING_LAST_NOTIFICATION_ID)
|
|
|
if last_notification_id is not None:
|
|
|
new_notifications_count = Notification.objects.filter(
|
|
|
id__gt=last_notification_id).filter(
|
|
|
name=username).count()
|
|
|
else:
|
|
|
new_notifications_count = Notification.objects.filter(
|
|
|
name=username).count()
|
|
|
context[CONTEXT_NEW_NOTIFICATIONS_COUNT] = new_notifications_count
|
|
|
context[CONTEXT_USERNAME] = username
|
|
|
|
|
|
|
|
|
def get_moderator_permissions(context, request):
|
|
|
try:
|
|
|
moderate = request.user.has_perm(PERMISSION_MODERATE)
|
|
|
except AttributeError:
|
|
|
moderate = False
|
|
|
context[CONTEXT_MODERATOR] = moderate
|
|
|
|
|
|
|
|
|
def user_and_ui_processor(request):
|
|
|
context = dict()
|
|
|
|
|
|
context[CONTEXT_PPD] = float(Post.objects.get_posts_per_day())
|
|
|
|
|
|
settings_manager = get_settings_manager(request)
|
|
|
context[CONTEXT_TAGS] = settings_manager.get_fav_tags()
|
|
|
theme = settings_manager.get_theme()
|
|
|
context[CONTEXT_THEME] = theme
|
|
|
context[CONTEXT_THEME_CSS] = 'css/' + theme + '/base_page.css'
|
|
|
|
|
|
# This shows the moderator panel
|
|
|
get_moderator_permissions(context, request)
|
|
|
|
|
|
context[CONTEXT_VERSION] = settings.VERSION
|
|
|
context[CONTEXT_SITE_NAME] = settings.SITE_NAME
|
|
|
|
|
|
get_notifications(context, request)
|
|
|
|
|
|
return context
|
|
|
|