Commit 48c86f0d authored by Jean Michel Rouly's avatar Jean Michel Rouly
Browse files

Process comment form.

parent 4e32cd40
......@@ -15,6 +15,18 @@ HNRS 110 • Question Discussion
</div>
</div>
{% if comment_form.errors %}
<div class="row">
<div class="col-lg-10 col-lg-offset-1">
<div class="alert alert-dismissable alert-danger">
<button type="button" class="close" data-dismiss="alert">&times;</button>
<strong>Oh snap!</strong> There was an error posting your comment.
Please try again.
</div>
</div>
</div>
{% endif %}
<div class="row">
<div class="col-lg-10 col-lg-offset-1">
<div class="panel panel-primary">
......@@ -38,9 +50,7 @@ HNRS 110 &bull; Question Discussion
Make Comment
</a>
<div class="collapse" id="make-comment">
Form
</div>
{% include 'comment_form.html' %}
</div>
</div>
......
......@@ -8,7 +8,9 @@ from django.contrib.auth.models import User
from django.template import RequestContext
from django.http import HttpResponseRedirect
from django.core.mail import EmailMessage
from django.utils import timezone
import os
import requests
# Create your views here.
......@@ -50,7 +52,12 @@ def feedback(request):
if request.method == 'POST':
form = FeedbackForm( request.POST )
if form.is_valid():
# email me
f = open(os.path.join(settings.MEDIA_ROOT, 'feedback.txt'), 'a')
data = form.cleaned_data
f.write( str(timezone.now()) )
f.write( str('\n') )
f.write( data['text'] )
f.write( str('\n\n\n') )
return HttpResponseRedirect('/')
else:
form = FeedbackForm()
......@@ -62,8 +69,20 @@ def feedback(request):
)
def view_question(request, slug):
if request.method == 'POST':
comment_form = CommentForm(request.POST)
if comment_form.is_valid():
comment = comment_form.save(commit=False)
comment.user = User.objects.get(id=request.user.id)
comment.parent = Question.objects.get(id=slug)
comment.save()
return HttpResponseRedirect('')
else:
comment_form = CommentForm()
return render_to_response('question.html', {
'question' : get_object_or_404(Question, pk=slug),
'comment_form' : comment_form,
},
RequestContext(request),
)
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment