Skip to content
This repository has been archived by the owner on Feb 13, 2022. It is now read-only.

Commit

Permalink
Merge f941d00 into 3d99f13
Browse files Browse the repository at this point in the history
  • Loading branch information
KaitCrawford committed Aug 29, 2018
2 parents 3d99f13 + f941d00 commit a79d5c8
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 1 deletion.
21 changes: 21 additions & 0 deletions molo/surveys/migrations/0029_auto_20180829_1139.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.11.15 on 2018-08-29 09:39
from __future__ import unicode_literals

from django.db import migrations
import molo.surveys.rules


class Migration(migrations.Migration):

dependencies = [
('surveys', '0028_update_help_text_on_field_choices'),
]

operations = [
migrations.AlterField(
model_name='surveysubmissiondatarule',
name='field_name',
field=molo.surveys.rules.FieldNameField(help_text="Field's label. For possible choices please input any text and save, so it will be displayed in the error messages below the field.", max_length=255, verbose_name='field name'),
),
]
8 changes: 7 additions & 1 deletion molo/surveys/rules.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,12 @@ def __ordered_subclasses__(cls):
AbstractBaseRule.__subclasses__ = classmethod(__ordered_subclasses__)


class FieldNameField(models.CharField):
def value_from_object(self, obj):
""" Returns the field label for rendering"""
return obj.get_expected_field().label


class SurveySubmissionDataRule(AbstractBaseRule):
static = True

Expand All @@ -66,7 +72,7 @@ class SurveySubmissionDataRule(AbstractBaseRule):
survey = models.ForeignKey('PersonalisableSurvey',
verbose_name=_('survey'),
on_delete=models.CASCADE)
field_name = models.CharField(
field_name = FieldNameField(
_('field name'), max_length=255,
help_text=_('Field\'s label. For possible choices '
'please input any text and save, '
Expand Down
24 changes: 24 additions & 0 deletions molo/surveys/tests/test_admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
PersonalisableSurvey,
PersonalisableSurveyFormField,
)
from molo.surveys.rules import SurveySubmissionDataRule
from ..forms import CHARACTER_COUNT_CHOICE_LIMIT
from wagtail_personalisation.models import Segment
from wagtail_personalisation.rules import UserIsLoggedInRule
Expand Down Expand Up @@ -309,3 +310,26 @@ def test_survey_index_view_displays_all_surveys(self):
response = self.client.get('/admin/surveys/')
self.assertContains(response, child_of_index_page.title)
self.assertContains(response, child_of_article_page.title)

def test_segment_submission_rule_edit_shows_field_label(self):
# create survey page
molo_survey_page, molo_survey_form_field = (
self.create_personalisable_molo_survey_page(
parent=self.section_index))
# create segment and rule
test_segment = Segment.objects.create(name="Test Segment")
rule = SurveySubmissionDataRule(
segment=test_segment,
survey=molo_survey_page, operator=SurveySubmissionDataRule.EQUALS,
expected_response='super random text',
field_name='question-1')
rule.save()
test_segment.save()

self.client.force_login(self.super_user)
response = self.client.get(
'/admin/wagtail_personalisation/segment/edit/%d/' %
test_segment.pk)

self.assertNotContains(response, rule.field_name)
self.assertContains(response, molo_survey_form_field.label)

0 comments on commit a79d5c8

Please sign in to comment.