From dfccf31f44c9d1649839ab50bc89865f8f7f15f3 Mon Sep 17 00:00:00 2001 From: Eric Theise Date: Wed, 8 Apr 2020 18:08:53 -0700 Subject: [PATCH] feat: addresses #17 & #21, revising survey --- maps/views.py | 1 - surveys/forms.py | 53 ++++++-- surveys/preview.py | 17 --- .../surveys/{ => ecosystem_2020}/base.html | 2 +- .../basic_organization_info.html | 34 ++++++ .../surveys/ecosystem_2020/contact_info.html | 54 ++++++++ .../surveys/{ => ecosystem_2020}/done.html | 2 +- .../surveys/{ => ecosystem_2020}/header.html | 0 .../surveys/ecosystem_2020/index.html | 54 ++++++++ .../ecosystem_2020/social_networks.html | 37 ++++++ surveys/templates/surveys/index.html | 115 ------------------ surveys/templates/surveys/individual.html | 52 -------- surveys/urls.py | 18 ++- surveys/views.py | 57 ++++++--- 14 files changed, 270 insertions(+), 226 deletions(-) delete mode 100644 surveys/preview.py rename surveys/templates/surveys/{ => ecosystem_2020}/base.html (93%) create mode 100644 surveys/templates/surveys/ecosystem_2020/basic_organization_info.html create mode 100644 surveys/templates/surveys/ecosystem_2020/contact_info.html rename surveys/templates/surveys/{ => ecosystem_2020}/done.html (80%) rename surveys/templates/surveys/{ => ecosystem_2020}/header.html (100%) create mode 100644 surveys/templates/surveys/ecosystem_2020/index.html create mode 100644 surveys/templates/surveys/ecosystem_2020/social_networks.html delete mode 100644 surveys/templates/surveys/index.html delete mode 100644 surveys/templates/surveys/individual.html diff --git a/maps/views.py b/maps/views.py index 09350d9..6cb9ada 100644 --- a/maps/views.py +++ b/maps/views.py @@ -29,7 +29,6 @@ def manage_socialnetworks(request, user_id): # Profile flow # This trivially branches to either the Organization or Individual Profile `django-formtools` wizard. def profile(request): - print(request.POST) if request.method == 'POST': if request.POST['type'] == 'org': return redirect('organization-profile') diff --git a/surveys/forms.py b/surveys/forms.py index 1f0d050..cc2818c 100644 --- a/surveys/forms.py +++ b/surveys/forms.py @@ -1,19 +1,36 @@ from django import forms -from django.forms import TextInput, ModelForm, RadioSelect, CheckboxSelectMultiple, DateTimeInput, URLInput, modelformset_factory +from django.forms import RadioSelect, CheckboxSelectMultiple, DateTimeInput, HiddenInput, URLInput, formset_factory from django.utils.translation import gettext_lazy as _ +from django.template.defaultfilters import safe from accounts.models import User, Role -from mdi.models import Organization, Sector, SocialNetwork +from mdi.models import Organization, OrganizationSocialNetwork, Sector, SocialNetwork -class IndividualForm(forms.Form): +class BaseForm(forms.Form): + def __init__(self, *args, **kwargs): + kwargs.setdefault('label_suffix', '') # globally override the Django >=1.6 default of ':' + super(BaseForm, self).__init__(*args, **kwargs) + + +class BaseModelForm(forms.ModelForm): + def __init__(self, *args, **kwargs): + kwargs.setdefault('label_suffix', '') # globally override the Django >=1.6 default of ':' + super(BaseModelForm, self).__init__(*args, **kwargs) + + +class ContactInfoForm(BaseForm): first_name = forms.CharField(max_length=254, required=False) middle_name = forms.CharField(max_length=254,required=False) last_name = forms.CharField(max_length=254, required=False) email = forms.EmailField(max_length=254, label='Email address') - role = forms.ChoiceField(choices=enumerate(Role.objects.all()), label='Are you/is this person a…', widget=RadioSelect(attrs={'class': 'radio'})) + role = forms.ModelMultipleChoiceField( + queryset=Role.objects.all(), + label=safe('Are you/is this person a…'), + widget=CheckboxSelectMultiple(attrs={'class': 'checkbox'}) + ) -class OrganizationForm(ModelForm): +class BasicOrganizationInfoForm(BaseModelForm): class Meta: model = Organization fields = [ @@ -34,6 +51,7 @@ class Meta: 'url': _('What is the URL of your enterprise or project?'), 'email': _('What is the general contact email address for your enterprise or project?'), 'socialnetworks': _('What are the social media handles of your enterprise or project?'), + 'address': _(safe('What is the physical address of the headquarters of your enterprise or project?
Street')), 'state': _('State or province'), 'founded': _('When was your enterprise or project founded?'), 'media_url': _('Paste a link to photos or any introductory video about your enterprise or project:'), @@ -49,7 +67,7 @@ class Meta: } -class SocialNetworksForm(ModelForm): +class SocialNetworksForm(BaseModelForm): class Meta: model = SocialNetwork fields = [ @@ -58,7 +76,7 @@ class Meta: ] -class LegalStatusForm(ModelForm): +class LegalStatusForm(BaseModelForm): class Meta: model = Organization fields = [ @@ -72,7 +90,7 @@ class Meta: } -class StageForm(ModelForm): +class StageForm(BaseModelForm): class Meta: model = Organization fields = [ @@ -86,7 +104,7 @@ class Meta: } -class CategoryForm(ModelForm): +class CategoryForm(BaseModelForm): class Meta: model = Organization fields = [ @@ -100,7 +118,7 @@ class Meta: } -class SectorForm(ModelForm): +class SectorForm(BaseModelForm): class Meta: model = Organization fields = [ @@ -112,3 +130,18 @@ class Meta: widgets = { 'sectors': CheckboxSelectMultiple(attrs={'class': 'checkbox'}) } + + +class OrganizationSocialNetworkForm(BaseModelForm): + class Meta: + model = OrganizationSocialNetwork + fields = [ + 'socialnetwork', + 'identifier', + ] + widgets = { + 'socialnetwork': HiddenInput(), + } + + +OrganizationSocialNetworkFormSet = formset_factory(OrganizationSocialNetworkForm, extra=0) diff --git a/surveys/preview.py b/surveys/preview.py deleted file mode 100644 index 94d4549..0000000 --- a/surveys/preview.py +++ /dev/null @@ -1,17 +0,0 @@ -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/templates/surveys/base.html b/surveys/templates/surveys/ecosystem_2020/base.html similarity index 93% rename from surveys/templates/surveys/base.html rename to surveys/templates/surveys/ecosystem_2020/base.html index 0d70d2a..c2f06fe 100644 --- a/surveys/templates/surveys/base.html +++ b/surveys/templates/surveys/ecosystem_2020/base.html @@ -13,7 +13,7 @@ -{% include 'surveys/header.html' %} +{% include 'surveys/ecosystem_2020/header.html' %}
diff --git a/surveys/templates/surveys/ecosystem_2020/basic_organization_info.html b/surveys/templates/surveys/ecosystem_2020/basic_organization_info.html new file mode 100644 index 0000000..cf92dd0 --- /dev/null +++ b/surveys/templates/surveys/ecosystem_2020/basic_organization_info.html @@ -0,0 +1,34 @@ +{% extends 'surveys/ecosystem_2020/base.html' %} +{% load static %} +{% load i18n %} +{% load maps_extras %} +{% block title %}{{ 'Basic Organization Information'|titlify }}{% endblock %} +{% block content %} + +
+ {% csrf_token %} + {% if form.errors %} + {{ form.errors }} + {% endif %} + {{ wizard.management_form }} +{% include 'maps/profiles/back_and_steps.html' %} + {% if wizard.form.forms %} + {{ wizard.form.management_form }} + {% for form in wizard.form.forms %} + {{ form }} + {% endfor %} + {% else %} +
+ Basic organization information +
+ {{ wizard.form }} +
+
+ {% endif %} + +{% include 'maps/profiles/footer.html' %} +
+ +{% endblock %} diff --git a/surveys/templates/surveys/ecosystem_2020/contact_info.html b/surveys/templates/surveys/ecosystem_2020/contact_info.html new file mode 100644 index 0000000..0c046a0 --- /dev/null +++ b/surveys/templates/surveys/ecosystem_2020/contact_info.html @@ -0,0 +1,54 @@ +{% extends 'surveys/ecosystem_2020/base.html' %} +{% load static %} +{% load i18n %} +{% load maps_extras %} +{% block title %}{{ 'Contact Information'|titlify }}{% endblock %} +{% block content %} + +
+ {% csrf_token %} + {% if form.errors %} + {{ form.errors }} + {% endif %} + {{ wizard.management_form }} +{% include 'maps/profiles/back_and_steps.html' %} + {% if wizard.form.forms %} + {{ wizard.form.management_form }} + {% for form in wizard.form.forms %} + {{ form }} + {% endfor %} + {% else %} +
+ 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.

