From 7c7ebd0f9bc13f307a2bcc4c005dcb17a3689f08 Mon Sep 17 00:00:00 2001 From: nathanbegbie Date: Tue, 7 Nov 2017 13:42:50 +0200 Subject: [PATCH 1/3] remove reference to non-existent wagtail personalisation migration --- molo/surveys/migrations/0018_add_combination_rule.py | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/molo/surveys/migrations/0018_add_combination_rule.py b/molo/surveys/migrations/0018_add_combination_rule.py index 3c32a50..1619e67 100644 --- a/molo/surveys/migrations/0018_add_combination_rule.py +++ b/molo/surveys/migrations/0018_add_combination_rule.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Generated by Django 1.9.13 on 2017-11-07 07:01 +# Generated by Django 1.9.13 on 2017-11-07 09:55 from __future__ import unicode_literals from django.db import migrations, models @@ -13,7 +13,6 @@ class Migration(migrations.Migration): dependencies = [ - ('wagtail_personalisation', '0013_auto_20171026_1748'), ('surveys', '0017_make_count_positive_integer'), ] @@ -29,9 +28,4 @@ class Migration(migrations.Migration): 'verbose_name': 'Rule Combination', }, ), - migrations.AlterField( - model_name='articletagrule', - name='date_to', - field=models.DateTimeField(blank=True, help_text='All times are UTC. Leave both fields blank to search all time.', null=True), - ), ] From c6c7121c62f8c9d3928285cfa8647cb661f895d1 Mon Sep 17 00:00:00 2001 From: nathanbegbie Date: Tue, 7 Nov 2017 14:51:48 +0200 Subject: [PATCH 2/3] Fix validation for Combination Rule fields --- molo/surveys/rules.py | 49 ++++++++++++++++++++++++------------------- 1 file changed, 27 insertions(+), 22 deletions(-) diff --git a/molo/surveys/rules.py b/molo/surveys/rules.py index 108eeb7..a569afe 100644 --- a/molo/surveys/rules.py +++ b/molo/surveys/rules.py @@ -394,30 +394,35 @@ def description(self): def clean(self): super(CombinationRule, self).clean() - if isinstance(self.body.stream_data[0], dict): - newData = [block['type'] for block in self.body.stream_data] - elif isinstance(self.body.stream_data[0], tuple): - newData = [block[0] for block in self.body.stream_data] + if len(self.body.stream_data) > 0: + if isinstance(self.body.stream_data[0], dict): + newData = [block['type'] for block in self.body.stream_data] + elif isinstance(self.body.stream_data[0], tuple): + newData = [block[0] for block in self.body.stream_data] - if (len(newData) - 1) % 2 != 0: - raise StreamBlockValidationError(non_block_errors=[_( - 'Rule Combination must follow the ' - ' pattern.')]) - - iterations = (len(newData) - 1) / 2 - for i in range(iterations): - first_rule_index = i * 2 - operator_index = (i * 2) + 1 - second_rule_index = (i * 2) + 2 - - if not ( - (newData[first_rule_index] == 'Rule' or - newData[first_rule_index] == 'NestedLogic') and - (newData[operator_index] == 'Operator') and - (newData[second_rule_index] == 'Rule' or - newData[second_rule_index] == 'NestedLogic')): + if len(newData) ==1 or (len(newData) - 1) % 2 != 0: raise StreamBlockValidationError(non_block_errors=[_( - 'Rule Combination must follow the ' + 'Rule Combination must follow the ' + ' pattern.')]) + + iterations = (len(newData) - 1) / 2 + for i in range(iterations): + first_rule_index = i * 2 + operator_index = (i * 2) + 1 + second_rule_index = (i * 2) + 2 + + if not ( + (newData[first_rule_index] == 'Rule' or + newData[first_rule_index] == 'NestedLogic') and + (newData[operator_index] == 'Operator') and + (newData[second_rule_index] == 'Rule' or + newData[second_rule_index] == 'NestedLogic')): + raise StreamBlockValidationError(non_block_errors=[_( + 'Rule Combination must follow the ' + ' pattern.')]) + else: + raise StreamBlockValidationError(non_block_errors=[_( + 'Rule Combination must follow the ' ' pattern.')]) class Meta: From dd6f272700b5cbf1612c9b646744ee554fb925fd Mon Sep 17 00:00:00 2001 From: nathanbegbie Date: Tue, 7 Nov 2017 15:02:13 +0200 Subject: [PATCH 3/3] Fix flake8 errors --- molo/surveys/rules.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/molo/surveys/rules.py b/molo/surveys/rules.py index a569afe..aa1209c 100644 --- a/molo/surveys/rules.py +++ b/molo/surveys/rules.py @@ -400,7 +400,7 @@ def clean(self): elif isinstance(self.body.stream_data[0], tuple): newData = [block[0] for block in self.body.stream_data] - if len(newData) ==1 or (len(newData) - 1) % 2 != 0: + if len(newData) == 1 or (len(newData) - 1) % 2 != 0: raise StreamBlockValidationError(non_block_errors=[_( 'Rule Combination must follow the ' ' pattern.')]) @@ -413,7 +413,7 @@ def clean(self): if not ( (newData[first_rule_index] == 'Rule' or - newData[first_rule_index] == 'NestedLogic') and + newData[first_rule_index] == 'NestedLogic') and (newData[operator_index] == 'Operator') and (newData[second_rule_index] == 'Rule' or newData[second_rule_index] == 'NestedLogic')): @@ -422,8 +422,8 @@ def clean(self): ' pattern.')]) else: raise StreamBlockValidationError(non_block_errors=[_( - 'Rule Combination must follow the ' - ' pattern.')]) + 'Rule Combination must follow the ' + ' pattern.')]) class Meta: verbose_name = _('Rule Combination')