Skip to content

Commit

Permalink
Merge branch 'develop' of github.com:jamalex/ka-lite into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
jamalex committed Dec 21, 2012
2 parents 25a40e0 + 1125f2a commit 6abae3b
Show file tree
Hide file tree
Showing 50 changed files with 1,084 additions and 21 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,5 @@ build/
virtualenv/
*.pid
mergetomaster.sh
videos/
videos/
content/*
1 change: 1 addition & 0 deletions LICENSE
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ django
django-chronograph
django-annoying
django_extensions
django-faq
GitPython
django-postmark
pyasn1
Expand Down
3 changes: 3 additions & 0 deletions kalite/main/custom_context_processors.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,7 @@ def custom(request):
"central_server_host": settings.CENTRAL_SERVER_HOST,
"is_central": settings.CENTRAL_SERVER,
"base_template": settings.CENTRAL_SERVER and "base_central.html" or "base_distributed.html",
"CONTENT_ROOT": settings.CONTENT_ROOT,
"CONTENT_URL": settings.CONTENT_URL,
"DATA_PATH": settings.DATA_PATH,
}
3 changes: 2 additions & 1 deletion kalite/main/management/commands/subtitledownload.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def handle(self, *args, **options):
self.stderr.write("Maximum downloads are in progress; aborting.\n")
return

videos = VideoFile.objects.filter(flagged_for_subtitle_download=True, subtitles_downloaded=False, subtitle_download_in_progress=False)
videos = VideoFile.objects.filter(flagged_for_subtitle_download=True, subtitle_download_in_progress=False)
if videos.count() == 0:
self.stdout.write("Nothing to download; aborting.\n")
return
Expand All @@ -46,6 +46,7 @@ def handle(self, *args, **options):
except Exception as e:
self.stderr.write("Error in downloading subtitles: %s\n" % e)
video.subtitle_download_in_progress = False
video.flagged_for_subtitle_download = False
video.save()
force_job("subtitledownload", "Download Subtitles")
return
4 changes: 2 additions & 2 deletions kalite/main/management/commands/videoscan.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ def handle(self, *args, **options):
# delete VideoFile objects that are not marked as in progress, but are neither 0% nor 100% done; they're broken
VideoFile.objects.filter(download_in_progress=False, percent_complete__gt=0, percent_complete__lt=100).delete()

files = glob.glob(settings.VIDEO_PATH + "*.mp4")
subtitle_files = glob.glob(settings.VIDEO_PATH + "*.srt")
files = glob.glob(settings.CONTENT_ROOT + "*.mp4")
subtitle_files = glob.glob(settings.CONTENT_ROOT + "*.srt")
videos_marked_at_all = set([video.youtube_id for video in VideoFile.objects.all()])
videos_marked_as_in_progress = set([video.youtube_id for video in VideoFile.objects.filter(download_in_progress=True)])
videos_marked_as_unstarted = set([video.youtube_id for video in VideoFile.objects.filter(percent_complete=0, download_in_progress=False)])
Expand Down
5 changes: 4 additions & 1 deletion kalite/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@
}

DATA_PATH = PROJECT_PATH + "/static/data/"
VIDEO_PATH = PROJECT_PATH + "/static/videos/"

CONTENT_ROOT = PROJECT_PATH + "/../content/"
CONTENT_URL = "/content/"

# Local time zone for this installation. Choices can be found here:
# http://en.wikipedia.org/wiki/List_of_tz_zones_by_name
Expand Down Expand Up @@ -103,6 +105,7 @@
"securesync",
"config",
"main",
"faq",
)

if DEBUG or CENTRAL_SERVER:
Expand Down
8 changes: 8 additions & 0 deletions kalite/static/css/khan-lite.css
Original file line number Diff line number Diff line change
Expand Up @@ -385,6 +385,14 @@ li .progress-circle {
left: 19px !important;
}

/*FAQ*/
.nav-subheader > span > a#nav_faq.selected:after {
left: 11px !important;
}
.nav-subheader > span > a#nav_faq.selected:before {
left: 10px !important;
}

