Skip to content

Commit

Permalink
15 - Save User Answer
Browse files Browse the repository at this point in the history
  • Loading branch information
jmitchel3 committed Jul 13, 2015
1 parent fd5eb06 commit 60ef628
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 7 deletions.
Binary file modified src/db.sqlite3
Binary file not shown.
4 changes: 2 additions & 2 deletions src/questions/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ class UserResponseForm(forms.Form):
question_id = forms.IntegerField()
answer_id = forms.IntegerField()
importance_level = forms.ChoiceField(choices=LEVELS)
coworker_answer_id = forms.IntegerField()
coworker_importance_level = forms.ChoiceField(choices=LEVELS)
their_answer_id = forms.IntegerField()
their_importance_level = forms.ChoiceField(choices=LEVELS)
Binary file modified src/questions/forms.pyc
Binary file not shown.
25 changes: 23 additions & 2 deletions src/questions/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# Create your views here.

from .forms import UserResponseForm
from .models import Question, Answer
from .models import Question, Answer, UserAnswer



Expand All @@ -14,11 +14,32 @@ def single(request, id):
if form.is_valid():
print form.cleaned_data
#print request.POST

question_id = form.cleaned_data.get('question_id') #form.cleaned_data['question_id']

answer_id = form.cleaned_data.get('answer_id')
importance_level = form.cleaned_data.get('importance_level')

their_importance_level = form.cleaned_data.get('their_importance_level')
their_answer_id = form.cleaned_data.get('their_answer_id')


question_instance = Question.objects.get(id=question_id)
answer_instance = Answer.objects.get(id=answer_id)
print answer_instance.text, question_instance.text

new_user_answer = UserAnswer()
new_user_answer.user = request.user
new_user_answer.question = question_instance
new_user_answer.my_answer = answer_instance
new_user_answer.my_answer_importance = importance_level
if their_answer_id != -1:
their_answer_istance = Answer.objects.get(id=their_answer_id)
new_user_answer.their_answer = their_answer_istance
new_user_answer.their_importance = their_importance_level
else:
new_user_answer.their_importance = "Not Important"
new_user_answer.save()

next_q = Question.objects.all().order_by("?").first()
return redirect("question_single", id=next_q.id)

Expand Down
Binary file modified src/questions/views.pyc
Binary file not shown.
6 changes: 3 additions & 3 deletions src/templates/questions/single.html
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@ <h3>Your answer</h3>

<h3>Your coworker's ideal answer</h3>
{% for ans in instance.answer_set.all %}
<input type='radio' name='coworker_answer_id' value='{{ ans.id }}'/> {{ ans.text }} <br/>
<input type='radio' name='their_answer_id' value='{{ ans.id }}'/> {{ ans.text }} <br/>
{% endfor %}
<input type='radio' name='coworker_answer_id' value='-1'/> Holds no importance <br/>
<input type='radio' name='their_answer_id' value='-1'/> Holds no importance <br/>


<br/>
Importance: {{ form.coworker_importance_level }} <br/><br/>
Importance: {{ form.their_importance_level }} <br/><br/>


<input type='submit' value='Save and continue' />
Expand Down

0 comments on commit 60ef628

Please sign in to comment.