From 705d2930324766b4fb11818e1a8a238314d0e1b2 Mon Sep 17 00:00:00 2001 From: Eric Theise Date: Wed, 8 Apr 2020 21:05:06 -0700 Subject: [PATCH] feat: addresses #17 & #21, revising survey --- mdi/migrations/0060_auto_20200409_0147.py | 30 +++++++ mdi/models.py | 6 +- surveys/forms.py | 62 +++------------ surveys/static/surveys/css/surveys.css | 5 ++ .../ecosystem_2020/categories_challenges.html | 79 +++++++++++++++++++ surveys/urls.py | 1 - surveys/views.py | 7 +- 7 files changed, 134 insertions(+), 56 deletions(-) create mode 100644 mdi/migrations/0060_auto_20200409_0147.py create mode 100644 surveys/templates/surveys/ecosystem_2020/categories_challenges.html diff --git a/mdi/migrations/0060_auto_20200409_0147.py b/mdi/migrations/0060_auto_20200409_0147.py new file mode 100644 index 0000000..17b97b9 --- /dev/null +++ b/mdi/migrations/0060_auto_20200409_0147.py @@ -0,0 +1,30 @@ +# Generated by Django 3.0.3 on 2020-04-09 01:47 + +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + dependencies = [ + ('accounts', '0038_auto_20200407_0005'), + ('mdi', '0059_auto_20200405_0444'), + ] + + operations = [ + migrations.AlterField( + model_name='organization', + name='socialnetworks', + field=models.ManyToManyField(blank=True, through='mdi.OrganizationSocialNetwork', to='accounts.SocialNetwork'), + ), + migrations.AlterField( + model_name='organizationsocialnetwork', + name='identifier', + field=models.CharField(blank=True, max_length=255), + ), + migrations.AlterField( + model_name='organizationsocialnetwork', + name='socialnetwork', + field=models.ForeignKey(blank=True, on_delete=django.db.models.deletion.CASCADE, to='accounts.SocialNetwork'), + ), + ] diff --git a/mdi/models.py b/mdi/models.py index dfb80a3..29f9e84 100644 --- a/mdi/models.py +++ b/mdi/models.py @@ -224,7 +224,7 @@ class Organization(models.Model): sectors = models.ManyToManyField(Sector, blank=True,) legal_status = models.ManyToManyField(LegalStatus, blank=True,) challenges = models.ManyToManyField(Challenge, blank=True,) - socialnetworks = models.ManyToManyField(SocialNetwork, through='OrganizationSocialNetwork') + socialnetworks = models.ManyToManyField(SocialNetwork, blank=True, through='OrganizationSocialNetwork') notes = models.TextField(blank=True, default='') admin_email = models.EmailField(default='', max_length=255) created_at = models.DateTimeField(auto_now_add=True) @@ -265,8 +265,8 @@ def __str__(self): class OrganizationSocialNetwork(models.Model): organization = models.ForeignKey(Organization, on_delete=models.CASCADE) - socialnetwork = models.ForeignKey(SocialNetwork, on_delete=models.CASCADE) - identifier = models.CharField(blank=False, max_length=255) + socialnetwork = models.ForeignKey(SocialNetwork, blank=True, on_delete=models.CASCADE) + identifier = models.CharField(blank=True, max_length=255) created_at = models.DateTimeField(auto_now_add=True) updated_at = models.DateTimeField(auto_now=True) diff --git a/surveys/forms.py b/surveys/forms.py index cc2818c..47428c0 100644 --- a/surveys/forms.py +++ b/surveys/forms.py @@ -1,5 +1,6 @@ from django import forms -from django.forms import RadioSelect, CheckboxSelectMultiple, DateTimeInput, HiddenInput, URLInput, formset_factory +from django.forms import CheckboxSelectMultiple, DateTimeInput, HiddenInput, RadioSelect, SelectMultiple, \ + URLInput, formset_factory from django.utils.translation import gettext_lazy as _ from django.template.defaultfilters import safe from accounts.models import User, Role @@ -67,67 +68,28 @@ class Meta: } -class SocialNetworksForm(BaseModelForm): - class Meta: - model = SocialNetwork - fields = [ - 'name', - 'description', - ] - - -class LegalStatusForm(BaseModelForm): +class CategoriesChallengesForm(BaseModelForm): class Meta: model = Organization fields = [ 'legal_status', - ] - labels = { - 'legal_status': _('What is your status if you are a legally incorporated enterprise?'), - } - widgets = { - 'legal_status': CheckboxSelectMultiple(attrs={'class': 'checkbox'}) - } - - -class StageForm(BaseModelForm): - class Meta: - model = Organization - fields = [ 'stage', - ] - labels = { - 'stage': _('At what stage in the development process is your enterprise or project?'), - } - widgets = { - 'stage': RadioSelect(attrs={'class': 'radio'}) - } - - -class CategoryForm(BaseModelForm): - class Meta: - model = Organization - fields = [ + 'challenges', 'categories', - ] - labels = { - 'categories': _('Which terms do you use to describe your project or enterprise?'), - } - widgets = { - 'categories': CheckboxSelectMultiple(attrs={'class': 'checkbox'}) - } - - -class SectorForm(BaseModelForm): - class Meta: - model = Organization - fields = [ 'sectors', ] labels = { + 'legal_status': _('What is your status if you are a legally incorporated enterprise?'), + 'stage': _('At what stage in the development process is your enterprise or project?'), + 'challenges': _('What challenges are you facing with your project or enterprise?'), + 'categories': _('Which terms do you use to describe your project or enterprise?'), 'sectors': _('In which industries or sectors do you operate?'), } widgets = { + 'legal_status': CheckboxSelectMultiple(attrs={'class': 'checkbox'}), + 'stage': RadioSelect(attrs={'class': 'radio'}), + 'challenges': SelectMultiple(attrs={'size': 4, 'class': 'multiple'}), + 'categories': CheckboxSelectMultiple(attrs={'class': 'checkbox'}), 'sectors': CheckboxSelectMultiple(attrs={'class': 'checkbox'}) } diff --git a/surveys/static/surveys/css/surveys.css b/surveys/static/surveys/css/surveys.css index 026293a..52069d7 100644 --- a/surveys/static/surveys/css/surveys.css +++ b/surveys/static/surveys/css/surveys.css @@ -1,3 +1,8 @@ fieldset > label { line-height: 3rem; } + +select.multiple { + height: 10rem; + overflow-y: auto; +} diff --git a/surveys/templates/surveys/ecosystem_2020/categories_challenges.html b/surveys/templates/surveys/ecosystem_2020/categories_challenges.html new file mode 100644 index 0000000..ede8a8e --- /dev/null +++ b/surveys/templates/surveys/ecosystem_2020/categories_challenges.html @@ -0,0 +1,79 @@ +{% extends 'surveys/ecosystem_2020/base.html' %} +{% load static %} +{% load i18n %} +{% load maps_extras %} +{% block title %}{{ 'Categories & Challenges'|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 %} +
+ Incorporation +
    + {{ wizard.form.legal_status.label }} + {% for checkbox in wizard.form.legal_status %} +
  • {{ checkbox.tag }} + +
  • + {% endfor %} +
