summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorashwinishinde2015-03-24 16:01:35 +0530
committerashwinishinde2015-03-24 16:01:35 +0530
commitaf6409ed6b3c24bc865a3bc1b1ac5c73898d5485 (patch)
treeb6ce4b498e7ff43c2ad013f26f5ebad2037fbc9d
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.
-rw-r--r--static/website/css/main.css1
-rw-r--r--static/website/templates/get-question.html18
-rw-r--r--static/website/templates/new-question.html10
-rw-r--r--static/website/templates/questions.html44
-rw-r--r--website/forms.py30
-rw-r--r--website/urls.py2
-rw-r--r--website/views.py45
7 files changed, 69 insertions, 81 deletions
diff --git a/static/website/css/main.css b/static/website/css/main.css
index fc96f5b..171503d 100644
--- a/static/website/css/main.css
+++ b/static/website/css/main.css
@@ -282,6 +282,7 @@ table .question a{
#footer-inner a{
color: #ffffff;
}
+
#footer-inner .cc{
font-size: 13px;
text-align: center;
diff --git a/static/website/templates/get-question.html b/static/website/templates/get-question.html
index 3a0e4eb..f90681c 100644
--- a/static/website/templates/get-question.html
+++ b/static/website/templates/get-question.html
@@ -168,14 +168,17 @@
{% with WIDGET_ERROR_CLASS='field_error' %}
<div class="row">
<div class="col-lg-12 col-md-12 col-sm-12 col-xs-12">
+ {{ form.body.errors }}
<div class="form-group">
{% render_field form.question value=question.id %}
- <label for="id_body">Answer</label>
- {% render_field form.body class+='form-control body' %}
+ <label for="id_body"><h4><u>Your Answer:</u></h4></label>
+ {% render_field form.body class+='form-control' %}
</div>
- {{ form.body.errors }}
+
</div>
</div>
+
+
{% endwith %}
<input class="btn btn-sm btn-info" type="submit" value="Submit Answer">
</form>
@@ -197,14 +200,7 @@
<h5>The Current question is under:</h5>
{{ question.category }} <!--
- --&gt; {{ question.tutorial }}
- {% if question.minute_range != 'None' %}
- --&gt; {{ question.minute_range }}
- {% endif %}
- {% if question.second_range != 'None' %}
- --&gt; {{ question.second_range}}
- {% endif %}-->
-
+
<h5>Move the question to:</h5>
<div class="row">
<div class="col-lg-4 col-md-4 col-sm-4 col-xs-4">
diff --git a/static/website/templates/new-question.html b/static/website/templates/new-question.html
index cb0439d..da803de 100644
--- a/static/website/templates/new-question.html
+++ b/static/website/templates/new-question.html
@@ -14,8 +14,9 @@
<img id="ajax-loader" src="{% static 'website/images/ajax-loader.gif' %}" style="display:none;">
</p>
<div class="row">
+ {{ form.category.errors }}
<div class="col-lg-3 col-md-3 col-sm-3">
- {% render_field form.category class+="form-control"%}
+ {% render_field form.category class+="form-control category"%}
</div>
<!--<div class="col-lg-3 col-md-3 col-sm-3">
{% if category %}
@@ -37,14 +38,17 @@
<p>Please enter your question details.</p>
<div class="row">
<div class="col-lg-12">
+ {{ form.title.errors }}
<div class="form-group">
<label for="id_title">Title:</label>
- {% render_field form.title class+="form-control" %}
+ {% render_field form.title class+="form-control title" %}
</div>
+ {{ form.body.errors }}
<div class="form-group">
<label for="id_body">Question:</label>
- {% render_field form.body class+="form-control" %}
+ {% render_field form.body class+="form-control body" %}
</div>
+
</div>
</div>
<input class="btn btn-success" type="submit" value="Submit Question">
diff --git a/static/website/templates/questions.html b/static/website/templates/questions.html
index 5242236..98d016d 100644
--- a/static/website/templates/questions.html
+++ b/static/website/templates/questions.html
@@ -10,10 +10,7 @@
</h4>
<table class="table table-bordered table-hover">
<th> FOSS </th>
- <!--<th> Tutorial</th>-->
- <th> Min </th>
- <th> Sec </th>
- <th> Question <span class="glyphicon glyphicon-link"></span></th>
+ <th> Question <span class="glyphicon glyphicon-link"></span></th>
<th> Date</th>
<th> Views</th>
<th> Answers</th>
@@ -21,41 +18,18 @@
{% for question in questions %}
<tr>
<td>
- <span href="#" class="category" data-toggle="tooltip" data-placement="top" title="{{ question.category}}">
- {{ question.category|truncatechars:12 }}
+ <span class="category" data-toggle="tooltip" data-placement="top" title="{{ question.category}}">
+
+ <a class="pull-left" href="{% url 'website:filter' question.category %}?qid={{ question.id }}">
+ {{ question.category|truncatechars:12 }}
+ </a>
+
</span>
- <a class="pull-right" href="{% url 'website:filter' question.category %}?qid={{ question.id }}">
- <span class="glyphicon glyphicon-search"></span>
- </a>
</td>
+
<td>
- <span class="tutorial" data-toggle="tooltip" data-placement="top" title="{{ question.tutorial}}">
- {{ question.tutorial|truncatechars:12 }}
- </span>
- <a class="pull-right" href="{% url 'website:filter' question.category question.tutorial %}?qid={{ question.id }}">
- <span class="glyphicon glyphicon-search"></span>
- </a>
- </td>
-
- <!--<td>
- <span>
- <a href="{% url 'website:filter' question.category question.tutorial %}?qid={{ question.id }}">
- {{ question.minute_range }}
- </a>
- </span>
- </td>
-
- <td>
- <span>
- <a href="{% url 'website:filter' question.category question.tutorial %}?qid={{ question.id }}">
- {{ question.second_range }}
- </a>
- </span>
- </td>-->
-
- <td>
- <span class="title" data-toggle="tooltip" data-placement="top" title="{{ question.title }}">
+ <span class="question" data-toggle="tooltip" data-placement="top" title="{{ question.title }}">
<a href="{% url 'website:get_question' question.id %}">{{ question.title|truncatechars:40 }}</a>
</span>
</td>
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)