-
Notifications
You must be signed in to change notification settings - Fork 153
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Richtext product page fields (#7754)
* updated some fields to rich text, and updated criterion files to reflect richtext * migrations * Update product_criterion.html * updated css * updated css * Update product_criterion.html * updated classnames and updated css for only p elements. * updated factory for products to use rich text, and also added migration to update existing fields with content * updated defaults for tests and percy * Update product.scss * Updated AI helptext for richtext * Update buyersguide.py * Update buyersguide.py * Update 0049_pni_criterion_richtext_fields.py * implemented review feedback * updated two more fields * user can control section was missing helptext Co-authored-by: Daniel Miranda <daniel@mozillafoundation.org>
- Loading branch information
1 parent
3c04321
commit b4d04d1
Showing
9 changed files
with
207 additions
and
64 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
network-api/networkapi/wagtailpages/migrations/0051_auto_20211028_0220.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
# Generated by Django 3.1.11 on 2021-10-28 02:20 | ||
|
||
from django.db import migrations | ||
import wagtail.core.fields | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('wagtailpages', '0050_auto_20211104_2126'), | ||
] | ||
|
||
operations = [ | ||
migrations.AlterField( | ||
model_name='generalproductpage', | ||
name='ai_helptext', | ||
field=wagtail.core.fields.RichTextField(blank=True, help_text='Helpful text around AI to show on the product page', max_length=5000), | ||
), | ||
migrations.AlterField( | ||
model_name='generalproductpage', | ||
name='how_can_you_control_your_data', | ||
field=wagtail.core.fields.RichTextField(blank=True, help_text='How does this product let you control your data?', max_length=5000), | ||
), | ||
migrations.AlterField( | ||
model_name='generalproductpage', | ||
name='offline_use_description', | ||
field=wagtail.core.fields.RichTextField(blank=True, help_text='Describe how this product can be used offline.', max_length=5000), | ||
), | ||
migrations.AlterField( | ||
model_name='generalproductpage', | ||
name='track_record_details', | ||
field=wagtail.core.fields.RichTextField(blank=True, help_text='Describe the track record of this company here.', max_length=5000), | ||
), | ||
migrations.AlterField( | ||
model_name='productpage', | ||
name='how_does_it_use_data_collected', | ||
field=wagtail.core.fields.RichTextField(blank=True, help_text='How does this product use the data collected?', max_length=5000), | ||
), | ||
migrations.AlterField( | ||
model_name='productpage', | ||
name='manage_vulnerabilities_helptext', | ||
field=wagtail.core.fields.RichTextField(blank=True, max_length=5000), | ||
), | ||
] |
73 changes: 73 additions & 0 deletions
73
network-api/networkapi/wagtailpages/migrations/0052_pni_criterion_richtext_fields.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
# This file is made to loop through all existing PNI products and update the following fields to richtext: | ||
# - Track record description | ||
# - How does the company use this data? | ||
# - How can you control your data? | ||
# - General AI description | ||
# - Manages security vulnerabilities Description | ||
|
||
from django.db import migrations | ||
from networkapi.wagtailpages.utils import get_default_locale | ||
|
||
|
||
# Forward migration content handler | ||
def update_fields_to_rich_text(product_qs): | ||
|
||
for product in product_qs: | ||
|
||
# If the page has no fields that need updating, do not save. This will speed up the process. | ||
needs_saving = False | ||
|
||
if hasattr(product, 'how_does_it_use_data_collected') and product.how_does_it_use_data_collected != "": | ||
product.how_does_it_use_data_collected = f"<p> {product.how_does_it_use_data_collected} </p>" | ||
needs_saving = True | ||
|
||
elif hasattr(product, 'manage_vulnerabilities_helptext') and product.manage_vulnerabilities_helptext != "": | ||
product.manage_vulnerabilities_helptext = f"<p> {product.manage_vulnerabilities_helptext} </p>" | ||
needs_saving = True | ||
|
||
elif hasattr(product, 'track_record_details') and product.track_record_details != "": | ||
product.track_record_details = f"<p> {product.track_record_details} </p>" | ||
needs_saving = True | ||
|
||
elif hasattr(product, 'offline_use_description') and product.offline_use_description != "": | ||
product.offline_use_description = f"<p> {product.offline_use_description} </p>" | ||
needs_saving = True | ||
|
||
elif hasattr(product, 'ai_helptext') and product.ai_helptext != "": | ||
product.ai_helptext = f"<p> {product.ai_helptext} </p>" | ||
needs_saving = True | ||
|
||
if needs_saving: | ||
product.save() | ||
print(f"Saved product: {product.title}") | ||
|
||
|
||
|
||
|
||
def gather_products_and_update_fields(apps, schema): | ||
GeneralProductPage = apps.get_model('wagtailpages', 'GeneralProductPage') | ||
SoftwareProductPage = apps.get_model('wagtailpages', 'SoftwareProductPage') | ||
|
||
(DEFAULT_LOCALE, DEFAULT_LOCALE_ID) = get_default_locale() | ||
|
||
product_pages = [ | ||
GeneralProductPage.objects.filter(locale_id=DEFAULT_LOCALE_ID), | ||
SoftwareProductPage.objects.filter(locale_id=DEFAULT_LOCALE_ID) | ||
] | ||
|
||
for product_set in product_pages: | ||
update_fields_to_rich_text(product_set) | ||
|
||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('wagtailpages', '0051_auto_20211028_0220'), | ||
] | ||
|
||
operations = [ | ||
migrations.RunPython( | ||
code=gather_products_and_update_fields | ||
) | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 7 additions & 3 deletions
10
network-api/networkapi/wagtailpages/templates/fragments/product_criterion.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,15 @@ | ||
{% load i18n %} | ||
{% load i18n wagtailcore_tags %} | ||
|
||
{% if value != hide_value %} | ||
<section class="criterion value-{{value|lower}} {% if no_border %}no-border{% endif%} {% if ding %}show-ding{% endif %} {% if class %}{{class}}{% endif %}" {% if ding %}aria-label="{% trans "This section requires attention." %}"{% endif %}> | ||
{% include "./product_criterion_primary_info.html" with show_value_as_symbol=show_value_as_symbol label=label value=value info=info %} | ||
{% include "./product_criterion_primary_info.html" with show_value_as_symbol=show_value_as_symbol label=label value=value rich_text_value=rich_text_value %} | ||
|
||
{% if help != None and help != "" %} | ||
<p class="pni-product-helptext mb-0 mt-3">{{ help }}</p> | ||
{% if rich_help_text %} | ||
<div class="criterion-richtext-help mb-0 mt-3">{{ help|richtext }}</div> | ||
{% else %} | ||
<p class="pni-product-helptext mb-0 mt-3">{{ help }}</p> | ||
{% endif %} | ||
{% endif %} | ||
</section> | ||
{% endif %} |
75 changes: 40 additions & 35 deletions
75
network-api/networkapi/wagtailpages/templates/fragments/product_criterion_primary_info.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,42 +1,47 @@ | ||
{% load i18n static %} | ||
{% load i18n static wagtailcore_tags %} | ||
|
||
<div class="primary-info"> | ||
<h3 class="tw-mb-4 tw-font-zilla tw-text-2xl tw-leading-7 tw-flex tw-items-center"> | ||
{{ label }} | ||
{% if info != None and info != "" %} | ||
<a href="{{info}}"> | ||
<img src="{% static "_images/buyers-guide/icon-info-circle.svg" %}" alt="{% trans "information" context "icon description for screen readers" %}" class="tw-h-4 tw-w-4 tw-ml-2 tw-mb-1"> | ||
</a> | ||
{% endif %} | ||
</h3> | ||
|
||
<p class="rating pni-product-smaller-body mb-0"> | ||
{% if value == "CD" %} | ||
{% if show_value_as_symbol %} | ||
<img src="{% static "_images/buyers-guide/score/icon-unknown.svg" %}" alt="{% trans "Can’t determine" context "Unknown rating" %}"> | ||
{% else %} | ||
{% trans "Can’t determine" context "Unknown rating" %} | ||
{% endif %} | ||
{% elif value == "NA" %} | ||
{% trans "Not applicable" %} | ||
{% elif value == "Yes" %} | ||
{% if show_value_as_symbol %} | ||
<img src="{% static "_images/buyers-guide/score/icon-yes.svg" %}" alt="{% trans "Yes" %}"> | ||
{% else %} | ||
{% trans "Yes" %} | ||
{% endif %} | ||
{% elif value == "No" %} | ||
{% if show_value_as_symbol %} | ||
<img src="{% static "_images/buyers-guide/score/icon-no.svg" %}" alt="{% trans "No" %}"> | ||
{% else %} | ||
{% trans "No" %} | ||
<h3 class="tw-mb-4 tw-font-zilla tw-text-2xl tw-leading-7 tw-flex tw-items-center"> | ||
{{ label }} | ||
{% if info != None and info != "" %} | ||
<a href="{{info}}"> | ||
<img src="{% static "_images/buyers-guide/icon-info-circle.svg" %}" alt="{% trans "information" context "icon description for screen readers" %}" class="tw-h-4 tw-w-4 tw-ml-2 tw-mb-1"> | ||
</a> | ||
{% endif %} | ||
</h3> | ||
{% if rich_text_value %} | ||
<div class="criterion-richtext-value mb-0"> | ||
{{ value|richtext }} | ||
</div> | ||
{% else %} | ||
{% if show_value_as_symbol %} | ||
<img src="{% get_static_prefix %}_images/buyers-guide/score/icon-{{value|lower}}.svg" alt="{{value}}"> | ||
<p class="rating pni-product-smaller-body mb-0"> | ||
{% if value == "Can’t Determine" or value == "CD"%} | ||
{% if show_value_as_symbol %} | ||
<img src="{% static "_images/buyers-guide/score/icon-unknown.svg" %}" alt="{% trans "Can’t determine" context "Unknown rating" %}"> | ||
{% else %} | ||
{% trans "Can’t Determine" context "Unknown rating" %} | ||
{% endif %} | ||
{% elif value == "NA" %} | ||
{% trans "Not Applicable" %} | ||
{% elif value == "Yes" %} | ||
{% if show_value_as_symbol %} | ||
<img src="{% static "_images/buyers-guide/score/icon-yes.svg" %}" alt="{% trans "Yes" %}"> | ||
{% else %} | ||
{% trans "Yes" %} | ||
{% endif %} | ||
{% elif value == "No" %} | ||
{% if show_value_as_symbol %} | ||
<img src="{% static "_images/buyers-guide/score/icon-no.svg" %}" alt="{% trans "No" %}"> | ||
{% else %} | ||
{% trans "No" %} | ||
{% endif %} | ||
{% else %} | ||
{{ value }} | ||
{% if show_value_as_symbol %} | ||
<img src="{% get_static_prefix %}_images/buyers-guide/score/icon-{{value|lower}}.svg" alt="{{value}}"> | ||
{% else %} | ||
{{ value }} | ||
{% endif %} | ||
{% endif %} | ||
{% endif %} | ||
</p> | ||
</p> | ||
{% endif %} | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters