context_processors.py
38 lines
| 1.1 KiB
| text/x-python
|
PythonLexer
/ boards / context_processors.py
|
r721 | __author__ = 'neko259' | |
|
r716 | from boards import utils, settings | |
|
r690 | from boards.models import Post | |
from boards.models.post import SETTING_MODERATE | |||
|
r721 | 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' | |||
|
r690 | ||
def user_and_ui_processor(request): | |||
context = {} | |||
user = utils.get_user(request) | |||
|
r721 | context[CONTEXT_USER] = user | |
context[CONTEXT_TAGS] = user.fav_tags.all() | |||
context[CONTEXT_PPD] = float(Post.objects.get_posts_per_day()) | |||
|
r690 | ||
theme = utils.get_theme(request, user) | |||
|
r721 | context[CONTEXT_THEME] = theme | |
context[CONTEXT_THEME_CSS] = 'css/' + theme + '/base_page.css' | |||
|
r690 | ||
# This shows the moderator panel | |||
moderate = user.get_setting(SETTING_MODERATE) | |||
if moderate == 'True': | |||
|
r721 | context[CONTEXT_MODERATOR] = user.is_moderator() | |
|
r690 | else: | |
|
r721 | context[CONTEXT_MODERATOR] = False | |
|
r690 | ||
|
r721 | context[CONTEXT_VERSION] = settings.VERSION | |
context[CONTEXT_SITE_NAME] = settings.SITE_NAME | |||
|
r690 | ||
return context |