diff --git a/opentech/public/people/migrations/0007_allow_blank_source.py b/opentech/public/people/migrations/0007_allow_blank_source.py new file mode 100644 index 0000000000000000000000000000000000000000..a7491a136e043caf004d4a038712f752eda1f2b9 --- /dev/null +++ b/opentech/public/people/migrations/0007_allow_blank_source.py @@ -0,0 +1,19 @@ +# Generated by Django 2.0.2 on 2018-08-29 14:27 + +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + dependencies = [ + ('people', '0006_fundreviewers'), + ] + + operations = [ + migrations.AlterField( + model_name='funding', + name='source', + field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.PROTECT, to='wagtailcore.Page'), + ), + ] diff --git a/opentech/public/projects/management/commands/migrate_projects.py b/opentech/public/projects/management/commands/migrate_projects.py index 5ebf9425a6d9baa74fd325207ffd770ca211c6eb..1b446bbba01b3b3b747ebe8ccb8a4842403023fb 100644 --- a/opentech/public/projects/management/commands/migrate_projects.py +++ b/opentech/public/projects/management/commands/migrate_projects.py @@ -1,4 +1,5 @@ import argparse +import itertools import json import mimetypes @@ -172,12 +173,28 @@ class Command(BaseCommand): amounts = self.ensure_iterable(node['field_project_funding_amount']) durations = self.ensure_iterable(node['field_project_term_time']) funds = self.ensure_iterable(node['field_project_funding_request']) - for year, amount, duration, fund in zip(years, amounts, durations, funds): + for year, amount, duration, fund in itertools.zip_longest(years, amounts, durations, funds): + try: + fund = self.funds[fund['target_id']] + except TypeError: + fund = None + + try: + duration = duration['value'] + except TypeError: + duration = 0 + + try: + amount = amount['value'] + except TypeError: + # This is an error, don't give funding + continue + project.funding.add(ProjectFunding( - value=amount['value'], + value=amount, year=year['value'], - duration=duration['value'], - source=self.funds[fund['target_id']], + duration=duration, + source=fund, )) try: @@ -201,7 +218,7 @@ class Command(BaseCommand): pass try: return node[field]['value'] - except TypeError : + except TypeError: return '' def get_referenced_term(self, tid): diff --git a/opentech/public/projects/migrations/0006_allow_blank_source.py b/opentech/public/projects/migrations/0006_allow_blank_source.py new file mode 100644 index 0000000000000000000000000000000000000000..ac212e9577f4f13e55454fb01c17e87da57d5041 --- /dev/null +++ b/opentech/public/projects/migrations/0006_allow_blank_source.py @@ -0,0 +1,19 @@ +# Generated by Django 2.0.2 on 2018-08-29 14:27 + +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + dependencies = [ + ('projects', '0005_projectpage_drupal_id'), + ] + + operations = [ + migrations.AlterField( + model_name='projectfunding', + name='source', + field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.PROTECT, to='wagtailcore.Page'), + ), + ] diff --git a/opentech/public/utils/models.py b/opentech/public/utils/models.py index 2c7fbb01c6f615a7bc3a822e9c68ec3f4d3018da..559a4e7dde1061cfd10b60da1be88f3dc12503ea 100644 --- a/opentech/public/utils/models.py +++ b/opentech/public/utils/models.py @@ -270,6 +270,8 @@ class BaseFunding(Orderable): source = models.ForeignKey( 'wagtailcore.Page', on_delete=models.PROTECT, + null=True, + blank=True, ) panels = [ diff --git a/opentech/public/utils/templates/utils/includes/funding.html b/opentech/public/utils/templates/utils/includes/funding.html index c75d5f550fd96a9c39dc28bfe771fbab1b7d05d3..b6b13d1240119be251fca59d52830c772582b8a3 100644 --- a/opentech/public/utils/templates/utils/includes/funding.html +++ b/opentech/public/utils/templates/utils/includes/funding.html @@ -1,15 +1,19 @@ -{% load wagtailcore_tags %} +{% load wagtailcore_tags humanize %} {% if page.total_funding %} <div class="fund-box {% if class %}{{class}}{% endif %}"> <h4>Funding to date</h4> {% for funding in page.funding.all %} <div class="fund-box__row"> <span>{{ funding.year }}</span> - <span>${{ funding.value }}</span> - <span>{{ funding.duration }} months</span> + <span>${{ funding.value|intcomma }}</span> + {% if funding.duration %} + <span>{{ funding.duration }} months</span> + {% endif %} </div> + {% if funding.source %} <a class="fund-box__link" href="{% pageurl funding.source %}">{{ funding.source }}</a> + {% endif %} {% endfor %} - <h4 class="heading heading--top-space heading--total-funding">Total Funding: <span>${{ page.total_funding }}</span></h4> + <h4 class="heading heading--top-space heading--total-funding">Total Funding: <span>${{ page.total_funding|intcomma }}</span></h4> </div> {% endif %} diff --git a/opentech/settings/base.py b/opentech/settings/base.py index cf6683fef1085d722296400d5522daf37fb4328b..fb9ed8313120d5c0b2f0defadf9a2d5ea90891b2 100644 --- a/opentech/settings/base.py +++ b/opentech/settings/base.py @@ -121,6 +121,7 @@ INSTALLED_APPS = [ 'django.contrib.admin', 'django.contrib.auth', 'django.contrib.contenttypes', + 'django.contrib.humanize', 'django.contrib.sessions', 'django.contrib.messages', 'django.contrib.postgres',