Skip to content

Commit

Permalink
rewrites test data after 0.2 refactor (#8)
Browse files Browse the repository at this point in the history
  • Loading branch information
smirolo committed Feb 20, 2018
1 parent 523bbbe commit d5f87c6
Show file tree
Hide file tree
Showing 8 changed files with 203 additions and 74 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -49,5 +49,5 @@ initdb: install-conf
-rm -f db.sqlite3
cd $(srcDir) && $(PYTHON) ./manage.py migrate $(RUNSYNCDB) --noinput
cd $(srcDir) && $(PYTHON) ./manage.py loaddata \
testsite/fixtures/initial_data.json testsite/fixtures/testquestions.json
testsite/fixtures/initial_data.json

7 changes: 5 additions & 2 deletions survey/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
from django.template.defaultfilters import slugify
from django.utils import six

from .models import Choice, Sample, Campaign
from .models import Answer, Choice, Sample, Campaign
from .utils import get_question_model


Expand Down Expand Up @@ -74,10 +74,13 @@ def _create_field(question_type, text,
return fields


class AnswerForm(forms.Form):
class AnswerForm(forms.ModelForm):
"""
Form used to submit an Answer to a Question as part of Sample to a Campaign.
"""
class Meta:
model = Answer
fields = []

def __init__(self, *args, **kwargs):
super(AnswerForm, self).__init__(*args, **kwargs)
Expand Down
2 changes: 1 addition & 1 deletion survey/urls/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,5 +62,5 @@
url(r'^(?P<survey>[a-zA-Z0-9-]+)/',
QuestionListView.as_view(), name='survey_question_list'),
url(r'^',
CampaignListView.as_view(), name='survey_list'),
CampaignListView.as_view(), name='survey_campaign_list'),
]
13 changes: 7 additions & 6 deletions survey/views/sample.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@

from ..forms import AnswerForm, SampleCreateForm, SampleUpdateForm
from ..mixins import IntervieweeMixin, SampleMixin, CampaignMixin
from ..models import Choice, Sample, Answer
from ..models import Answer, Choice, EnumeratedQuestions, Sample
from ..utils import get_question_model


Expand Down Expand Up @@ -174,15 +174,16 @@ def form_valid(self, form):
# We are going to create all the Answer records for that Sample here,
# initialize them with a text when present in the submitted form.
self.object = form.save()
for question in get_question_model().objects.filter(
survey=self.object.survey):
for enum_q in EnumeratedQuestions.objects.filter(
campaign=self.object.survey):
kwargs = {'sample': self.object,
'question': question, 'rank': question.rank}
'question': enum_q.question, 'rank': enum_q.rank}
answer_text = form.cleaned_data.get(
'question-%d' % question.rank, None)
'question-%d' % enum_q.rank, None)
if answer_text:
kwargs.update({'text': answer_text})
Answer.objects.create(**kwargs)
Answer.objects.create(
metric=enum_q.question.default_metric, **kwargs)
return HttpResponseRedirect(self.get_success_url())

