From 2d2a6f1b95afd35e3d324cf364e5868330c1437e Mon Sep 17 00:00:00 2001 From: Eric Theise Date: Fri, 3 Apr 2020 11:34:39 -0700 Subject: [PATCH] feat: #21 survey forms & formtools --- surveys/preview.py | 17 ++++++++ surveys/static/surveys/css/surveys.css | 3 ++ surveys/static/surveys/js/surveys.js | 1 + surveys/templates/surveys/done.html | 8 ++++ surveys/templates/surveys/individual.html | 52 +++++++++++++++++++++++ surveys/urls.py | 2 +- 6 files changed, 82 insertions(+), 1 deletion(-) create mode 100644 surveys/preview.py create mode 100644 surveys/static/surveys/css/surveys.css create mode 100644 surveys/static/surveys/js/surveys.js create mode 100644 surveys/templates/surveys/done.html create mode 100644 surveys/templates/surveys/individual.html diff --git a/surveys/preview.py b/surveys/preview.py new file mode 100644 index 0000000..94d4549 --- /dev/null +++ b/surveys/preview.py @@ -0,0 +1,17 @@ +from django.http import HttpResponseRedirect +from formtools.preview import FormPreview + + +class IndividualFormPreview(FormPreview): + def done(self, request, cleaned_data): + return HttpResponseRedirect('/form/success') + + +class OrganizationFormPreview(FormPreview): + def done(self, request, cleaned_data): + return HttpResponseRedirect('/form/success') + + +class SocialNetworksFormPreview(FormPreview): + def done(self, request, cleaned_data): + return HttpResponseRedirect('/form/success') diff --git a/surveys/static/surveys/css/surveys.css b/surveys/static/surveys/css/surveys.css new file mode 100644 index 0000000..026293a --- /dev/null +++ b/surveys/static/surveys/css/surveys.css @@ -0,0 +1,3 @@ +fieldset > label { + line-height: 3rem; +} diff --git a/surveys/static/surveys/js/surveys.js b/surveys/static/surveys/js/surveys.js new file mode 100644 index 0000000..e9fa46d --- /dev/null +++ b/surveys/static/surveys/js/surveys.js @@ -0,0 +1 @@ +document.getElementsByTagName('label') diff --git a/surveys/templates/surveys/done.html b/surveys/templates/surveys/done.html new file mode 100644 index 0000000..c3a2a4b --- /dev/null +++ b/surveys/templates/surveys/done.html @@ -0,0 +1,8 @@ +{% extends 'surveys/base.html' %} +{% load static %} +{% load i18n %} +{% load maps_extras %} +{% block title %}{{ '2020 Ecosystem Survey'|titlify }}{% endblock %} +{% block content %} +
{{ form_data | pprint }}
+{% endblock %} diff --git a/surveys/templates/surveys/individual.html b/surveys/templates/surveys/individual.html new file mode 100644 index 0000000..68d9d77 --- /dev/null +++ b/surveys/templates/surveys/individual.html @@ -0,0 +1,52 @@ +{% extends 'surveys/base.html' %} +{% load static %} +{% load i18n %} +{% load maps_extras %} +{% block title %}{{ '2020 Ecosystem Survey'|titlify }}{% endblock %} +{% block content %} + +

Do you need funding for your cooperative digital project?

+ +
+ Step {{ wizard.steps.step1 }} of {{ wizard.steps.count }} +
+ {{ wizard.management_form }} + {% if wizard.form.forms %} + {{ wizard.form.management_form }} + {% for form in wizard.form.forms %} + {{ form }} + {% endfor %} + {% else %} + {{ wizard.form }} + {% endif %} + + {% csrf_token %} + {% if error_message %}

{{ error_message }}

{% endif %} +
+ Your contact information +

Please provide the contact information for the best person to reach out to should we have follow-up questions about the answers you have provided to the short form of our survey. This contact information will not be part of the index. It will not be published online.

+
+ {{ individual_form }} +
    + {{ role_form.role.label }} + {% for radio in role_form.role %} +
  • {{ radio.tag }} + +
  • + {% endfor %} +
+ +
+ + {% if wizard.steps.prev %} + + + {% endif %} + + +
+ +{% endblock %} diff --git a/surveys/urls.py b/surveys/urls.py index 2e2b0db..0d1c650 100644 --- a/surveys/urls.py +++ b/surveys/urls.py @@ -3,7 +3,7 @@ from . import views from .forms import IndividualForm, OrganizationForm, SocialNetworksForm from .preview import IndividualFormPreview, OrganizationFormPreview, SocialNetworksFormPreview -from .views import SurveyWizard, FORMS, TEMPLATES, ContactWizard +from .views import FORMS, SurveyWizard, ContactWizard urlpatterns = [