#nav_addstudent, #nav_addteacher, #nav_admin, #nav_coachreports, #nav_watch, #nav_practice, #nav_signup, #nav_login, #nav_update {
display: none;
}
Expand Down
3 changes: 2 additions & 1 deletion kalite/templates/base_central.html
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
article {
padding: 30px;
}
#nav_signup, #nav_login, #nav_admin {
#nav_signup, #nav_login, #nav_admin, #nav_faq {
display: block;
}
</style>
Expand All @@ -28,6 +28,7 @@
{% block sitewide_navigation %}
<span class="dropdown topic-browser-dropdown">
<a href="/" id="nav_home" class="{% block home_selected %}{% endblock home_selected %}">Home</a>
<a href="/faq/" id="nav_faq" class="{% block faq_selected %}{% endblock faq_selected %}">FAQ</a>
{% if user.is_authenticated %}
{% if user.is_superuser %}
<a href="/admin/" id="nav_admin" class="{% block admin_selected %}{% endblock admin_selected %}">Admin</a>
Expand Down
2 changes: 1 addition & 1 deletion kalite/templates/exercise.html
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ <h2>
<li>
<div class="thumbnail">
<a class="related-video" href="{{ video.path }}" title="{{ video.title }}" target="_blank">
<div class="thumb" style="background-image: url(/static/videos/{{ video.youtube_id }}.jpg); ">
<div class="thumb" style="background-image: url({{ CONTENT_ROOT }}{{ video.youtube_id }}.jpg); ">
<div class="thumbnail_label" style="margin-top: 68px; ">
<div class="thumbnail_desc">
<span class="progress-circle" data-youtube-id="{{ video.youtube_id }}"></span>
Expand Down
14 changes: 14 additions & 0 deletions kalite/templates/faq/base.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{% extends base_template %}
{% block faq_selected %}selected{% endblock faq_selected %}
{% block basecss %}
<style>
.question {
font-weight: bold;
}

#id-topics {
margin-left: 25px;
}
</style>
{% endblock basecss %}

14 changes: 14 additions & 0 deletions kalite/templates/faq/question_detail.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{% extends "faq/base.html" %}

{% block title %}{{ block.super }}: Question - {{ object.text|truncatewords:30}}{% endblock %}


{% block content %}{{ block.super }}

{{ object.text }}

<br/>

{{ object.answer }}

{% endblock %}
18 changes: 18 additions & 0 deletions kalite/templates/faq/submit_question.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{% extends "faq/base.html" %}

{% block title %}{{ block.super }}: Add Question{% endblock %}

{% block content %}{{ block.super }}
<h3>Submit Question</h3>
<p>
Use this form to submit a question (and optionally a corresponding answer)
that you would like to see added to the FAQs on this site.
</p>
<form action="." method="POST">
{% csrf_token %}
<table>
{{ form.as_table }}
</table>
<input type="submit" value="Submit"/>
</form>
{% endblock %}
4 changes: 4 additions & 0 deletions kalite/templates/faq/submit_thanks.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{% extends "faq/base.html" %}

{% block title %}{{ block.super }}: Thanks{% endblock %}
{% block content %}{{ block.super }}<h3>Thanks!</h3>{% endblock %}
15 changes: 15 additions & 0 deletions kalite/templates/faq/topic_detail.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{% extends "faq/base.html" %}

{% block title %}{{ block.super }}: {{ topic }}{% endblock %}

{% block content %}{{ block.super }}
<h3>Frequently Asked Questions: {{ topic }}</h3>
<dl>
{% for question in questions %}
<dt class="question">{{ question.text }}</dt>
<dd class="answer">{{ question.answer }}</dd>
{% endfor %}
</dl>
</br>
<a href="{% url faq_topic_list %}">Back to topic list...</a>
{% endblock %}
15 changes: 15 additions & 0 deletions kalite/templates/faq/topic_list.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{% extends "faq/base.html" %}

{% block title %}{{ block.super }}Frequently Asked Questions: Topics{% endblock %}

{% block content %}{{ block.super }}
<h1>Frequently Asked Questions</h1>
<div id="id-topics">
<h2>Topics</h2>
<ul>
{% for topic in topics %}
<li><a href="{{ topic.get_absolute_url }}">{{ topic }}</a></li>
{% endfor %}
</ul>
</div>
{% endblock %}
8 changes: 4 additions & 4 deletions kalite/templates/video.html
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@
$("#video-thumb").load(function() {

// flashVars.flv = "{{ video.download_urls.mp4 }}";
flashVars.flv = "/static/videos/{{ video.youtube_id }}.mp4";
flashVars.flv = "{{ CONTENT_URL }}{{ video.youtube_id }}.mp4";
// flashVars.startimage = "{{ video.download_urls.png }}";
flashVars.startimage = "/static/videos/{{ video.youtube_id }}.png";
flashVars.srturl = "/static/videos/{{ video.youtube_id }}.srt";
flashVars.startimage = "{{ CONTENT_URL }}{{ video.youtube_id }}.png";
flashVars.srturl = "{{ CONTENT_URL }}{{ video.youtube_id }}.srt";
var width = $("#video-thumb").width();
var height = $("#video-thumb").height();

Expand Down Expand Up @@ -80,7 +80,7 @@ <h2 class="title-header">
<div id="flash-container" style="position: absolute; left: -10000px;">
<div id="flash-content"></div>
</div>
<img id="video-thumb" src="/static/videos/{{ video.youtube_id }}.png" width="100%">
<img id="video-thumb" src="{{ CONTENT_URL }}{{ video.youtube_id }}.png" width="100%">
</div>

{% endblock content %}
12 changes: 8 additions & 4 deletions kalite/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,13 @@
)

urlpatterns += patterns('',
url(r'^static/(?P<path>.*)$', 'django.views.static.serve', {
'document_root': settings.MEDIA_ROOT,
}),
)
url(r'^' + settings.CONTENT_URL[1:] + '(?P<path>.*)$', 'django.views.static.serve', {
'document_root': settings.CONTENT_ROOT,
}),
url(r'^' + settings.MEDIA_URL[1:] + '(?P<path>.*)$', 'django.views.static.serve', {
'document_root': settings.MEDIA_ROOT,
}),
)

