##// END OF EJS Templates
Do not try to add an attachment ref for external attachment if there is an internal and external attachment in the same post
Do not try to add an attachment ref for external attachment if there is an internal and external attachment in the same post

File last commit:

r1760:641fa167 default
r1839:4c8bff54 default
Show More
context_processors.py
85 lines | 3.2 KiB | text/x-python | PythonLexer
/ boards / context_processors.py
from boards.abstracts.settingsmanager import get_settings_manager, \
SETTING_LAST_NOTIFICATION_ID, SETTING_IMAGE_VIEWER, SETTING_ONLY_FAVORITES
from boards.models import Banner
from boards.models.user import Notification
from boards import settings
from boards.models import Post, Tag, Thread
CONTEXT_SITE_NAME = 'site_name'
CONTEXT_VERSION = 'version'
CONTEXT_THEME_CSS = 'theme_css'
CONTEXT_THEME = 'theme'
CONTEXT_PPD = 'posts_per_day'
CONTEXT_USER = 'user'
CONTEXT_NEW_NOTIFICATIONS_COUNT = 'new_notifications_count'
CONTEXT_USERNAMES = 'usernames'
CONTEXT_TAGS_STR = 'tags_str'
CONTEXT_IMAGE_VIEWER = 'image_viewer'
CONTEXT_HAS_FAV_THREADS = 'has_fav_threads'
CONTEXT_POW_DIFFICULTY = 'pow_difficulty'
CONTEXT_NEW_POST_COUNT = 'new_post_count'
CONTEXT_BANNERS = 'banners'
CONTEXT_ONLY_FAVORITES = 'only_favorites'
def get_notifications(context, settings_manager):
usernames = settings_manager.get_notification_usernames()
new_notifications_count = 0
if usernames:
last_notification_id = settings_manager.get_setting(
SETTING_LAST_NOTIFICATION_ID)
new_notifications_count = Notification.objects.get_notification_posts(
usernames=usernames, last=last_notification_id).only('id').count()
context[CONTEXT_NEW_NOTIFICATIONS_COUNT] = new_notifications_count
context[CONTEXT_USERNAMES] = usernames
def get_new_post_count(context, settings_manager):
fav_threads = settings_manager.get_fav_threads()
if fav_threads:
fav_thread_ops = Post.objects.filter(id__in=fav_threads.keys()) \
.order_by('-pub_time').only('thread_id', 'pub_time')
ops = [{'op': op, 'last_id': fav_threads[str(op.id)]} for op in fav_thread_ops]
count = Thread.objects.get_new_post_count(ops)
if count > 0:
context[CONTEXT_NEW_POST_COUNT] = '(+{})'.format(count)
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_STR] = Tag.objects.get_tag_url_list(fav_tags)
theme = settings_manager.get_theme()
context[CONTEXT_THEME] = theme
# TODO Use static here
context[CONTEXT_THEME_CSS] = 'css/' + theme + '/base_page.css'
context[CONTEXT_VERSION] = settings.get('Version', 'Version')
context[CONTEXT_SITE_NAME] = settings.get('Version', 'SiteName')
if (settings.get_bool('Forms', 'LimitFirstPosting') and not settings_manager.get_setting('confirmed_user'))\
or settings.get_bool('Forms', 'LimitPostingSpeed'):
context[CONTEXT_POW_DIFFICULTY] = settings.get_int('Forms', 'PowDifficulty')
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
context[CONTEXT_BANNERS] = Banner.objects.order_by('-id')
context[CONTEXT_ONLY_FAVORITES] = settings_manager.get_setting(
SETTING_ONLY_FAVORITES, False)
get_notifications(context, settings_manager)
get_new_post_count(context, settings_manager)
return context