Commit 8ad1e7fb by Victor Shnayder

Add framework for a site status banner.

- still needs style
- will cache for 10 seconds
parent fbba883c
"""
A tiny app that checks for a status message.
"""
from django.conf import settings
import logging
import os
import sys
from util.cache import cache
log = logging.getLogger(__name__)
def get_site_status_msg():
"""
Look for a file settings.STATUS_MESSAGE_PATH. If found, return the
contents. Otherwise, return None. Caches result for 10 seconds, per-machine.
If something goes wrong, returns None. ("is there a status msg?" logic is
not allowed to break the entire site).
"""
cache_time = 10
try:
key = ','.join([settings.HOSTNAME, settings.STATUS_MESSAGE_PATH])
content = cache.get(key)
if content == '':
# cached that there isn't a status message
return None
if content is None:
# nothing in the cache, so check the filesystem
if os.path.isfile(settings.STATUS_MESSAGE_PATH):
with open(settings.STATUS_MESSAGE_PATH) as f:
content = f.read()
else:
# remember that there isn't anything there
cache.set(key, '', cache_time)
content = None
return content
except:
log.debug("Error while getting a status message: {0}".format(sys.exc_info()))
return None
......@@ -25,6 +25,7 @@ import glob2
import errno
import hashlib
from collections import defaultdict
import socket
import djcelery
from path import path
......@@ -95,6 +96,13 @@ GENERATE_PROFILE_SCORES = False
# Used with XQueue
XQUEUE_WAITTIME_BETWEEN_REQUESTS = 5 # seconds
# Used for per-maching caching
try:
HOSTNAME = socket.gethostname()
except:
HOSTNAME = 'localhost'
############################# SET PATH INFORMATION #############################
PROJECT_ROOT = path(__file__).abspath().dirname().dirname() # /mitx/lms
REPO_ROOT = PROJECT_ROOT.dirname()
......@@ -103,7 +111,6 @@ ENV_ROOT = REPO_ROOT.dirname() # virtualenv dir /mitx is in
ASKBOT_ROOT = REPO_ROOT / "askbot"
COURSES_ROOT = ENV_ROOT / "data"
# FIXME: To support multiple courses, we should walk the courses dir at startup
DATA_DIR = COURSES_ROOT
sys.path.append(REPO_ROOT)
......@@ -127,8 +134,11 @@ node_paths = [COMMON_ROOT / "static/js/vendor",
NODE_PATH = ':'.join(node_paths)
# Where to look for a status message
STATUS_MESSAGE_PATH = ENV_ROOT / "status_message.html"
############################ OpenID Provider ##################################
OPENID_PROVIDER_TRUSTED_ROOTS = ['cs50.net', '*.cs50.net']
OPENID_PROVIDER_TRUSTED_ROOTS = ['cs50.net', '*.cs50.net']
################################## MITXWEB #####################################
# This is where we stick our compiled template files. Most of the app uses Mako
......@@ -158,7 +168,7 @@ TEMPLATE_CONTEXT_PROCESSORS = (
'askbot.user_messages.context_processors.user_messages',#must be before auth
'django.contrib.auth.context_processors.auth', #this is required for admin
'django.core.context_processors.csrf', #necessary for csrf protection
# Added for django-wiki
'django.core.context_processors.media',
'django.core.context_processors.tz',
......@@ -355,7 +365,7 @@ WIKI_CAN_ASSIGN = lambda article, user: user.is_staff or user.is_superuser
WIKI_USE_BOOTSTRAP_SELECT_WIDGET = False
WIKI_LINK_LIVE_LOOKUPS = False
WIKI_LINK_DEFAULT_LEVEL = 2
WIKI_LINK_DEFAULT_LEVEL = 2
################################# Jasmine ###################################
JASMINE_TEST_DIRECTORY = PROJECT_ROOT + '/static/coffee'
......@@ -372,10 +382,10 @@ STATICFILES_FINDERS = (
TEMPLATE_LOADERS = (
'mitxmako.makoloader.MakoFilesystemLoader',
'mitxmako.makoloader.MakoAppDirectoriesLoader',
# 'django.template.loaders.filesystem.Loader',
# 'django.template.loaders.app_directories.Loader',
#'askbot.skins.loaders.filesystem_load_template_source',
# 'django.template.loaders.eggs.Loader',
)
......@@ -393,7 +403,7 @@ MIDDLEWARE_CLASSES = (
'django.contrib.messages.middleware.MessageMiddleware',
'track.middleware.TrackMiddleware',
'mitxmako.middleware.MakoMiddleware',
'course_wiki.course_nav.Middleware',
'askbot.middleware.anon_user.ConnectToSessionMessagesMiddleware',
......@@ -624,7 +634,7 @@ INSTALLED_APPS = (
'certificates',
'instructor',
'psychometrics',
#For the wiki
'wiki', # The new django-wiki from benjaoming
'django_notify',
......
......@@ -8,19 +8,27 @@ from django.core.urlresolvers import reverse
# App that handles subdomain specific branding
import branding
# app that handles site status messages
from status.status import get_site_status_msg
site_status_msg = get_site_status_msg()
%>
%if course:
% if site_status_msg:
<div class="site-status">${site_status_msg}</div>
% endif
% if course:
<header class="global slim" aria-label="Global Navigation">
%else:
% else:
<header class="global" aria-label="Global Navigation">
%endif
% endif
<nav>
<h1 class="logo"><a href="${reverse('root')}"><img src="${static.url(branding.get_logo_url(request.META.get('HTTP_HOST')))}"/></a></h1>
%if course:
% if course:
<h2><span class="provider">${course.org}:</span> ${course.number} ${course.title}</h2>
%endif
% endif
<ol class="left find-courses-button">
<li class="primary">
......@@ -28,7 +36,7 @@ import branding
</li>
</ol>
%if user.is_authenticated():
% if user.is_authenticated():
<ol class="user">
<li class="primary">
<a href="${reverse('dashboard')}" class="user-link">
......@@ -46,7 +54,7 @@ import branding
</li>
</ol>
%else:
% else:
<ol class="guest">
<li class="secondary">
<a href="${reverse('about_edx')}">About</a>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment