Skip to content

Commit

Permalink
feat: addresses #17 & #21, revising survey
Browse files Browse the repository at this point in the history
  • Loading branch information
erictheise committed Apr 9, 2020
1 parent dfccf31 commit 705d293
Show file tree
Hide file tree
Showing 7 changed files with 134 additions and 56 deletions.
30 changes: 30 additions & 0 deletions mdi/migrations/0060_auto_20200409_0147.py
Original file line number Diff line number Diff line change
@@ -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'),
),
]
6 changes: 3 additions & 3 deletions mdi/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)

Expand Down
62 changes: 12 additions & 50 deletions surveys/forms.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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'})
}

Expand Down
5 changes: 5 additions & 0 deletions surveys/static/surveys/css/surveys.css
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
fieldset > label {
line-height: 3rem;
}

select.multiple {
height: 10rem;
overflow-y: auto;
}
Original file line number Diff line number Diff line change
@@ -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 %}
<div class="page-header">
<h1><span class="pc-ff--sans pc-fw--normal">2020 Ecosystem Survey </span><br/> Categories & Challenges</h1>
</div>
<form action="" method="post">
{% 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 %}
<fieldset>
<legend><strong>Incorporation</strong></legend>
<ul class="input-group">
<strong>{{ wizard.form.legal_status.label }}</strong>
{% for checkbox in wizard.form.legal_status %}
<li>{{ checkbox.tag }}
<label for="{{ checkbox.id_for_label }}">{{ checkbox.choice_label }}</label>
</li>
{% endfor %}
</ul>
</fieldset>
<div class="spacer"></div>

<fieldset>
<legend><strong>Development stage and challenges</strong></legend>
<ul class="input-group">
<strong>{{ wizard.form.stage.label }}</strong>
{% for radio in wizard.form.stage %}
<li>{{ radio.tag }}
<label for="{{ radio.id_for_label }}">{{ radio.choice_label }}</label>
</li>
{% endfor %}
</ul>
<div class="spacer"></div>

<strong>{{ wizard.form.challenges.label }}</strong>
{{ wizard.form.challenges }}
</fieldset>
<div class="spacer"></div>

<ul class="input-group">
<strong>{{ wizard.form.categories.label }}</strong>
{% for checkbox in wizard.form.categories %}
<li>{{ checkbox.tag }}
<label for="{{ checkbox.id_for_label }}">{{ checkbox.choice_label }}</label>
</li>
{% endfor %}
</ul>
<div class="spacer"></div>
<div class="spacer"></div>
<ul class="input-group">
<strong>{{ wizard.form.sectors.label }}</strong>
{% for checkbox in wizard.form.sectors %}
<li>{{ checkbox.tag }}
<label for="{{ checkbox.id_for_label }}">{{ checkbox.choice_label }}</label>
</li>
{% endfor %}
</ul>
<div class="spacer"></div>

</fieldset>
{% endif %}

{% include 'maps/profiles/footer.html' %}
</form>

{% endblock %}
1 change: 0 additions & 1 deletion surveys/urls.py
Original file line number Diff line number Diff line change
@@ -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

Expand Down
7 changes: 5 additions & 2 deletions surveys/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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',
}


Expand All @@ -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],
})

Expand Down

0 comments on commit 705d293

Please sign in to comment.