summaryrefslogtreecommitdiff
path: root/website/views.py
blob: 0a8f43b55de2832770bb0430bfa79bbedb9e8bb8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
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)