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

[#1581] Made help texts configurable via CMS #752

Closed
wants to merge 2 commits into from
Closed
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Generated by Django 3.2.15 on 2023-08-09 10:12

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
("extensions", "0005_alter_commonextension_menu_icon"),
]

operations = [
migrations.AddField(
model_name="commonextension",
name="help_text",
field=models.TextField(
blank=True, help_text="Help text for the page", verbose_name="Help text"
),
),
]
30 changes: 30 additions & 0 deletions src/open_inwoner/cms/extensions/migrations/0007_help_texts.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# Generated by Django 3.2.15 on 2023-11-11 10:00

from django.db import migrations, models
from django.db.models import Q

from cms.models import Page


def set_help_texts(apps, schema_editor):
PageModel = apps.get_model("cms", "Page")

# pages = PageModel.objects.filter(
# Q(publisher_is_draft=False) and Q(commonextension__isnull=False)
# )

for page in Page.objects.all():
page.commonextension.help_text = "hello world"
setattr(page.commonextension, "help_text", "hello world")
page.save()


class Migration(migrations.Migration):

dependencies = [
("extensions", "0006_commonextension_help_text"),
]

operations = [
migrations.RunPython(set_help_texts, reverse_code=migrations.RunPython.noop)
]
5 changes: 5 additions & 0 deletions src/open_inwoner/cms/extensions/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@ class CommonExtension(PageExtension):
blank=True,
help_text=_("Icon in het menu"),
)
help_text = models.TextField(
_("Help text"),
blank=True,
help_text=_("Help text for the page"),
)

def __str__(self):
return str(self.get_page())
Expand Down
8 changes: 7 additions & 1 deletion src/open_inwoner/cms/tests/cms_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,19 @@
from open_inwoner.cms.extensions.models import CommonExtension


def create_homepage():
def create_homepage(extension_args: dict = None):
"""
helper to create an empty, published homepage
"""
p = api.create_page(
"Home", "cms/fullwidth.html", "nl", in_navigation=True, reverse_id="home"
)

# create common extension
if extension_args:
extension_args["extended_object"] = p
CommonExtension.objects.create(**extension_args)

p.set_as_homepage()

if not p.publish("nl"):
Expand Down
26 changes: 26 additions & 0 deletions src/open_inwoner/cms/tests/test_data_migrations.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
from open_inwoner.utils.tests.test_migrations import TestMigrations

from ..collaborate.cms_apps import CollaborateApphook
from .cms_tools import create_apphook_page


class HelpTextMigrationTest(TestMigrations):
app = "extensions"
migrate_from = "0006_commonextension_help_text"
migrate_to = "0007_help_texts"

def setUpBeforeMigration(self, apps):
create_apphook_page(
CollaborateApphook,
extension_args={
"help_text": "",
},
)
self.PageModel = apps.get_model("cms", "Page")

def test_help_text(self):
pages = self.PageModel.objects.filter(publisher_is_draft=False)

import pdb

pdb.set_trace()
83 changes: 83 additions & 0 deletions src/open_inwoner/cms/tests/test_page_options.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
from unittest.mock import patch

from django.test import TestCase, override_settings
from django.urls import reverse

from django_webtest import WebTest
from pyquery import PyQuery

from open_inwoner.accounts.tests.factories import UserFactory
from open_inwoner.ssd.cms_apps import SSDApphook

from ..cases.cms_apps import CasesApphook
from ..collaborate.cms_apps import CollaborateApphook
from ..inbox.cms_apps import InboxApphook
from ..products.cms_apps import ProductsApphook
from ..profile.cms_apps import ProfileApphook
from ..tests import cms_tools


@override_settings(ROOT_URLCONF="open_inwoner.cms.tests.urls")
class TestCMSHelpText(TestCase):
"""
Test cases for CMS page-specific help texts

See /open_inwoner/configurations/tests/test_help_modal.py for
global help texts defined via SiteConfiguration.
"""

def setUp(self):
self.user = UserFactory()
self.user.set_password("12345")
self.user.email = "[email protected]"
self.user.save()

@patch("open_inwoner.configurations.models.SiteConfiguration.get_solo")
def test_home_page_help_text(self, mock_solo):
mock_solo.return_value.cookiebanner_enabled = False

cms_tools.create_homepage(
extension_args={
"help_text": "Help! I need somebody. Help!",
},
)

url = reverse("pages-root")
self.client.login(email=self.user.email, password="12345")
response = self.client.get(url)

doc = PyQuery(response.content.decode("utf-8"))

modal = doc.find(".help-modal")[0]
self.assertEqual(modal.attrib["data-help-text"], "Help! I need somebody. Help!")

@patch("open_inwoner.configurations.models.SiteConfiguration.get_solo")
def test_apphook_page_help_text(self, mock_solo):
mock_solo.return_value.cookiebanner_enabled = False

test_cases = [
(CollaborateApphook, "collaborate:plan_list"),
(InboxApphook, "inbox:index"),
(ProductsApphook, "products:category_list"),
(ProfileApphook, "profile:detail"),
(SSDApphook, "ssd:uitkeringen"),
]
for i, (cms_apphook, url_name) in enumerate(test_cases):
with self.subTest(f"Test help text for {cms_apphook} page"):
cms_tools.create_apphook_page(
cms_apphook,
extension_args={
"help_text": "Help! I need somebody. Help!",
},
)

url = reverse(url_name)
self.client.login(email=self.user.email, password="12345")
response = self.client.get(url)

doc = PyQuery(response.content.decode("utf-8"))

modal = doc.find(".help-modal")[0]
self.assertEqual(
modal.attrib["data-help-text"], "Help! I need somebody. Help!"
)
31 changes: 29 additions & 2 deletions src/open_inwoner/components/templatetags/header_tags.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
from django import template
from django.db.models import Q

from cms.models import Page

from open_inwoner.configurations.models import SiteConfiguration

Expand All @@ -19,6 +22,30 @@ def accessibility_header(request, **kwargs):
Extra context:
- help_text: str | The help text depending on the current path.
"""
config = SiteConfiguration.get_solo()
kwargs["help_text"] = config.get_help_text(request)

# help texts for cms pages with extension
cms_pages = Page.objects.filter(
Q(publisher_is_draft=False) and Q(commonextension__isnull=False)
).select_related("commonextension")

for page in cms_pages:
if page.application_namespace in (
"collaborate",
"home",
"inbox",
"products",
"profile",
"ssd",
):
kwargs["help_text"] = page.commonextension.help_text
elif page.get_absolute_url() in ("", "/"):
kwargs["help_text"] = page.commonextension.help_text

# help texts for cms pages without extension
cms_pages = Page.objects.filter(
Q(publisher_is_draft=False) and Q(commonextension__isnull=True)
)
for page in cms_pages:
kwargs["help_text"] = SiteConfiguration.get_solo().get_help_text(request)

return {**kwargs, "request": request}
26 changes: 14 additions & 12 deletions src/open_inwoner/configurations/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -265,23 +265,26 @@ class SiteConfiguration(SingletonModel):
home_help_text = models.TextField(
blank=True,
default=_(
"Welkom! Op dit scherm vindt u een overzicht van de verschillende onderwerpen en producten & diensten."
"Welkom! Op dit scherm vindt u een overzicht van de verschillende onderwerpen "
"en producten & diensten."
),
verbose_name=_("Home help"),
help_text=_("The help text for the home page."),
)
theme_help_text = models.TextField(
blank=True,
default=_(
"Op dit scherm vindt u de verschillende onderwerpen waarvoor wij producten en diensten aanbieden."
"Op dit scherm vindt u de verschillende onderwerpen waarvoor wij producten en "
"diensten aanbieden."
),
verbose_name=_("Category help"),
help_text=_("The help text for the theme page."),
)
product_help_text = models.TextField(
blank=True,
default=_(
"Op dit scherm kunt u de details vinden over het gekozen product of dienst. Afhankelijk van het product kunt u deze direct aanvragen of meer informatie opvragen."
"Op dit scherm kunt u de details vinden over het gekozen product of dienst. "
"Afhankelijk van het product kunt u deze direct aanvragen of meer informatie opvragen."
),
verbose_name=_("Product help"),
help_text=_("The help text for the product page."),
Expand All @@ -303,15 +306,21 @@ class SiteConfiguration(SingletonModel):
questionnaire_help_text = models.TextField(
blank=True,
default=_(
"Het onderdeel Zelfdiagnose stelt u in staat om met het beantwoorden van enkele vragen een advies te krijgen van de gemeente, met concrete vervolgstappen en producten en diensten. U kunt tevens uw antwoorden en het advies bewaren om met een begeleider van de gemeente te bespreken."
"Het onderdeel Zelfdiagnose stelt u in staat om met het beantwoorden van enkele vragen "
"een advies te krijgen van de gemeente, met concrete vervolgstappen en producten en "
"diensten. U kunt tevens uw antwoorden en het advies bewaren om met een begeleider van "
"de gemeente te bespreken."
),
verbose_name=_("Questionnaire help"),
help_text=_("The help text for the questionnaire page."),
)
plan_help_text = models.TextField(
blank=True,
default=_(
"Met het onderdeel Samenwerken kunt u samen met uw contactpersonen of begeleider van de gemeente aan de slag om met een samenwerkingsplan uw persoonlijke situatie te verbeteren. Door samen aan uw doelen te werken en acties te omschrijven kunnen we elkaar helpen."
"Met het onderdeel Samenwerken kunt u samen met uw contactpersonen of begeleider "
"van de gemeente aan de slag om met een samenwerkingsplan uw persoonlijke situatie "
"te verbeteren. Door samen aan uw doelen te werken en acties te omschrijven kunnen "
"we elkaar helpen."
),
verbose_name=_("Plan help"),
help_text=_("The help text for the plan page."),
Expand Down Expand Up @@ -533,15 +542,8 @@ def get_help_text(self, request) -> Optional[str]:
return ""

lookup = {
"pages-root": "home_help_text",
"products:category_list": "theme_help_text",
"products:category_product_detail": "product_help_text",
"products:product_detail": "product_help_text",
"products:product_form": "product_help_text",
"search:search": "search_help_text",
"profile:detail": "account_help_text",
"products:questionnaire_list": "questionnaire_help_text",
"collaborate:plan_list": "plan_help_text",
"pages-cookieroot": "cookie_info_text",
"pages-cookie": "cookie_link_text",
}
Expand Down
Loading