from .branding import get_branding_context, get_trial_context from django.conf import settings from .models import UserNotification from .roles import template_role_context def role_context(request): context = template_role_context(getattr(request, 'user', None)) context.update(get_branding_context()) context.update(get_trial_context()) user = getattr(request, 'user', None) if getattr(user, 'is_authenticated', False): notifications = list(UserNotification.objects.filter(user=user).order_by('-created_at')[:8]) context.update( { 'header_notifications': notifications, 'header_unread_notification_count': UserNotification.objects.filter(user=user, read_at__isnull=True).count(), } ) else: context.update({'header_notifications': [], 'header_unread_notification_count': 0}) context.update( { 'static_asset_version': settings.STATIC_ASSET_VERSION, 'session_idle_timeout_seconds': settings.SESSION_IDLE_TIMEOUT_SECONDS, 'session_reauth_timeout_seconds': settings.SENSITIVE_ACTION_REAUTH_SECONDS, 'force_branded_error_pages': settings.FORCE_BRANDED_ERROR_PAGES, } ) return context