def get_context_data(self, **kwargs):
Expand Down
228 changes: 182 additions & 46 deletions testsite/fixtures/initial_data.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,51 +14,187 @@
},
"model": "auth.User", "pk": 2
},
{ "fields" : {
"slug" : "survey-example",
"title" : "Test Campaign",
"description" : "This is an example survey to test the app",
"account" : 2,
"active": true
},
"model" : "survey.campaign", "pk" : 1
},
{ "fields" : {
"text" : "Do you like the djaodjin-survey app...",
"survey" : 1,
"question_type" : "radio",
"choices" : "Somewhat\nYes\nAwesome",
"rank" : 1,
"required" : true
},
"model" : "survey.question", "pk" : 1
},
{ "fields" : {
"text" : "Which feature of the app do you use...",
"survey" : 1,
"question_type" : "checkbox",
"choices" : "Radio\nSelect Multiple\nFree form text\nInteger",
"rank" : 2,
"required" : true
},
"model" : "survey.question", "pk" : 2
},
{ "fields" : {
"text" : "Rate this app from 1 to 10...",
"survey" : 1,
"question_type" : "integer",
"rank" : 3,
"required" : true
},
"model" : "survey.question", "pk" : 3
},
{ "fields" : {
"text" : "Additional Comments...",
"survey" : 1,
"question_type" : "text",
"rank" : 4,
"required" : true
},
"model" : "survey.question", "pk" : 4
{
"fields" : {
"slug" : "survey-example",
"title" : "Test Campaign",
"description" : "This is an example survey to test the app",
"account" : 2,
"active": true
},
"model" : "survey.campaign", "pk" : 1
},
{ "fields": {
"slug": "q1",
"title": "Question 1",
"system": 3
},
"model" : "survey.unit", "pk" : 1
},
{ "fields": {
"slug": "q1",
"title": "Question 1",
"unit": 1
},
"model" : "survey.metric", "pk" : 1
},
{ "fields": {
"unit": 1,
"rank": 1,
"text": "Somewhat"
},
"model" : "survey.choice", "pk" : 1
},
{ "fields": {
"unit": 1,
"rank": 2,
"text": "Yes"
},
"model" : "survey.choice", "pk" : 2
},
{ "fields": {
"unit": 1,
"rank": 3,
"text": "Awesome"
},
"model" : "survey.choice", "pk" : 3
},
{ "fields": {
"slug": "q2",
"title": "Question 2",
"system": 3
},
"model" : "survey.unit", "pk" : 2
},
{ "fields": {
"slug": "q2",
"title": "Question 2",
"unit": 1
},
"model" : "survey.metric", "pk" : 2
},
{ "fields": {
"unit": 2,
"rank": 4,
"text": "Radio"
},
"model" : "survey.choice", "pk" : 4
},
{ "fields": {
"unit": 2,
"rank": 5,
"text": "Select Multiple"
},
"model" : "survey.choice", "pk" : 5
},
{ "fields": {
"unit": 2,
"rank": 6,
"text": "Free form text"
},
"model" : "survey.choice", "pk" : 6
},
{ "fields": {
"unit": 2,
"rank": 7,
"text": "Integer"
},
"model" : "survey.choice", "pk" : 7
},
{ "fields": {
"slug": "q3",
"title": "Question 3",
"system": 3
},
"model" : "survey.unit", "pk" : 3
},
{ "fields": {
"slug": "q3",
"title": "Question 3",
"unit": 2
},
"model" : "survey.metric", "pk" : 3
},
{ "fields": {
"slug": "q4",
"title": "Question 4",
"system": 3
},
"model" : "survey.unit", "pk" : 4
},
{ "fields": {
"slug": "q4",
"title": "Question 4",
"unit": 4
},
"model" : "survey.metric", "pk" : 4
},
{
"fields" : {
"path": "/q1",
"text" : "Do you like the djaodjin-survey app...",
"question_type" : "radio",
"default_metric": 1
},
"model" : "survey.question", "pk" : 1
},
{
"fields": {
"campaign": 1,
"question": 1,
"rank": 1
},
"model": "survey.EnumeratedQuestions", "pk": 1
},
{
"fields" : {
"path": "/q2",
"text" : "Which feature of the app do you use...",
"question_type" : "checkbox",
"default_metric": 2
},
"model" : "survey.question", "pk" : 2
},
{
"fields": {
"campaign": 1,
"question": 2,
"rank": 2
},
"model": "survey.EnumeratedQuestions", "pk": 2
},
{
"fields" : {
"path": "/q3",
"text" : "Rate this app from 1 to 10...",
"question_type" : "integer",
"default_metric": 3
},
"model" : "survey.question", "pk" : 3
},
{
"fields": {
"campaign": 1,
"question": 3,
"rank": 3
},
"model": "survey.EnumeratedQuestions", "pk": 3
},
{
"fields" : {
"path": "/q4",
"text" : "Additional Comments...",
"question_type" : "text",
"default_metric": 4
},
"model" : "survey.question", "pk" : 4
},
{
"fields": {
"campaign": 1,
"question": 4,
"rank": 4
},
"model": "survey.EnumeratedQuestions", "pk": 4
}
]
20 changes: 6 additions & 14 deletions testsite/fixtures/testquestions.json
Original file line number Diff line number Diff line change
@@ -1,38 +1,30 @@
[
{
"model": "survey.EditableFilter",
"pk": 1,
"fields": {
"slug": "all",
"created_at": "2016-07-07T00:14:57.185Z",
"updated_at": "2016-07-07T00:15:50.135Z",
"title": "all",
"tags": "cohort"
}
},
"model": "survey.EditableFilter", "pk": 1
},
{
"model": "survey.EditableFilter",
"pk": 2,
"fields": {
"slug": "all-1",
"created_at": "2016-07-07T00:16:06.370Z",
"updated_at": "2016-07-07T00:16:08.950Z",
"title": "all",
"tags": "metric"
}
},
"model": "survey.EditableFilter", "pk": 2
},
{
"model": "survey.matrix",
"pk": 1,
"fields": {
"created_at": "2016-07-07T00:14:52.777Z",
"title": "hello-world",
"slug": "hello-world",
"metric": 2,
"cohorts": [
1
]
}
},
"model": "survey.matrix", "pk": 1
},
{
"model": "auth.user",
Expand Down
3 changes: 0 additions & 3 deletions testsite/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,6 @@ def load_config(confpath):
# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/1.6/howto/deployment/checklist/

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = '9j24plovjvx%-_bvfgd*))umqd_olg!=4#a4i9_rf*)fl9b4b_'

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True

Expand Down
2 changes: 1 addition & 1 deletion testsite/templates/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<div id="wrap">
<header>
<ul>
<li><a href="{% url 'campaign_list' %}">campaign list</a>
<li><a href="{% url 'survey_campaign_list' %}">campaign list</a>
{% if request.user.is_authenticated %}
<li><a href="{% url 'logout' %}">sign out</a>
{% else %}
Expand Down

0 comments on commit d5f87c6

Please sign in to comment.