##// END OF EJS Templates
Don't jquery-select image's post twice
Don't jquery-select image's post twice

File last commit:

r1340:668e9798 default
r1352:60237ae8 default
Show More
context_processors.py
68 lines | 2.3 KiB | text/x-python | PythonLexer
/ boards / context_processors.py
from boards.abstracts.settingsmanager import get_settings_manager, \
SETTING_USERNAME, SETTING_LAST_NOTIFICATION_ID, SETTING_IMAGE_VIEWER
from boards.models.user import Notification
__author__ = 'neko259'
from boards import settings, utils
from boards.models import Post, Tag
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'
CONTEXT_TAGS_STR = 'tags_str'
CONTEXT_IMAGE_VIEWER = 'image_viewer'
CONTEXT_HAS_FAV_THREADS = 'has_fav_threads'
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)
new_notifications_count = Notification.objects.get_notification_posts(
username=username, last=last_notification_id).count()
context[CONTEXT_NEW_NOTIFICATIONS_COUNT] = new_notifications_count
context[CONTEXT_USERNAME] = username
def user_and_ui_processor(request):
context = dict()
context[CONTEXT_PPD] = float(Post.objects.get_posts_per_day())
settings_manager = get_settings_manager(request)
fav_tags = settings_manager.get_fav_tags()
context[CONTEXT_TAGS] = fav_tags
context[CONTEXT_TAGS_STR] = Tag.objects.get_tag_url_list(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
context[CONTEXT_MODERATOR] = utils.is_moderator(request)
context[CONTEXT_VERSION] = settings.get('Version', 'Version')
context[CONTEXT_SITE_NAME] = settings.get('Version', 'SiteName')
context[CONTEXT_IMAGE_VIEWER] = settings_manager.get_setting(
SETTING_IMAGE_VIEWER,
default=settings.get('View', 'DefaultImageViewer'))
context[CONTEXT_HAS_FAV_THREADS] =\
len(settings_manager.get_fav_threads()) > 0
get_notifications(context, request)
return context