summaryrefslogtreecommitdiff
path: root/website
diff options
context:
space:
mode:
authorashwinishinde2015-03-24 16:01:35 +0530
committerashwinishinde2015-03-24 16:01:35 +0530
commitaf6409ed6b3c24bc865a3bc1b1ac5c73898d5485 (patch)
treeb6ce4b498e7ff43c2ad013f26f5ebad2037fbc9d /website
parent54bd70b5d4338f9d2737c4403352ce45c111216e (diff)
downloadFOSSEE-Forum-af6409ed6b3c24bc865a3bc1b1ac5c73898d5485.tar.gz
FOSSEE-Forum-af6409ed6b3c24bc865a3bc1b1ac5c73898d5485.tar.bz2
FOSSEE-Forum-af6409ed6b3c24bc865a3bc1b1ac5c73898d5485.zip
Subject:Resolved View all questions and validate ask new answer
Description: 1) display view all questions. 2) validate all the fields in ask new answer. 3) validate submit answer.
Diffstat (limited to 'website')
-rw-r--r--website/forms.py30
-rw-r--r--website/urls.py2
-rw-r--r--website/views.py45
3 files changed, 45 insertions, 32 deletions
diff --git a/website/forms.py b/website/forms.py
index a55aec1..558d058 100644
--- a/website/forms.py
+++ b/website/forms.py
@@ -7,16 +7,18 @@ class NewQuestionForm(forms.ModelForm):
category = forms.ModelChoiceField(widget = forms.Select(attrs = {}),
queryset = FossCategory.objects.order_by('name'),
empty_label = "Select a category",
- error_messages = {'required':'Categoty field required.'})
+ required = True,
+ error_messages = {'required':'Select a category.'})
- '''tutorial = forms.ModelChoiceField(widget = forms.Select(attrs = {}), q
- ueryset = Issue.objects.order_by('name'),
- empty_label = "Select a Issue",
- error_messages = {'required':'Issue field required.'})'''
- '''class Meta:
- model = Question
- fields = ['category', 'tutorial', 'title', 'body']'''
-
+ title = forms.CharField(widget=forms.TextInput(),
+ required = True,
+ error_messages = {'required':'Title field required.'})
+
+ body = forms.CharField(widget=forms.Textarea(),
+ required = True,
+ error_messages = {'required':'question field required.'}
+ )
+
class Meta:
model = Question
fields = ['category', 'title', 'body']
@@ -25,12 +27,16 @@ class NewQuestionForm(forms.ModelForm):
category = kwargs.pop('category', None)
super(NewQuestionForm, self).__init__(*args, **kwargs)
-class AnswerQuesitionForm(forms.Form):
+class AnswerQuestionForm(forms.ModelForm):
question = forms.IntegerField(widget=forms.HiddenInput())
body = forms.CharField(widget=forms.Textarea(),
- required = True
+ required = True,
+ error_messages = {'required':'Answer field required.'}
)
+ class Meta:
+ model = Question
+ fields = ['question', 'body']
class AnswerCommentForm(forms.Form):
- body = forms.CharField(widget=forms.Textarea(),required = True)
+ body = forms.CharField(widget=forms.Textarea(),required = True,)
diff --git a/website/urls.py b/website/urls.py
index 33ad485..1c7d75e 100644
--- a/website/urls.py
+++ b/website/urls.py
@@ -8,7 +8,7 @@ urlpatterns = patterns('',
url(r'^question-answer/(?P<qid>\d+)/$', 'website.views.question_answer', name='question_answer'),
url(r'^answer-comment/$', 'website.views.answer_comment', name='answer_comment'),
url(r'^filter/(?P<category>[^/]+)/$', 'website.views.filter', name='filter'),
- url(r'^filter/(?P<category>[^/]+)/(?P<tutorial>[^/]+)/$', 'website.views.filter', name='filter'),
+ url(r'^filter/(?P<category>[^/]+)/$', 'website.views.filter', name='filter'),
#url(r'^filter/(?P<category>[^/]+)/(?P<tutorial>[^/]+)/(?P<minute_range>[^/]+)/$', 'website.views.filter', name='filter'),
#url(r'^filter/(?P<category>[^/]+)/(?P<tutorial>[^/]+)/(?P<minute_range>[^/]+)/(?P<second_range>[^/]+)/$', 'website.views.filter', name='filter'),
url(r'^new-question/$', 'website.views.new_question', name='new_question'),
diff --git a/website/views.py b/website/views.py
index de3e370..64c0505 100644
--- a/website/views.py
+++ b/website/views.py
@@ -1,8 +1,9 @@
import re
from django.http import HttpResponse, HttpResponseRedirect
-from django.shortcuts import render, get_object_or_404
+from django.shortcuts import render, get_object_or_404,render_to_response
from django.core.context_processors import csrf
+from django.template import RequestContext
from django.views.decorators.csrf import csrf_exempt
from django.contrib.auth.decorators import login_required
from django.db.models import Q, Max
@@ -14,7 +15,7 @@ User = get_user_model()
from website.models import Question, Answer, Notification, AnswerComment, FossCategory
from spoken_auth.models import TutorialDetails, TutorialResources
-from website.forms import NewQuestionForm, AnswerQuesitionForm,AnswerCommentForm
+from website.forms import NewQuestionForm, AnswerQuestionForm,AnswerCommentForm
from website.helpers import get_video_info, prettify
from django.db.models import Count
@@ -52,12 +53,13 @@ def get_question(request, question_id=None, pretty_url=None):
if pretty_url != pretty_title:
return HttpResponseRedirect('/question/'+ question_id + '/' + pretty_title)
answers = question.answer_set.all()
- form = AnswerQuesitionForm()
+ form = AnswerQuestionForm()
context = {
'question': question,
'answers': answers,
'form': form
}
+
context.update(csrf(request))
# updating views count
question.views += 1
@@ -66,18 +68,20 @@ def get_question(request, question_id=None, pretty_url=None):
@login_required
def question_answer(request,qid):
- print qid
- context = {}
+
+ dict_context = {}
+
if request.method == 'POST':
- form = AnswerQuesitionForm(request.POST)
+ form = AnswerQuestionForm(request.POST)
+ question = get_object_or_404(Question, id=qid)
+ answers = question.answer_set.all()
+ answer = Answer()
+ answer.uid = request.user.id
if form.is_valid():
cleaned_data = form.cleaned_data
qid = cleaned_data['question']
body = cleaned_data['body']
- question = get_object_or_404(Question, id=qid)
- answer = Answer()
- answer.uid = request.user.id
answer.question = question
answer.body = body.encode('unicode_escape')
answer.save()
@@ -97,7 +101,7 @@ def question_answer(request,qid):
Your question titled <b>"{1}"</b> has been answered.<br>
Link: {2}<br><br>
Regards,<br>
- Spoken Tutorial Forums
+ Fossee Forums
""".format(
user.username,
question.title,
@@ -113,15 +117,17 @@ def question_answer(request,qid):
email.attach_alternative(message, "text/html")
email.send(fail_silently=True)
# End of email send
- return HttpResponseRedirect('/question/'+ str(qid) + "#answer" + str(answer.id))
- else:
- form = AnswerQuesitionForm()
- context = {
- 'form': form
- }
- #print form
+ return HttpResponseRedirect('/question/'+ str(qid) + "#answer" + str(answer.id))
+ else:
+ dict_context = {
+ 'question':question,
+ 'answers': answers,
+ 'form': form
+ }
+
+ return render(request, 'website/templates/get-question.html', dict_context)
- return HttpResponseRedirect('/question/'+ str(qid))
+ return HttpResponseRedirect('/')
@@ -235,7 +241,7 @@ def new_question(request):
question = Question()
question.user = request.user
question.category = cleaned_data['category']
- #question.tutorial = cleaned_data['tutorial']
+
question.title = cleaned_data['title']
question.body = cleaned_data['body'].encode('unicode_escape')
question.views= 1
@@ -272,6 +278,7 @@ def new_question(request):
context['category'] = category
context['form'] = form
+ print form.errors
context.update(csrf(request))
return render(request, 'website/templates/new-question.html', context)