views.py 1.65 KB
Newer Older
1
from website.models import Question, Comment, Reply
Jean Michel Rouly's avatar
Jean Michel Rouly committed
2
from website.forms import QuestionForm, CommentForm, ReplyForm, FeedbackForm
Jean Michel Rouly's avatar
Jean Michel Rouly committed
3
4
from django.conf import settings
from django.shortcuts import render_to_response, get_object_or_404
Jean Michel Rouly's avatar
Jean Michel Rouly committed
5
from django.shortcuts import render
6
from django.contrib.auth.decorators import login_required
7
8
9
from django.contrib.auth.models import User
from django.template import RequestContext
from django.http import HttpResponseRedirect
Jean Michel Rouly's avatar
Jean Michel Rouly committed
10
from django.core.mail import EmailMessage
Jean Michel Rouly's avatar
Jean Michel Rouly committed
11

Jean Michel Rouly's avatar
Jean Michel Rouly committed
12
13
import requests

Jean Michel Rouly's avatar
Jean Michel Rouly committed
14
# Create your views here.
Jean Michel Rouly's avatar
Jean Michel Rouly committed
15
16
17
18
19
def instructions(request):
    return render_to_response('instructions.html', {
    },
    )

20
@login_required
Jean Michel Rouly's avatar
Jean Michel Rouly committed
21
def submit_question(request):
22
23
24
25
26
27
28
29
30
31
    if request.method == 'POST':
        form = QuestionForm(request.POST)
        if form.is_valid():
            question = form.save(commit=False)
            question.user = User.objects.get(id=request.user.id)
            question.save()
            return HttpResponseRedirect('/')
    else:
        form = QuestionForm()

Jean Michel Rouly's avatar
Jean Michel Rouly committed
32
    return render_to_response('submit_question.html', {
33
        'form' : form,
Jean Michel Rouly's avatar
Jean Michel Rouly committed
34
    },
35
    RequestContext(request),
Jean Michel Rouly's avatar
Jean Michel Rouly committed
36
    )
37
38
39

@login_required
def index(request):
40
41
42
    if request.method == 'POST':
        pass

43
    return render_to_response('index.html', {
44
        'questions' : Question.objects.all(),
45
46
    },
    )
Jean Michel Rouly's avatar
Jean Michel Rouly committed
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62

@login_required
def feedback(request):
    if request.method == 'POST':
        form = FeedbackForm( request.POST )
        if form.is_valid():
            # email me
            return HttpResponseRedirect('/')
    else:
        form = FeedbackForm()

    return render_to_response('feedback.html', {
        'form' : form,
    },
    RequestContext(request),
    )