views.py 1.12 KB
Newer Older
1
2
from website.models import Question, Comment, Reply
from website.forms import QuestionForm
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

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

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

19
@login_required
Jean Michel Rouly's avatar
Jean Michel Rouly committed
20
def submit_question(request):
21
22
23
24
25
26
27
28
29
30
    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
31
    return render_to_response('submit_question.html', {
32
        'form' : form,
Jean Michel Rouly's avatar
Jean Michel Rouly committed
33
    },
34
    RequestContext(request),
Jean Michel Rouly's avatar
Jean Michel Rouly committed
35
    )
36
37
38
39
40
41

@login_required
def index(request):
    return render_to_response('index.html', {
    },
    )