def _process_request(self, request): """Adds data necessary for Horizon to function to the request.""" request.horizon = { 'dashboard': None, 'panel': None, 'async_messages': [] } if not hasattr(request, "user") or not request.user.is_authenticated: # proceed no further if the current request is already known # not to be authenticated # it is CRITICAL to perform this check as early as possible # to avoid creating too many sessions return None # Since we know the user is present and authenticated, lets refresh the # session expiry if configured to do so. if getattr(settings, "SESSION_REFRESH", True): timeout = getattr(settings, "SESSION_TIMEOUT", 3600) token_life = request.user.token.expires - datetime.datetime.now( pytz.utc) session_time = min(timeout, int(token_life.total_seconds())) request.session.set_expiry(session_time) if request.is_ajax(): # if the request is Ajax we do not want to proceed, as clients can # 1) create pages with constant polling, which can create race # conditions when a page navigation occurs # 2) might leave a user seemingly left logged in forever # 3) thrashes db backed session engines with tons of changes return None # If we use cookie-based sessions, check that the cookie size does not # reach the max size accepted by common web browsers. if (settings.SESSION_ENGINE == 'django.contrib.sessions.backends.signed_cookies'): max_cookie_size = getattr(settings, 'SESSION_COOKIE_MAX_SIZE', None) session_cookie_name = getattr(settings, 'SESSION_COOKIE_NAME', None) session_key = request.COOKIES.get(session_cookie_name) if max_cookie_size is not None and session_key is not None: cookie_size = sum((len(key) + len(value) for key, value in request.COOKIES.items())) if cookie_size >= max_cookie_size: LOG.error( 'Total Cookie size for user_id: %(user_id)s is ' '%(cookie_size)sB >= %(max_cookie_size)sB. ' 'You need to configure file-based or database-backed ' 'sessions instead of cookie-based sessions: ' 'https://docs.openstack.org/horizon/latest/' 'admin/sessions.html', { 'user_id': request.session.get( 'user_id', 'Unknown'), 'cookie_size': cookie_size, 'max_cookie_size': max_cookie_size, }) tz = utils.get_timezone(request) if tz: timezone.activate(tz)
def get_initial(self): return { 'language': utils.get_language(self.request), 'timezone': utils.get_timezone(self.request), 'pagesize': utils.get_page_size(self.request), 'instance_log_length': utils.get_log_length(self.request) }
def process_request(self, request): """Adds data necessary for Horizon to function to the request.""" request.horizon = {'dashboard': None, 'panel': None, 'async_messages': []} if not hasattr(request, "user") or not request.user.is_authenticated(): # proceed no further if the current request is already known # not to be authenticated # it is CRITICAL to perform this check as early as possible # to avoid creating too many sessions return None if request.is_ajax(): # if the request is Ajax we do not want to proceed, as clients can # 1) create pages with constant polling, which can create race # conditions when a page navigation occurs # 2) might leave a user seemingly left logged in forever # 3) thrashes db backed session engines with tons of changes return None # If we use cookie-based sessions, check that the cookie size does not # reach the max size accepted by common web browsers. if ( settings.SESSION_ENGINE == 'django.contrib.sessions.backends.signed_cookies' ): max_cookie_size = getattr( settings, 'SESSION_COOKIE_MAX_SIZE', None) session_cookie_name = getattr( settings, 'SESSION_COOKIE_NAME', None) session_key = request.COOKIES.get(session_cookie_name) if max_cookie_size is not None and session_key is not None: cookie_size = sum(( len(key) + len(value) for key, value in request.COOKIES.items() )) if cookie_size >= max_cookie_size: LOG.error( 'Total Cookie size for user_id: %(user_id)s is ' '%(cookie_size)sB >= %(max_cookie_size)sB. ' 'You need to configure file-based or database-backed ' 'sessions instead of cookie-based sessions: ' 'http://docs.openstack.org/developer/horizon/topics/' 'deployment.html#session-storage', { 'user_id': request.session.get( 'user_id', 'Unknown'), 'cookie_size': cookie_size, 'max_cookie_size': max_cookie_size, } ) tz = utils.get_timezone(request) if tz: timezone.activate(tz)
def adjust_datestr(request, datestr): tz = pytz.timezone(utils.get_timezone(request)) dt = iso8601.parse_date(datestr).astimezone(tz) return dt.strftime('%Y-%m-%d %H:%M:%S')
def get_initial(self): return { 'language': utils.get_language(self.request), 'timezone': utils.get_timezone(self.request), 'pagesize': utils.get_page_size(self.request), 'instance_log_length': utils.get_log_length(self.request)}