Skip to content

Commit

Permalink
Merge pull request #4814 from benjaoming/channel-contenxt-data
Browse files Browse the repository at this point in the history
Channel context data refactored
  • Loading branch information
rtibbles committed Feb 8, 2016
2 parents c9ee9d5 + b42d920 commit 170de21
Show file tree
Hide file tree
Showing 9 changed files with 26 additions and 38 deletions.
Binary file removed data/khan/images/learning-image.png
Binary file not shown.
19 changes: 9 additions & 10 deletions kalite/contentload/management/commands/unpack_assessment_zip.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

from django.conf import settings as django_settings
from django.core.management.base import BaseCommand, CommandError
from django.core.management import call_command

logging = django_settings.LOG

Expand Down Expand Up @@ -39,17 +40,17 @@ def handle(self, *args, **kwargs):
return

if is_valid_url(ziplocation): # url; download the zip
print "Downloading assessment item data from a remote server. Please be patient; this file is big, so this may take some time..."
logging.info("Downloading assessment item data from a remote server. Please be patient; this file is big, so this may take some time...")
# this way we can download stuff larger than the device's RAM
r = requests.get(ziplocation, prefetch=False)
content_length = r.headers.get("Content-Length")
print "Downloaded size: ", str(int(content_length) // 1024 // 1024) + " MB" if content_length else "Unknown"
logging.info("Downloaded size: ", str(int(content_length) // 1024 // 1024) + " MB" if content_length else "Unknown")
sys.stdout.write("Downloading file...")
sys.stdout.flush()
f = tempfile.TemporaryFile("r+")
r.raise_for_status()
for cnt, chunk in enumerate(r.iter_content(chunk_size=1024)):
if chunk: # filter out keep-alive new chunks
if chunk: # filter out keep-alive new chunks
f.write(chunk)
if cnt % 1000 == 0:
sys.stdout.write(".")
Expand All @@ -60,10 +61,14 @@ def handle(self, *args, **kwargs):
else: # file; just open it normally
f = open(ziplocation, "rb")

print "Unpacking..."
logging.info("Unpacking...")
zf = zipfile.ZipFile(f, "r")
unpack_zipfile_to_content_folder(zf)

logging.info("Scanning items and updating content db...")
call_command("annotate_content_items")
logging.info("Done, assessment items installed and everything updated. Refresh your browser!")


def should_upgrade_assessment_items():
# if assessmentitems.version doesn't exist, then we assume
Expand Down Expand Up @@ -101,12 +106,6 @@ def unpack_zipfile_to_content_folder(zf):
os.path.join(folder, 'assessmentitems.version'),
settings.KHAN_ASSESSMENT_ITEM_VERSION_PATH
)
# JSON file is apparrently not required (not in the test at least)
if os.path.isfile(os.path.join(folder, 'assessmentitems.json')):
shutil.move(
os.path.join(folder, 'assessmentitems.json'),
settings.KHAN_ASSESSMENT_ITEM_JSON_PATH
)


def is_valid_url(url):
Expand Down
22 changes: 1 addition & 21 deletions kalite/distributed/custom_context_processors.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,40 +5,20 @@
* Metadata about the central server (for syncing, getting content, language packs, etc)
* App settings, including version / build ID
"""
import json
import os

from django.conf import settings
from django.utils.translation import ugettext as _

from kalite import version
from kalite.topic_tools import settings as topic_tools_settings

channel_data = {}

def custom(request):
global channel_data

channel_data_trans = {}

# MUST: Translation must happen inside this function because it will NOT work if it is outside
# because that part of the code only runs once when this module is loaded/imported.
if not channel_data:
# Parsing a whole JSON file just to load the settings is not nice
try:
channel_data = json.load(open(os.path.join(topic_tools_settings.CHANNEL_DATA_PATH, "channel_data.json"), 'r'))
except IOError:
channel_data = {}

for key, value in channel_data.items():
channel_data_trans[key] = _(value)

return {
"central_server_host": settings.CENTRAL_SERVER_HOST,
"central_server_domain": settings.CENTRAL_SERVER_DOMAIN,
"securesync_protocol": settings.SECURESYNC_PROTOCOL,
"base_template": "distributed/base.html",
"channel_data": channel_data_trans,
"channel_data": settings.KALITE_CHANNEL_CONTEXT_DATA,
"channel": topic_tools_settings.CHANNEL,
"is_central": False,
"settings": settings,
Expand Down
File renamed without changes
File renamed without changes
2 changes: 1 addition & 1 deletion kalite/distributed/templates/distributed/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@
</button>
<div class="navbar-brand">
<a href="{% url 'homepage' %}" title="{{ channel_data.channel_name }} {% trans 'Home' %}">
<img src="/data/{{ channel }}/images/horizontal-logo-small.png" alt="{{ channel_data.channel_name }} {% trans 'logo' %}">
<img src="{{ channel_data.header_logo }}" alt="{{ channel_data.channel_name }} {% trans 'logo' %}">
</a>
<div class="pull-right visible-xs sitepoint" id="points-xs"></div>
</div>
Expand Down
2 changes: 1 addition & 1 deletion kalite/distributed/templates/distributed/homepage.html
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ <h2 class="main-headline hidden-xs">{{ channel_data.head_line }}</h2>
<div class="col-sm-4 col-sm-push-4 col-xs-10 col-xs-push-1 vertical-shadow suggested-action">
<a href="{% url 'learn' %}">
<h2 class="h3 suggested-action-title">{% trans "Learn!" %}</h2>
<img class="img-responsive" id="suggested-action-image-link-homepage" src="/data/{{ channel }}/images/logo_10_enlarged_2.png" alt="{% trans 'Learn with Khan Academy videos and exercises!' %}">
<img class="img-responsive" id="suggested-action-image-link-homepage" src="{{ channel_data.frontpage_splash }}" alt="{% trans 'Learn with Khan Academy videos and exercises!' %}">
</a>
</div>
</div>
Expand Down
14 changes: 14 additions & 0 deletions kalite/settings/base.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# -*- coding: utf-8 -*-
import time
from kalite import version
import logging
Expand All @@ -8,6 +9,7 @@
from kalite import ROOT_DATA_PATH
from kalite.shared.warnings import RemovedInKALite_v016_Warning

from django.utils.translation import ugettext_lazy

# Load local settings first... loading it again later to have the possibility
# to overwrite default app settings.. very strange method, will be refactored
Expand Down Expand Up @@ -247,6 +249,18 @@
STATIC_URL = getattr(local_settings, "STATIC_URL", "/static/")


# Context data included by ka lite's context processor
KALITE_CHANNEL_CONTEXT_DATA = {
"channel_name": ugettext_lazy(u"KA Lite"),
"head_line": ugettext_lazy(u"A free world-class education for anyone anywhere."),
"tag_line": ugettext_lazy(u"KA Lite is a light-weight web server for viewing and interacting with core Khan Academy content (videos and exercises) without needing an Internet connection."),
"channel_license": ugettext_lazy(u"CC-BY-NC-SA"),
"footer_text": ugettext_lazy(u"Videos © 2015 Khan Academy (Creative Commons) // Exercises © 2015 Khan Academy"),
"header_logo": os.path.join(STATIC_URL, 'images', 'horizontal-logo-small.png'),
"frontpage_splash": os.path.join(STATIC_URL, 'images', 'logo_10_enlarged_2.png'),
}


DEFAULT_DATABASE_PATH = getattr(local_settings, "DATABASE_PATH", DEFAULT_DATABASE_PATH)

DATABASES = getattr(local_settings, "DATABASES", {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
import os

from django.core.management import call_command
from optparse import make_option

from django.conf import settings as django_settings
Expand All @@ -12,8 +9,6 @@

from django.core.management.base import BaseCommand

from django.utils.translation import gettext as _


class Command(BaseCommand):

Expand Down

0 comments on commit 170de21

Please sign in to comment.