diff options
Diffstat (limited to 'website')
-rw-r--r-- | website/__init__.py | 0 | ||||
-rw-r--r-- | website/helpers.py | 26 | ||||
-rw-r--r-- | website/models.py | 54 | ||||
-rw-r--r-- | website/templatetags/__init__.py | 0 | ||||
-rw-r--r-- | website/templatetags/count_tags.py | 11 | ||||
-rw-r--r-- | website/templatetags/recent_posts.html | 0 | ||||
-rw-r--r-- | website/templatetags/sidebar_tags.py | 12 | ||||
-rw-r--r-- | website/tests.py | 16 | ||||
-rw-r--r-- | website/urls.py | 9 | ||||
-rw-r--r-- | website/views.py | 84 |
10 files changed, 212 insertions, 0 deletions
diff --git a/website/__init__.py b/website/__init__.py new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/website/__init__.py diff --git a/website/helpers.py b/website/helpers.py new file mode 100644 index 0000000..dd37152 --- /dev/null +++ b/website/helpers.py @@ -0,0 +1,26 @@ +def get_video_info(path): + """Uses ffmpeg to determine information about a video. This has not been broadly + tested and your milage may vary""" + + from decimal import Decimal + import subprocess + import re + + process = subprocess.Popen(['/usr/bin/ffmpeg', '-i', path], stdout=subprocess.PIPE, stderr=subprocess.STDOUT) + stdout, stderr = process.communicate() + duration_m = re.search(r"Duration:\s{1}(?P<hours>\d+?):(?P<minutes>\d+?):(?P<seconds>\d+\.\d+?)", stdout, re.DOTALL).groupdict() + info_m = re.search(r": Video: (?P<codec>.*?), (?P<profile>.*?), (?P<width>.*?)x(?P<height>.*?), ", stdout, re.DOTALL).groupdict() + + hours = Decimal(duration_m['hours']) + minutes = Decimal(duration_m['minutes']) + seconds = Decimal(duration_m['seconds']) + + total = 0 + total += 60 * 60 * hours + total += 60 * minutes + total += seconds + + info_m['duration'] = total + info_m['width'] = int(info_m['width']) + info_m['height'] = int(info_m['height']) + return info_m diff --git a/website/models.py b/website/models.py new file mode 100644 index 0000000..9570965 --- /dev/null +++ b/website/models.py @@ -0,0 +1,54 @@ +from django.db import models +from django.contrib.auth.models import User + +class Post(models.Model): + user = models.ForeignKey(User) + category = models.CharField(max_length=200) + tutorial = models.CharField(max_length=200) + title = models.CharField(max_length=200) + body = models.TextField() + date_created = models.DateTimeField(auto_now_add=True) + date_modified = models.DateTimeField(auto_now=True) + +class Reply(models.Model): + user = models.ForeignKey(User) + post = models.ForeignKey(Post) + title = models.CharField(max_length=200) + body = models.TextField() + date_created = models.DateTimeField(auto_now_add=True) + date_modified = models.DateTimeField(auto_now=True) + +# CDEEP database created using inspectdb arg of manage.py +class TutorialDetails(models.Model): + id = models.IntegerField(primary_key=True) + foss_category = models.CharField(max_length=255L) + tutorial_name = models.CharField(max_length=600L) + tutorial_level = models.CharField(max_length=400L) + order_code = models.IntegerField() + class Meta: + db_table = 'tutorial_details' + +class TutorialResources(models.Model): + id = models.IntegerField(primary_key=True) + tutorial_detail_id = models.IntegerField() + uid = models.IntegerField() + language = models.CharField(max_length=50L) + upload_time = models.DateTimeField() + reviewer = models.CharField(max_length=400L) + tutorial_content_id = models.IntegerField() + tutorial_outline = models.TextField() + tutorial_outline_uid = models.IntegerField() + tutorial_outline_status = models.IntegerField() + tutorial_script = models.TextField() + tutorial_script_uid = models.IntegerField() + tutorial_script_status = models.IntegerField() + tutorial_script_timed = models.TextField() + tutorial_video = models.TextField() + tutorial_video_uid = models.IntegerField() + tutorial_video_status = models.IntegerField() + tutorial_status = models.CharField(max_length=50L) + cvideo_version = models.IntegerField() + hit_count = models.BigIntegerField() + request_exception = models.TextField() + class Meta: + db_table = 'tutorial_resources' diff --git a/website/templatetags/__init__.py b/website/templatetags/__init__.py new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/website/templatetags/__init__.py diff --git a/website/templatetags/count_tags.py b/website/templatetags/count_tags.py new file mode 100644 index 0000000..e4233f1 --- /dev/null +++ b/website/templatetags/count_tags.py @@ -0,0 +1,11 @@ +from django import template + +from website.models import Post, Reply + +register = template.Library() + +def category_post_count(category): + category_post_count = Post.objects.filter(category=category).count() + return category_post_count +register.simple_tag(category_post_count) + diff --git a/website/templatetags/recent_posts.html b/website/templatetags/recent_posts.html new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/website/templatetags/recent_posts.html diff --git a/website/templatetags/sidebar_tags.py b/website/templatetags/sidebar_tags.py new file mode 100644 index 0000000..a7e5cc7 --- /dev/null +++ b/website/templatetags/sidebar_tags.py @@ -0,0 +1,12 @@ +from django import template + +from website.models import Post, Reply + +register = template.Library() + +def recent_posts(): + recent_posts = Post.objects.all().order_by('-id')[:5] + return {'recent_posts': recent_posts} + +register.inclusion_tag('website/templates/recent_posts.html')(recent_posts) + diff --git a/website/tests.py b/website/tests.py new file mode 100644 index 0000000..501deb7 --- /dev/null +++ b/website/tests.py @@ -0,0 +1,16 @@ +""" +This file demonstrates writing tests using the unittest module. These will pass +when you run "manage.py test". + +Replace this with more appropriate tests for your application. +""" + +from django.test import TestCase + + +class SimpleTest(TestCase): + def test_basic_addition(self): + """ + Tests that 1 + 1 always equals 2. + """ + self.assertEqual(1 + 1, 2) diff --git a/website/urls.py b/website/urls.py new file mode 100644 index 0000000..29c25ea --- /dev/null +++ b/website/urls.py @@ -0,0 +1,9 @@ +from django.conf.urls import patterns, include, url + +urlpatterns = patterns('', + url(r'^$', 'website.views.home', name='home'), + url(r'^category/(?P<category>.+)/$', 'website.views.fetch_tutorials', name='fetch_tutorials'), + url(r'^tutorial/(?P<category>.+)/(?P<tutorial>.+)/$', 'website.views.fetch_posts', name='fetch_posts'), + url(r'^post/(?P<post_id>\d+)$', 'website.views.get_post', name='get_post'), + url(r'^new-post/$', 'website.views.new_post', name='new_post'), +) diff --git a/website/views.py b/website/views.py new file mode 100644 index 0000000..0a8f43b --- /dev/null +++ b/website/views.py @@ -0,0 +1,84 @@ +import math + +from django.http import HttpResponse, HttpResponseRedirect +from django.shortcuts import render_to_response, get_object_or_404 + +from website.models import Post, Reply, TutorialDetails, TutorialResources +from website.helpers import get_video_info + +categories = [ + 'Advanced-C++', 'BASH', 'Blender', + 'C-and-C++', 'CellDesigner', 'Digital-Divide', + 'Drupal', 'Firefox', 'GChemPaint', 'Geogebra', + 'GeoGebra-for-Engineering-drawing', 'GIMP', 'GNS3', + 'GSchem', 'Java', 'Java-Business-Application', + 'KiCad', 'KTouch', 'KTurtle', 'LaTeX', + 'LibreOffice-Suite-Base', 'LibreOffice-Suite-Calc', + 'LibreOffice-Suite-Draw', 'LibreOffice-Suite-Impress', + 'LibreOffice-Suite-Math', 'LibreOffice-Suite-Writer', + 'Linux', 'Netbeans', 'Ngspice', 'OpenFOAM', 'Orca', + 'PERL', 'PHP-and-MySQL', 'Python', 'Python-Old-Version', + 'QCad', 'R', 'Ruby', 'Scilab', 'Selenium', + 'Single-Board-Heater-System', 'Spoken-Tutorial-Technology', + 'Step', 'Thunderbird', 'Tux-Typing', 'What-is-Spoken-Tutorial', 'Xfig' +] + +def home(request): + context = { + 'categories': categories + } + return render_to_response('website/templates/index.html', context) + +def fetch_tutorials(request, category=None): + tutorials = TutorialDetails.objects.using('spoken').filter(foss_category=category) + context = { + 'category': category, + 'tutorials': tutorials + } + return render_to_response('website/templates/fetch_tutorials.html', context) + +def fetch_posts(request, category=None, tutorial=None): + posts = Post.objects.filter(category=category).filter(tutorial=tutorial) + context = { + 'category': category, + 'tutorial': tutorial, + 'posts': posts + } + return render_to_response('website/templates/fetch_posts.html', context) + + +def get_post(request, post_id=None): + post = get_object_or_404(Post, id=post_id) + replies = post.reply_set.all() + context = { + 'post': post, + 'replies': replies + } + return render_to_response('website/templates/get_post.html', context) + +def new_post(request): + video_info = get_video_info('/home/cheese/test-video.ogv') + duration = math.ceil(video_info['duration']/60) #assuming the video is less than an hour + return HttpResponse(duration) + + + + + + + + + + + + + + + + + + + + + + |