From 4a7538be76d9f5ad5d6593f2dd2da3ad5b6517c8 Mon Sep 17 00:00:00 2001 From: sbsimo Date: Thu, 26 Oct 2017 12:33:59 +0200 Subject: [PATCH] if quantity is null, category count is the only aggregation possible --> form controls --- .../migrations/0003_auto_20171026_0528.py | 24 +++++++++++++++++++ charts_app/models.py | 6 ++--- haitidata/templates/layers/layer_detail.html | 7 ++++++ 3 files changed, 34 insertions(+), 3 deletions(-) create mode 100644 charts_app/migrations/0003_auto_20171026_0528.py diff --git a/charts_app/migrations/0003_auto_20171026_0528.py b/charts_app/migrations/0003_auto_20171026_0528.py new file mode 100644 index 0000000..e8bfa6c --- /dev/null +++ b/charts_app/migrations/0003_auto_20171026_0528.py @@ -0,0 +1,24 @@ +# -*- coding: utf-8 -*- +from __future__ import unicode_literals + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('charts_app', '0002_auto_20170705_0742'), + ] + + operations = [ + migrations.AlterField( + model_name='chart', + name='quantity', + field=models.CharField(max_length=200, blank=True), + ), + migrations.AlterField( + model_name='chart', + name='title', + field=models.CharField(max_length=128), + ), + ] diff --git a/charts_app/models.py b/charts_app/models.py index 0551e5f..5ebb4c2 100644 --- a/charts_app/models.py +++ b/charts_app/models.py @@ -45,7 +45,7 @@ class Chart(models.Model): layer = models.ForeignKey(Layer, validators=[validate_wfs]) title = models.CharField(max_length=128, blank=False) category = models.CharField(max_length=200) - quantity = models.CharField(max_length=200) + quantity = models.CharField(max_length=200, blank=True) type = models.SmallIntegerField(choices=CHART_TYPES, default=0) aggr_type = models.SmallIntegerField(choices=AGGREGATION_TYPES, default=3) abstract = models.TextField(blank=True) @@ -60,7 +60,7 @@ class ChartForm(ModelForm): layer = cleaned_data.get('layer') category = cleaned_data.get('category') quantity = cleaned_data.get('quantity') - + aggr_type = cleaned_data.get('aggr_type') categories, quantities = get_fields(layer) if category not in categories: @@ -69,7 +69,7 @@ class ChartForm(ModelForm): code='non_extant_category_field', params={'lyr_title': lyr.title, 'category': category}) - if quantity not in quantities: + if quantity not in quantities and aggr_type != 2: lyr = Layer.objects.get(pk=layer) raise VE(_('%(lyr_title)s does not contain the field %(quantity)s'), code='non_extant_quantity_field', diff --git a/haitidata/templates/layers/layer_detail.html b/haitidata/templates/layers/layer_detail.html index b88cbb1..ea300b7 100644 --- a/haitidata/templates/layers/layer_detail.html +++ b/haitidata/templates/layers/layer_detail.html @@ -668,7 +668,14 @@ } } + function check_quantity(){ + if (document.f.quantity.value == ''){ + document.f.aggr_type.value = 2; + } + } + function updateLinkAndTitle(){ + check_quantity(); update_link(); chart_title(); attachAbstract();