Commit 388f49c6 authored by mdefilippis's avatar mdefilippis
Browse files

all questions page with input

parent bb2dfd8f
......@@ -31,5 +31,6 @@ urlpatterns = [
url(r'^admin/', admin.site.urls),
url(r'^$', views.index, name='index'),
url(r'^ask/', views.ask, name='ask'),
url(r'^all/', views.all, name='all'),
]
......@@ -2,4 +2,8 @@ from django import forms
class QuestionForm(forms.Form):
your_question = forms.CharField(label='Your question', max_length=100)
your_question = forms.CharField(label='', max_length=100,widget=forms.TextInput(attrs={'size': 80}))
class AnswerForm(forms.Form):
answer = forms.CharField(max_length=100, widget=forms.TextInput(attrs={'size':60}))
{% extends 'base.html' %}
{% load staticfiles%}
{% load static %}
{% block navbar %}
<div class="col-md-12 col-sm-12 col-xs-6">
{% include "navbar.html" %}
</div>
{% endblock %}
{% block content %}
<div class="container well" style="background-color:white;">
<table class="table">
<thead>
<tr>
<th>Question</th>
<th>Reponse</th>
<th>Date</th>
</tr>
</thead>
<tbody>
{% for question in questions %}
<tr>
<td style="font-weight: 900;"><a href="">{{question.question}}</a></td>
<td>{{question.answer.response}} {% if not question.answer %}
<form method="POST" action="{% url 'all' %}">
{% csrf_token %}
<input hidden="true" value="{{question.question}}" name="question"/>
<input type="text" value="" name="answer"/>
<h5><a href="#" onclick="$(this).closest('form').submit()">send</a></h5>
</form>
{% endif %}</td>
<td class="">{{question.created}}</td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
{% endblock %}
\ No newline at end of file
......@@ -11,7 +11,9 @@
<ul class="nav navbar-nav">
<li class=""><a href="{% url 'index' %}">Home</a></li>
<li><a href="{% url 'ask' %}">Ask a question</a></li>
{% if user.is_superuser %}
<li><a href="{% url 'all' %}">See all questions</a></li>
{% endif %}
<li><a href="/tacos">Logout</a></li>
</ul>
......
......@@ -2,13 +2,22 @@
{% load staticfiles%}
{% load static %}
{% block navbar %}
<div class="col-md-12 col-sm-12 col-xs-6">
{% include "navbar.html" %}
</div>
{% endblock %}
{% block content %}
<div class="container well">
<form action="/ask/" method="post">
<form class="col-md-12" action="/ask/" method="post">
{% csrf_token %}
<div><label>Your question :</label></div>
{{ form }}
<input type="submit" value="poster">
<div><input type="submit" value="post"></div>
</form>
</div>
......
......@@ -11,7 +11,7 @@ from faq.webapp.serializers import UserSerializer, QuestionSerializer, GroupSeri
from faq.webapp.models import Question, Answer
from django.http import HttpResponse
from django.template import loader
from .forms import QuestionForm
from .forms import QuestionForm, AnswerForm
from django.http import HttpResponseRedirect
from django.contrib import messages
......@@ -37,6 +37,23 @@ class QuestionViewSet(viewsets.ModelViewSet):
serializer_class = QuestionSerializer
@login_required
def all(request):
if request.method == 'POST':
question_text = request.POST['question']
answer_text = request.POST['answer']
q = Question.objects.get(question = question_text)
a = Answer(question = q, response = answer_text)
a.save()
questions = Question.objects.all().order_by('created')
context = {'questions': questions}
return render(request, 'all_questions.html', context)
@login_required
def index(request):
......
Supports Markdown
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