+
+ + + + +
    + {{ wizard.form.role.label }} + {% for checkbox in wizard.form.role %} +
  • {{ checkbox.tag }} + +
  • + {% endfor %} +
+
+
+ {% endif %} + +{% include 'maps/profiles/footer.html' %} +
+ +{% endblock %} diff --git a/surveys/templates/surveys/done.html b/surveys/templates/surveys/ecosystem_2020/done.html similarity index 80% rename from surveys/templates/surveys/done.html rename to surveys/templates/surveys/ecosystem_2020/done.html index c3a2a4b..1f159cb 100644 --- a/surveys/templates/surveys/done.html +++ b/surveys/templates/surveys/ecosystem_2020/done.html @@ -1,4 +1,4 @@ -{% extends 'surveys/base.html' %} +{% extends 'surveys/ecosystem_2020/base.html' %} {% load static %} {% load i18n %} {% load maps_extras %} diff --git a/surveys/templates/surveys/header.html b/surveys/templates/surveys/ecosystem_2020/header.html similarity index 100% rename from surveys/templates/surveys/header.html rename to surveys/templates/surveys/ecosystem_2020/header.html diff --git a/surveys/templates/surveys/ecosystem_2020/index.html b/surveys/templates/surveys/ecosystem_2020/index.html new file mode 100644 index 0000000..f44a22a --- /dev/null +++ b/surveys/templates/surveys/ecosystem_2020/index.html @@ -0,0 +1,54 @@ +{% extends 'surveys/ecosystem_2020/base.html' %} +{% load static %} +{% load i18n %} +{% load maps_extras %} +{% block title %}{{ '2020 Ecosystem Survey'|titlify }}{% endblock %} +{% block content %} + + +
+ {% csrf_token %} +

