Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

address all acceptance criteria #6930

Merged
merged 1 commit into from
Jun 24, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions network-api/networkapi/wagtailpages/fields.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,39 @@
from django.db import models


class ExtendedBoolean(models.CharField):
"""
TODO: unify this with the ExtendedYesNoField below. Because this would
introduce a superclass hierarchy change, and Django is notoriously
bad at those, this is a separate task.

See https://github.com/mozilla/foundation.mozilla.org/issues/6929
"""

description = "Yes, No, Unknown"

choice_list = [
('Yes', 'Yes'),
('No', 'No'),
('U', 'Unknown'),
]

default_choice = 'U'

def __init__(self, *args, **kwargs):
kwargs['choices'] = self.choice_list
kwargs['default'] = self.default_choice
kwargs['max_length'] = 3
super().__init__(*args, **kwargs)

def deconstruct(self):
name, path, args, kwargs = super().deconstruct()
del kwargs['choices']
del kwargs['default']
del kwargs['max_length']
return name, path, args, kwargs


class ExtendedYesNoField(models.CharField):
description = "Yes, No, Not Applicable, or Can’t Determine"

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
# Generated by Django 3.1.11 on 2021-06-23 21:40

from django.db import migrations
import networkapi.wagtailpages.fields


def update_software_product_fields(apps, schema_editor):
SoftwareProductPage = apps.get_model("wagtailpages", "SoftwareProductPage")

# ExtendedBoolean is char(3), so the original boolean
# values True/False become the string values 'tru'/'fal'.

for product in SoftwareProductPage.objects.all():
if product.easy_to_learn_and_use == 'tru':
product.easy_to_learn_and_use = 'Yes'

if product.easy_to_learn_and_use == 'fal':
product.easy_to_learn_and_use = 'No'

if product.easy_to_learn_and_use == None:
product.easy_to_learn_and_use = 'U'

if product.medical_privacy_compliant == 'tru':
product.medical_privacy_compliant = 'Yes'

if product.medical_privacy_compliant == 'fal':
product.medical_privacy_compliant = 'No'

if product.medical_privacy_compliant == None:
product.medical_privacy_compliant = 'U'

product.save()


class Migration(migrations.Migration):

dependencies = [
('wagtailpages', '0018_translation_mixin_migration_for_cta_models'),
]

operations = [
migrations.AlterField(
model_name='softwareproductpage',
name='easy_to_learn_and_use',
field=networkapi.wagtailpages.fields.ExtendedBoolean(help_text='Is it easy to learn & use the features?', null=True, default='U'),
),
migrations.AlterField(
model_name='softwareproductpage',
name='medical_privacy_compliant',
field=networkapi.wagtailpages.fields.ExtendedBoolean(help_text='Compliant with US medical privacy laws?', null=True, default='U'),
),
migrations.RunPython(
code=update_software_product_fields
),
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Generated by Django 3.1.11 on 2021-06-23 22:05

from django.db import migrations
import networkapi.wagtailpages.fields


class Migration(migrations.Migration):

dependencies = [
('wagtailpages', '0019_fix_software_fields_part_1'),
]

operations = [
migrations.AlterField(
model_name='softwareproductpage',
name='easy_to_learn_and_use',
field=networkapi.wagtailpages.fields.ExtendedBoolean(help_text='Is it easy to learn & use the features?'),
),
migrations.AlterField(
model_name='softwareproductpage',
name='medical_privacy_compliant',
field=networkapi.wagtailpages.fields.ExtendedBoolean(help_text='Compliant with US medical privacy laws?'),
),
]
16 changes: 5 additions & 11 deletions network-api/networkapi/wagtailpages/pagemodels/products.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@

from wagtail_airtable.mixins import AirtableMixin

from networkapi.wagtailpages.fields import ExtendedYesNoField
from networkapi.wagtailpages.fields import ExtendedBoolean, ExtendedYesNoField
from networkapi.wagtailpages.pagemodels.mixin.foundation_metadata import (
FoundationMetadataPageMixin
)
Expand Down Expand Up @@ -898,11 +898,8 @@ class SoftwareProductPage(ProductPage):
max_length=5000,
blank=True
)
# NullBooleanField is deprecated as of Django 3.1.
# We're using it here primarily for a data migration, but we should
# move to BooleanField as soon as it's safe to do so with the content we have
medical_privacy_compliant = models.BooleanField(
null=True,

medical_privacy_compliant = ExtendedBoolean(
help_text='Compliant with US medical privacy laws?'
)

Expand All @@ -917,11 +914,8 @@ class SoftwareProductPage(ProductPage):
max_length=5000,
blank=True
)
# NullBooleanField is deprecated as of Django 3.1.
# We're using it here primarily for a data migration, but we should
# move to BooleanField as soon as it's safe to do so with the content we have
easy_to_learn_and_use = models.BooleanField(
null=True,

easy_to_learn_and_use = ExtendedBoolean(
help_text='Is it easy to learn & use the features?',
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@
{% include "./product_criterion.html" with label=handles_recordings_how value=product.handles_recordings_how %}
{% endif %}

{% include "./product_criterion.html" with label=recording_alert value=product.recording_alert|extended_yes_no help=product.recording_alert_helptext %}
{% include "./product_criterion.html" with label=medical_privacy_compliant value=product.medical_privacy_compliant|yes_no help=product.medical_privacy_compliant_helptext %}
{% include "./product_criterion.html" with label=recording_alert value=product.recording_alert|extended_yes_no help=product.recording_alert_helptext %}
{% include "./product_criterion.html" with label=medical_privacy_compliant value=product.medical_privacy_compliant|extended_boolean help=product.medical_privacy_compliant_helptext %}
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,22 @@ def yes_no(value):
"""Converts nullish boolean to yes or no string"""
if value is False:
return gettext('No')

if value is True:
return gettext('Yes')

return gettext('Unknown')


@register.filter
def extended_boolean(value):
if value == 'Yes':
return gettext('Yes')
if value == 'No':
return gettext('No')
if value == 'U':
return gettext('Unknown')
return value


@register.filter
def extended_yes_no(value):
"""Converts quad-state to human readable string"""
Expand Down