Skip to content

Commit

Permalink
feat: toward #17 and #21, survey models, etc
Browse files Browse the repository at this point in the history
  • Loading branch information
erictheise committed May 11, 2020
1 parent c3e7564 commit 17ec31a
Show file tree
Hide file tree
Showing 5 changed files with 229 additions and 169 deletions.
46 changes: 44 additions & 2 deletions surveys/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,48 @@
from django.template.defaultfilters import safe
from accounts.models import User, Role
from mdi.models import Organization, OrganizationSocialNetwork, Sector, SocialNetwork, Stage
from datetime import date
from django.utils import timezone


class DateSelectorWidget(forms.MultiWidget):
def __init__(self, attrs=None):
years = [(0, 'Select a year…')] + [(year, year) for year in reversed(range(1844, timezone.now().year + 2))]
months = [
(0, 'Select a month…'),
(1, 'January'),
(2, 'February'),
(3, 'March'),
(4, 'April'),
(5, 'May'),
(6, 'June'),
(7, 'July'),
(8, 'August'),
(9, 'September'),
(10, 'October'),
(11, 'November'),
(12, 'December'),
]
days = [(0, 'Select a day…')] + [(day, day) for day in range(1, 32)]
widgets = [
forms.Select(attrs={'class': 'required'}, choices=years),
forms.Select(attrs=attrs, choices=months),
forms.Select(attrs=attrs, choices=days),
]
super().__init__(widgets, attrs)

def decompress(self, value):
if isinstance(value, date):
return [value.year, value.month, value.day]
elif isinstance(value, str):
year, month, day = value.split('-')
return [year, month, day]
return [None, None, None]

def value_from_datadict(self, data, files, name):
year, month, day = super().value_from_datadict(data, files, name)
# DateField expects a single string that it can parse into a date.
return '{}-{}-{}'.format(year, month, day)


class BaseForm(forms.Form):
Expand Down Expand Up @@ -60,15 +102,15 @@ class Meta:
'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?<br/> Street')),
'state': _('State or province'),
'founded': _('When was your enterprise or project founded?'),
'founded': _(safe('When was your enterprise or project founded? (Year required. <span class="required"> *</span>)')),
'media_url': _('Paste a link to photos or any introductory video about your enterprise or project:'),
'logo_url': _('Paste a link to the logo for your enterprise or project:'),
}
help_texts = {
}
widgets = {
'url': URLInput(attrs={'placeholder': 'e.g., https://example.coop/'}),
'founded': DateTimeInput(format="%d/%m/%Y", attrs={'placeholder': "MM/DD/YYYY"}),
'founded': DateSelectorWidget(),
'media_url': URLInput(attrs={'placeholder': 'e.g., https://www.youtube.com/watch?v=qcPUARqRsVM'}),
'logo_url': URLInput(attrs={'placeholder': 'e.g., https://example.coop/logo.png'}),
}
Expand Down
166 changes: 83 additions & 83 deletions surveys/migrations/0001_initial.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,89 +27,89 @@ class Migration(migrations.Migration):
name='Ecosystem2020',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('a', models.DateTimeField(auto_now=True, db_column='A')),
('b', models.CharField(blank=True, db_column='B', max_length=254)),
('c', models.CharField(blank=True, db_column='C', max_length=254)),
('d', models.CharField(blank=True, db_column='D', max_length=254)),
('e', models.CharField(blank=True, db_column='E', max_length=254)),
('f', models.CharField(blank=True, db_column='F', max_length=254)),
('g', models.CharField(blank=True, db_column='G', max_length=254)),
('h', models.CharField(blank=True, db_column='H', max_length=254)),
('i', models.CharField(blank=True, db_column='I', max_length=254)),
('j', models.CharField(blank=True, db_column='J', max_length=254)),
('k', models.CharField(blank=True, db_column='K', max_length=254)),
('l', models.CharField(blank=True, db_column='L', max_length=254)),
('m', models.CharField(blank=True, db_column='M', max_length=254)),
('n', models.CharField(blank=True, db_column='N', max_length=254)),
('o', models.CharField(blank=True, db_column='O', max_length=254)),
('p', models.CharField(blank=True, db_column='P', max_length=254)),
('q', models.CharField(blank=True, db_column='Q', max_length=254)),
('r', models.CharField(blank=True, db_column='R', max_length=254)),
('s', models.CharField(blank=True, db_column='S', max_length=254)),
('t', models.CharField(blank=True, db_column='T', max_length=254)),
('u', models.CharField(blank=True, db_column='U', max_length=254)),
('v', models.CharField(blank=True, db_column='V', max_length=254)),
('w', models.CharField(blank=True, db_column='W', max_length=254)),
('x', models.CharField(blank=True, db_column='X', max_length=254)),
('y', models.CharField(blank=True, db_column='Y', max_length=254)),
('z', models.CharField(blank=True, db_column='Z', max_length=254)),
('aa', models.CharField(blank=True, db_column='AA', max_length=254)),
('ab', models.CharField(blank=True, db_column='AB', max_length=254)),
('ac', models.CharField(blank=True, db_column='AC', max_length=254)),
('ad', models.CharField(blank=True, db_column='AD', max_length=254)),
('ae', models.CharField(blank=True, db_column='AE', max_length=254)),
('af', models.CharField(blank=True, db_column='AF', max_length=254)),
('ag', models.CharField(blank=True, db_column='AG', max_length=254)),
('ah', models.CharField(blank=True, db_column='AH', max_length=254)),
('ai', models.CharField(blank=True, db_column='AI', max_length=254)),
('aj', models.CharField(blank=True, db_column='AJ', max_length=254)),
('ak', models.CharField(blank=True, db_column='AK', max_length=254)),
('al', models.CharField(blank=True, db_column='AL', max_length=254)),
('am', models.CharField(blank=True, db_column='AM', max_length=254)),
('an', models.CharField(blank=True, db_column='AN', max_length=254)),
('ao', models.CharField(blank=True, db_column='AO', max_length=254)),
('ap', models.CharField(blank=True, db_column='AP', max_length=254)),
('aq', models.CharField(blank=True, db_column='AQ', max_length=254)),
('ar', models.CharField(blank=True, db_column='AR', max_length=254)),
('as_field', models.CharField(blank=True, db_column='AS', max_length=254)),
('at', models.CharField(blank=True, db_column='AT', max_length=254)),
('au', models.CharField(blank=True, db_column='AU', max_length=254)),
('av', models.CharField(blank=True, db_column='AV', max_length=254)),
('aw', models.CharField(blank=True, db_column='AW', max_length=254)),
('ax', models.CharField(blank=True, db_column='AX', max_length=254)),
('ay', models.CharField(blank=True, db_column='AY', max_length=254)),
('az', models.CharField(blank=True, db_column='AZ', max_length=254)),
('ba', models.CharField(blank=True, db_column='BA', max_length=254)),
('bb', models.CharField(blank=True, db_column='BB', max_length=254)),
('bc', models.CharField(blank=True, db_column='BC', max_length=254)),
('bd', models.CharField(blank=True, db_column='BD', max_length=254)),
('be', models.CharField(blank=True, db_column='BE', max_length=254)),
('bf', models.CharField(blank=True, db_column='BF', max_length=254)),
('bg', models.CharField(blank=True, db_column='BG', max_length=254)),
('bh', models.CharField(blank=True, db_column='BH', max_length=254)),
('bi', models.CharField(blank=True, db_column='BI', max_length=254)),
('bj', models.CharField(blank=True, db_column='BJ', max_length=254)),
('bk', models.CharField(blank=True, db_column='BK', max_length=254)),
('bl', models.CharField(blank=True, db_column='BL', max_length=254)),
('bm', models.CharField(blank=True, db_column='BM', max_length=254)),
('bn', models.CharField(blank=True, db_column='BN', max_length=254)),
('bo', models.CharField(blank=True, db_column='BO', max_length=254)),
('bp', models.CharField(blank=True, db_column='BP', max_length=254)),
('bq', models.CharField(blank=True, db_column='BQ', max_length=254)),
('br', models.CharField(blank=True, db_column='BR', max_length=254)),
('bs', models.CharField(blank=True, db_column='BS', max_length=254)),
('bt', models.CharField(blank=True, db_column='BT', max_length=254)),
('bu', models.CharField(blank=True, db_column='BU', max_length=254)),
('bv', models.CharField(blank=True, db_column='BV', max_length=254)),
('bw', models.CharField(blank=True, db_column='BW', max_length=254)),
('bx', models.CharField(blank=True, db_column='BX', max_length=254)),
('by', models.CharField(blank=True, db_column='BY', max_length=254)),
('bz', models.CharField(blank=True, db_column='BZ', max_length=254)),
('ca', models.CharField(blank=True, db_column='CA', max_length=254)),
('cb', models.CharField(blank=True, db_column='CB', max_length=254)),
('cc', models.CharField(blank=True, db_column='CC', max_length=254)),
('cd', models.CharField(blank=True, db_column='CD', max_length=254)),
('ce', models.CharField(blank=True, db_column='CE', max_length=254)),
('a', models.DateTimeField(auto_now=True)),
('b', models.CharField(blank=True, max_length=254)),
('c', models.CharField(blank=True, max_length=254)),
('d', models.CharField(blank=True, max_length=254)),
('e', models.CharField(blank=True, max_length=254)),
('f', models.CharField(blank=True, max_length=254)),
('g', models.CharField(blank=True, max_length=254)),
('h', models.CharField(blank=True, max_length=254)),
('i', models.CharField(blank=True, max_length=254)),
('j', models.CharField(blank=True, max_length=254)),
('k', models.CharField(blank=True, max_length=254)),
('l', models.CharField(blank=True, max_length=254)),
('m', models.CharField(blank=True, max_length=254)),
('n', models.CharField(blank=True, max_length=254)),
('o', models.CharField(blank=True, max_length=254)),
('p', models.CharField(blank=True, max_length=254)),
('q', models.CharField(blank=True, max_length=254)),
('r', models.CharField(blank=True, max_length=254)),
('s', models.CharField(blank=True, max_length=254)),
('t', models.CharField(blank=True, max_length=254)),
('u', models.CharField(blank=True, max_length=254)),
('v', models.CharField(blank=True, max_length=254)),
('w', models.CharField(blank=True, max_length=254)),
('x', models.CharField(blank=True, max_length=254)),
('y', models.CharField(blank=True, max_length=254)),
('z', models.CharField(blank=True, max_length=254)),
('aa', models.CharField(blank=True, max_length=254)),
('ab', models.CharField(blank=True, max_length=254)),
('ac', models.CharField(blank=True, max_length=254)),
('ad', models.CharField(blank=True, max_length=254)),
('ae', models.CharField(blank=True, max_length=254)),
('af', models.CharField(blank=True, max_length=254)),
('ag', models.CharField(blank=True, max_length=254)),
('ah', models.CharField(blank=True, max_length=254)),
('ai', models.CharField(blank=True, max_length=254)),
('aj', models.CharField(blank=True, max_length=254)),
('ak', models.CharField(blank=True, max_length=254)),
('al', models.CharField(blank=True, max_length=254)),
('am', models.CharField(blank=True, max_length=254)),
('an', models.CharField(blank=True, max_length=254)),
('ao', models.CharField(blank=True, max_length=254)),
('ap', models.CharField(blank=True, max_length=254)),
('aq', models.CharField(blank=True, max_length=254)),
('ar', models.CharField(blank=True, max_length=254)),
('as_field', models.CharField(blank=True, max_length=254)),
('at', models.CharField(blank=True, max_length=254)),
('au', models.CharField(blank=True, max_length=254)),
('av', models.CharField(blank=True, max_length=254)),
('aw', models.CharField(blank=True, max_length=254)),
('ax', models.CharField(blank=True, max_length=254)),
('ay', models.CharField(blank=True, max_length=254)),
('az', models.CharField(blank=True, max_length=254)),
('ba', models.CharField(blank=True, max_length=254)),
('bb', models.CharField(blank=True, max_length=254)),
('bc', models.CharField(blank=True, max_length=254)),
('bd', models.CharField(blank=True, max_length=254)),
('be', models.CharField(blank=True, max_length=254)),
('bf', models.CharField(blank=True, max_length=254)),
('bg', models.CharField(blank=True, max_length=254)),
('bh', models.CharField(blank=True, max_length=254)),
('bi', models.CharField(blank=True, max_length=254)),
('bj', models.CharField(blank=True, max_length=254)),
('bk', models.CharField(blank=True, max_length=254)),
('bl', models.CharField(blank=True, max_length=254)),
('bm', models.CharField(blank=True, max_length=254)),
('bn', models.CharField(blank=True, max_length=254)),
('bo', models.CharField(blank=True, max_length=254)),
('bp', models.CharField(blank=True, max_length=254)),
('bq', models.CharField(blank=True, max_length=254)),
('br', models.CharField(blank=True, max_length=254)),
('bs', models.CharField(blank=True, max_length=254)),
('bt', models.CharField(blank=True, max_length=254)),
('bu', models.CharField(blank=True, max_length=254)),
('bv', models.CharField(blank=True, max_length=254)),
('bw', models.CharField(blank=True, max_length=254)),
('bx', models.CharField(blank=True, max_length=254)),
('by', models.CharField(blank=True, max_length=254)),
('bz', models.CharField(blank=True, max_length=254)),
('ca', models.CharField(blank=True, max_length=254)),
('cb', models.CharField(blank=True, max_length=254)),
('cc', models.CharField(blank=True, max_length=254)),
('cd', models.CharField(blank=True, max_length=254)),
('ce', models.CharField(blank=True, max_length=254)),
],
options={
'db_table': 'surveys_ecosystem2020',
Expand Down
18 changes: 18 additions & 0 deletions surveys/migrations/0002_auto_20200508_0056.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 3.0.3 on 2020-05-08 00:56

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('surveys', '0001_initial'),
]

operations = [
migrations.AlterField(
model_name='ecosystem2020',
name='bg',
field=models.TextField(blank=True),
),
]
Loading

0 comments on commit 17ec31a

Please sign in to comment.