Do you need funding for your cooperative digital project?

+

No matter at which stage of development, potential funders, the International Cooperative Alliance, and + supportive policymakers need to know that you exist!!

+ +

Whether your project just launched or is already fully operational and growing, prospective supporters need to + understand the significance of your project!

+ +

They need to grasp that you matter. FOR THAT, THEY NEED DATA!

+ +

We need to provide funders and all supporters with reliable information about your project!! Without it, you may + be dismissed and remain invisible.

+ +

Please help us to help you.

+ +

The survey has been prepared by Prof. Trebor Scholz and Angela Difede at The New School’s Institute for the + Cooperative Digital Economy. Please feel free to contact us directly with any questions.

+ +

WE WILL ADD THE INFORMATION THAT YOU PROVIDE HERE TO A *PUBLIC INDEX* ON HTTP://PLATFORM.COOP

+ +

+ Our email:
+ info@platform.coop +

+ +

+ Mail:
+ Institute for the Cooperative Digital Economy
+ The New School
+ 79 5th Avenue, Room 1601
+ New York, NY, 10003
+ USA +

+ +
+ + +
+ +{% endblock %} diff --git a/surveys/templates/surveys/ecosystem_2020/social_networks.html b/surveys/templates/surveys/ecosystem_2020/social_networks.html new file mode 100644 index 0000000..2aeae6b --- /dev/null +++ b/surveys/templates/surveys/ecosystem_2020/social_networks.html @@ -0,0 +1,37 @@ +{% extends "maps/base.html" %} +{% load static %} +{% load i18n %} +{% load maps_extras %} + +{% block title %}{{ 'Social media'|titlify }}{% endblock %}} + +{% block content %} + +
+ {% csrf_token %} + {% if form.errors %} + {{ form.errors }} + {% endif %} + {{ wizard.management_form }} +{% include 'maps/profiles/back_and_steps.html' %} + {% if wizard.form.forms %} + {{ wizard.form.management_form }} +

