diff --git a/opentech/apply/categories/blocks.py b/opentech/apply/categories/blocks.py index ecd61dc8c8151f7f7332db1bff15624c6fe2604e..b51e9e2651a1bd080a1dc29e63f96fe5a64bbccc 100644 --- a/opentech/apply/categories/blocks.py +++ b/opentech/apply/categories/blocks.py @@ -42,11 +42,11 @@ class CategoryQuestionBlock(FormFieldBlock): return forms.ChoiceField def use_defaults_from_category(self, kwargs, category): - map = {'field_label': 'label', 'help_text': 'help_text'} + category_fields = {'label': 'name', 'help_text': 'help_text'} - for field in ['field_label', 'help_text']: - if field not in kwargs: - kwargs[map[field]] = getattr(category, field) + for field in category_fields.keys(): + if not kwargs.get(field): + kwargs[field] = getattr(category, category_fields[field]) return kwargs diff --git a/opentech/apply/categories/models.py b/opentech/apply/categories/models.py index 525cb37f7313e92478acc32fcb8164f84f6ad3c6..8b223aa5cf2a474be9064e1110dc53977ceb245d 100644 --- a/opentech/apply/categories/models.py +++ b/opentech/apply/categories/models.py @@ -22,10 +22,6 @@ class Category(ClusterableModel): name = models.CharField(max_length=255) help_text = models.CharField(max_length=255, blank=True) - @property - def field_label(self): - return self.name - panels = [ FieldPanel('name'), InlinePanel('options', label='Options'), diff --git a/opentech/apply/categories/tests/test_blocks.py b/opentech/apply/categories/tests/test_blocks.py index 19c3aff8d4d1c593de5662bd0ea7d9f821f569e0..0e8db56139db755e4d0f0c4979bf98c4bc2ec10b 100644 --- a/opentech/apply/categories/tests/test_blocks.py +++ b/opentech/apply/categories/tests/test_blocks.py @@ -11,15 +11,26 @@ class TestCategoryQuestionBlock(TestCase): self.category = CategoryFactory() self.block = CategoryQuestionBlock() - def test_field_and_help_default(self): - block = self.block.to_python({ + def get_field(self, **kwargs): + data = { 'field_label': '', 'help_text': '', 'category': self.category.id, 'multi': False, - }) + } + data.update(kwargs) + + block = self.block.to_python(data) - field = self.block.get_field(block) + return self.block.get_field(block) + def test_field_and_help_default(self): + field = self.get_field(field_label='', help_text='') self.assertEqual(self.category.name, field.label) self.assertEqual(self.category.help_text, field.help_text) + + def test_supplied_field_and_help(self): + values = {'field_label': 'LABEL', 'help_text': 'HELP'} + field = self.get_field(**values) + self.assertEqual(values['field_label'], field.label) + self.assertEqual(values['help_text'], field.help_text)