if settings.CENTRAL_SERVER:

Expand All @@ -39,6 +42,7 @@
url(r'^addsubscription/$', 'add_subscription', {}, 'add_subscription'),
url(r'^feeds/rss/$', RssSiteNewsFeed(), {}, 'rss_feed'),
url(r'^feeds/atom/$', AtomSiteNewsFeed(), {}, 'atom_feed'),
url(r'^faq/', include('faq.urls')),
)

handler404 = 'main.views.central_404_handler'
Expand Down
12 changes: 9 additions & 3 deletions kalite/utils/subtitles.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
import requests, json, os, sys

download_path = os.path.dirname(os.path.realpath(__file__)) + "/../static/videos/"
PROJECT_PATH = os.path.dirname(os.path.realpath(__file__)) + "/../"

sys.path = [PROJECT_PATH] + sys.path

import settings

download_path = settings.CONTENT_ROOT

headers = {
"X-api-username": "",
Expand All @@ -19,8 +25,8 @@ def get_subtitles(youtube_id, language, format="json"):
# use the base video endpoint to get the Amara video id from the Youtube ID
r = requests.get("%s?video_url=http://www.youtube.com/watch?v=%s" % (base_url, youtube_id), headers=headers)
content = json.loads(r.text)
if content.has_key("objects"):
video_id = json.loads(r.text)["objects"][0]["id"]
if content.get("objects", None):
video_id = content["objects"][0]["id"]
else:
return False

Expand Down
11 changes: 9 additions & 2 deletions kalite/utils/videos.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,18 @@
import sys, os, re, json, urllib, glob

download_path = os.path.dirname(os.path.realpath(__file__)) + "/../static/videos/"
PROJECT_PATH = os.path.dirname(os.path.realpath(__file__)) + "/../"

data_path = os.path.dirname(os.path.realpath(__file__)) + "/../static/data/"
sys.path = [PROJECT_PATH] + sys.path

import settings

download_path = settings.CONTENT_ROOT

data_path = settings.DATA_PATH

download_url = "http://s3.amazonaws.com/KA-youtube-converted/%s/%s"


class DownloadCancelled(Exception):
def __str__(self):
return "Download has been cancelled"
Expand Down
2 changes: 1 addition & 1 deletion kalite/version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
VERSION = "0.8.6"
VERSION = "0.8.7"
27 changes: 27 additions & 0 deletions python-packages/faq/LICENSE.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
Copyright (c) 2011 Kevin Fricovsky and contributors.
All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:

1. Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.

2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.

3. Neither the name of this project nor the names of its contributors may
be used to endorse or promote products derived from this software without
specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Empty file added python-packages/faq/__init__.py
Empty file.
21 changes: 21 additions & 0 deletions python-packages/faq/_testrunner.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
"""
Test support harness to make setup.py test work.
"""

import sys

from django.conf import settings
settings.configure(
DATABASES = {
'default': {'ENGINE': 'django.db.backends.sqlite3', 'NAME': ':memory;'}
},
INSTALLED_APPS = ['django.contrib.auth', 'django.contrib.contenttypes', 'faq'],
ROOT_URLCONF = 'faq.urls',
)

def runtests():
import django.test.utils
runner_class = django.test.utils.get_runner(settings)
test_runner = runner_class(verbosity=1, interactive=True)
failures = test_runner.run_tests(['faq'])
sys.exit(failures)
30 changes: 30 additions & 0 deletions python-packages/faq/admin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
from django.contrib import admin
from models import Question, Topic

class TopicAdmin(admin.ModelAdmin):
prepopulated_fields = {'slug':('name',)}

class QuestionAdmin(admin.ModelAdmin):
list_display = ['text', 'sort_order', 'created_by', 'created_on',
'updated_by', 'updated_on', 'status']
list_editable = ['sort_order', 'status']

def save_model(self, request, obj, form, change):
'''
Update created-by / modified-by fields.
The date fields are upadated at the model layer, but that's not got
access to the user.
'''
# If the object's new update the created_by field.
if not change:
obj.created_by = request.user

# Either way update the updated_by field.
obj.updated_by = request.user

# Let the superclass do the final saving.
return super(QuestionAdmin, self).save_model(request, obj, form, change)

admin.site.register(Question, QuestionAdmin)
admin.site.register(Topic, TopicAdmin)
1 change: 1 addition & 0 deletions python-packages/faq/faq
Loading

0 comments on commit 6abae3b

Please sign in to comment.