context_processors.py
42 lines
| 1.1 KiB
| text/x-python
|
PythonLexer
/ boards / context_processors.py
neko259
|
r730 | from boards.abstracts.settingsmanager import PERMISSION_MODERATE, \ | ||
get_settings_manager | ||||
neko259
|
r728 | |||
neko259
|
r721 | __author__ = 'neko259' | ||
neko259
|
r728 | from boards import settings | ||
neko259
|
r690 | from boards.models import Post | ||
neko259
|
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' | ||||
neko259
|
r690 | |||
neko259
|
r811 | PERMISSION_MODERATE = 'moderation' | ||
neko259
|
r690 | |||
def user_and_ui_processor(request): | ||||
context = {} | ||||
neko259
|
r721 | context[CONTEXT_PPD] = float(Post.objects.get_posts_per_day()) | ||
neko259
|
r690 | |||
neko259
|
r730 | settings_manager = get_settings_manager(request) | ||
neko259
|
r728 | context[CONTEXT_TAGS] = settings_manager.get_fav_tags() | ||
theme = settings_manager.get_theme() | ||||
neko259
|
r721 | context[CONTEXT_THEME] = theme | ||
context[CONTEXT_THEME_CSS] = 'css/' + theme + '/base_page.css' | ||||
neko259
|
r690 | |||
# This shows the moderator panel | ||||
neko259
|
r813 | try: | ||
moderate = request.user.has_perm('moderation') | ||||
except AttributeError: | ||||
moderate = False | ||||
neko259
|
r728 | context[CONTEXT_MODERATOR] = moderate | ||
neko259
|
r690 | |||
neko259
|
r721 | context[CONTEXT_VERSION] = settings.VERSION | ||
context[CONTEXT_SITE_NAME] = settings.SITE_NAME | ||||
neko259
|
r690 | |||
neko259
|
r811 | return context | ||