+
+
+ +
+ Development stage and challenges +
    + {{ wizard.form.stage.label }} + {% for radio in wizard.form.stage %} +
  • {{ radio.tag }} + +
  • + {% endfor %} +
+
+ + {{ wizard.form.challenges.label }} + {{ wizard.form.challenges }} +
+
+ + +
+
+ +
+ + + {% endif %} + +{% include 'maps/profiles/footer.html' %} +
+ +{% endblock %} diff --git a/surveys/urls.py b/surveys/urls.py index f3444df..46dbfdd 100644 --- a/surveys/urls.py +++ b/surveys/urls.py @@ -1,6 +1,5 @@ from django.urls import path from django.conf.urls import url -from .forms import SocialNetworksForm from . views import index, ECOSYSTEM_FORMS, EcosystemWizard from mdi.models import OrganizationSocialNetwork diff --git a/surveys/views.py b/surveys/views.py index 26ee20b..90a4a12 100644 --- a/surveys/views.py +++ b/surveys/views.py @@ -3,7 +3,8 @@ from django.views.generic import TemplateView from formtools.wizard.views import SessionWizardView from django.shortcuts import get_object_or_404, render, redirect -from .forms import ContactInfoForm, BasicOrganizationInfoForm, OrganizationSocialNetworkFormSet, LegalStatusForm, StageForm, CategoryForm, SectorForm +from .forms import ContactInfoForm, BasicOrganizationInfoForm, OrganizationSocialNetworkFormSet, \ + CategoriesChallengesForm from accounts.models import User from mdi.models import Organization, Category, Sector, Type, SocialNetwork @@ -13,12 +14,14 @@ ('contact_info', ContactInfoForm), ('basic_organization_info', BasicOrganizationInfoForm), ('social_networks', OrganizationSocialNetworkFormSet), + ('categories_challenges', CategoriesChallengesForm), ] 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', + 'categories_challenges': 'surveys/ecosystem_2020/categories_challenges.html', } @@ -44,7 +47,7 @@ def get_form_initial(self, step): return self.initial_dict.get('social_networks', initial) def done(self, form_list, **kwargs): - return render(self.request, 'done.html', { + return render(self.request, 'surveys/ecosystem_2020/done.html', { 'form_data': [form.cleaned_data for form in form_list], })