What are the associated social media handles of your enterprise or project?

+
+ + {% for form in wizard.form.forms %} + + {% endfor %} + {% else %} + + {% endif %} + +{% include 'maps/profiles/footer.html' %} +
+ +{% endblock %} diff --git a/surveys/templates/surveys/index.html b/surveys/templates/surveys/index.html deleted file mode 100644 index e7b3c30..0000000 --- a/surveys/templates/surveys/index.html +++ /dev/null @@ -1,115 +0,0 @@ -{% 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?

-

No matter at which stage of development, potential funders, the International Cooperative Alliance, and supportive policymakers need to know that you exist!!

- -

Whether your project just launched or is already fully operational and growing, prospective supporters need to understand the significance of your project!

- -

They need to grasp that you matter. FOR THAT, THEY NEED DATA!

- -

We need to provide funders and all supporters with reliable information about your project!! Without it, you may be dismissed and remain invisible.

- -

Please help us to help you.

- -

The survey has been prepared by Prof. Trebor Scholz and Angela Difede at The New School’s Institute for the Cooperative Digital Economy. Please feel free to contact us directly with any questions.

- -

WE WILL ADD THE INFORMATION THAT YOU PROVIDE HERE TO A *PUBLIC INDEX* ON HTTP://PLATFORM.COOP

- -

- Our email:
- info@platform.coop -

-

- Mail:
- Institute for the Cooperative Digital Economy
- The New School
- 79 5th Avenue, Room 1601
- New York, NY, 10003
- USA -

- -
-
- {% 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.

-
- {{ user_form }} -
    - {{ role_form.role.label }} - {% for radio in role_form.role %} -
  • {{ radio.tag }} - -
  • - {% endfor %} -
- -
- -
-
- About your enterprise or project - {{ organization_form }} -
    -{% comment %} {% for sn in socialnetworks_form.socialnetworks %} -
  • {{ sn.tag }}: -{# #} -
  • - {% endfor %}{% endcomment %} -
- -
    - {{ legal_status_form.legal_status.label }} - {% for checkbox in legal_status_form.legal_status %} -
  • {{ checkbox.tag }} - -
  • - {% endfor %} -
- -
    - {{ stage_form.stage.label }} - {% for radio in stage_form.stage %} -
  • {{ radio.tag }} - -
  • - {% endfor %} -
- -
    - {{ category_form.categories.label }} - {% for checkbox in category_form.categories %} -
  • {{ checkbox.tag }} - -
  • - {% endfor %} -
- -
    - {{ sector_form.sectors.label }} - {% for checkbox in sector_form.sectors %} -
  • {{ checkbox.tag }} - -
  • - {% endfor %} -
- -
- -
- -
- -{% endblock %} diff --git a/surveys/templates/surveys/individual.html b/surveys/templates/surveys/individual.html deleted file mode 100644 index 68d9d77..0000000 --- a/surveys/templates/surveys/individual.html +++ /dev/null @@ -1,52 +0,0 @@ -{% 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 0d1c650..f3444df 100644 --- a/surveys/urls.py +++ b/surveys/urls.py @@ -1,16 +1,12 @@ from django.urls import path from django.conf.urls import url -from . import views -from .forms import IndividualForm, OrganizationForm, SocialNetworksForm -from .preview import IndividualFormPreview, OrganizationFormPreview, SocialNetworksFormPreview -from .views import FORMS, SurveyWizard, ContactWizard - +from .forms import SocialNetworksForm +from . views import index, ECOSYSTEM_FORMS, EcosystemWizard +from mdi.models import OrganizationSocialNetwork urlpatterns = [ - # path('', views.index, name='index'), - url(r'^ecosystem/$', SurveyWizard.as_view(FORMS)), - url(r'^preview/individual/$', IndividualFormPreview(IndividualForm)), - url(r'^preview/organization/$', OrganizationFormPreview(OrganizationForm)), - url(r'^preview/socialnetworks/$', SocialNetworksFormPreview(SocialNetworksForm)), - url(r'^ecosystem-2020/$', ContactWizard.as_view([IndividualForm, OrganizationForm, SocialNetworksForm])), + url(r'^$', index), + path(r'ecosystem-2020/', + EcosystemWizard.as_view(ECOSYSTEM_FORMS, instance_dict={'social_networks': OrganizationSocialNetwork}), + name='ecosystem-2020'), ] diff --git a/surveys/views.py b/surveys/views.py index 815ac95..26ee20b 100644 --- a/surveys/views.py +++ b/surveys/views.py @@ -1,37 +1,58 @@ from django.http import HttpResponse, HttpResponseRedirect from django.template import loader +from django.views.generic import TemplateView from formtools.wizard.views import SessionWizardView -from django.shortcuts import get_object_or_404, render -from .forms import IndividualForm, OrganizationForm, LegalStatusForm, StageForm, CategoryForm, SectorForm +from django.shortcuts import get_object_or_404, render, redirect +from .forms import ContactInfoForm, BasicOrganizationInfoForm, OrganizationSocialNetworkFormSet, LegalStatusForm, StageForm, CategoryForm, SectorForm from accounts.models import User -from mdi.models import Organization, Category, Sector, Type +from mdi.models import Organization, Category, Sector, Type, SocialNetwork -class ContactWizard(SessionWizardView): - def done(self, form_list, **kwargs): - return render(self.request, 'surveys/done.html', { - 'form_data': [form.cleaned_data for form in form_list], - }) - - -FORMS = [ - ('individual', IndividualForm), - ('organization', OrganizationForm), +ECOSYSTEM_FORMS = [ + ('contact_info', ContactInfoForm), + ('basic_organization_info', BasicOrganizationInfoForm), + ('social_networks', OrganizationSocialNetworkFormSet), ] -TEMPLATES = { - 'individual': 'surveys/individual.html', - 'organization': 'surveys/index.html', +ECOSYSTEM_TEMPLATES = { + 'contact_info': 'surveys/ecosystem_2020/contact_info.html', + 'basic_organization_info': 'surveys/ecosystem_2020/basic_organization_info.html', + 'social_networks': 'surveys/ecosystem_2020/social_networks.html', } -class SurveyWizard(SessionWizardView): +class EcosystemWizard(SessionWizardView): def get_template_names(self): - return [TEMPLATES[self.steps.current]] + return [ECOSYSTEM_TEMPLATES[self.steps.current]] + + def get_context_data(self, form, **kwargs): + context = super().get_context_data(form=form, **kwargs) + return context + + def get_form_initial(self, step): + initial = [] + if step == 'social_networks': + socialnetworks = SocialNetwork.objects.all() + for index, sn in enumerate(socialnetworks): + initial.append({ + 'socialnetwork' : sn, + 'name': sn.name, + 'hint' : sn.hint, + }) + # print(initial) + return self.initial_dict.get('social_networks', initial) def done(self, form_list, **kwargs): return render(self.request, 'done.html', { 'form_data': [form.cleaned_data for form in form_list], }) + +def index(request): + if request.method == 'POST': + return redirect('ecosystem-2020') + + else: + return render(request, 'surveys/ecosystem_2020/index.html') +