Skip to content

Commit

Permalink
Merge pull request #575 from maykinmedia/task/1352-hide-cta-sidemenu-…
Browse files Browse the repository at this point in the history
…button-when-it-exists-in-context

[#1352] Hide sidemenu ctabutton when it exists in product content
  • Loading branch information
alextreme authored Apr 6, 2023
2 parents 243cc5d + 5a3a790 commit 946935c
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,19 @@
</li>
{% endfor %}
{{ contents }}

<!-- dynamic anchor item for products -->
<div class="anchor-menu__start-inquiry">
{% if product.form %}
{% button_row mobile=True %}
{% button href=product.form_link text=_("Aanvraag starten") primary=True icon="arrow_forward" icon_position="before" %}
{% endbutton_row %}
{% elif product.link %}
{% button_row mobile=True %}
{% button href=product.link text=_("Aanvraag starten") primary=True icon="arrow_forward" icon_position="before" %}
{% endbutton_row %}
{% if not product.has_cta_tag %}
{% if product.form %}
{% button_row mobile=True %}
{% button href=product.form_link text=_("Aanvraag starten") primary=True icon="arrow_forward" icon_position="before" %}
{% endbutton_row %}
{% elif product.link %}
{% button_row mobile=True %}
{% button href=product.link text=_("Aanvraag starten") primary=True icon="arrow_forward" icon_position="before" %}
{% endbutton_row %}
{% endif %}
{% endif %}
</div>
</ul>
Expand Down
3 changes: 3 additions & 0 deletions src/open_inwoner/pdc/models/product.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,9 @@ def get_absolute_url(self, category=None):
kwargs={"slug": self.slug, "theme_slug": category_slug},
)

def has_cta_tag(self):
return "\[CTABUTTON\]" in self.content


class ProductFile(models.Model):
product = models.ForeignKey(
Expand Down
27 changes: 27 additions & 0 deletions src/open_inwoner/pdc/tests/test_product.py
Original file line number Diff line number Diff line change
Expand Up @@ -208,3 +208,30 @@ def test_button_is_not_rendered_inside_content_when_no_form_or_link(self):
cta_button = response.pyquery(".grid__main")[0].find_class("cta-button")

self.assertFalse(cta_button)

def test_sidemenu_button_is_not_rendered_when_cta_inside_product_content(self):
product = ProductFactory(
content="Some content \[CTABUTTON\]", link="http://www.example.com"
)

response = self.app.get(
reverse("pdc:product_detail", kwargs={"slug": product.slug})
)
sidemenu_cta_button = response.pyquery(
'.anchor-menu__list-item a[href="http://www.example.com"]'
)

self.assertFalse(sidemenu_cta_button)

def test_sidemenu_button_is_rendered_when_no_cta_inside_product_content(self):
product = ProductFactory(content="Some content", link="http://www.example.com")

response = self.app.get(
reverse("pdc:product_detail", kwargs={"slug": product.slug})
)
sidemenu_cta_button = response.pyquery(
'.anchor-menu__list-item a[href="http://www.example.com"]'
)

self.assertTrue(sidemenu_cta_button)
self.assertIn(product.link, sidemenu_cta_button[0].values())
28 changes: 10 additions & 18 deletions src/open_inwoner/templates/pages/product/detail.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,16 @@

{% block sidebar_content %}
{% anchor_menu anchors=anchors desktop=True %}
{% if product.form %}
<li class="anchor-menu__list-item">
{% button href=product.form_link size="big" text=_("Aanvraag starten") primary=True icon="arrow_forward" icon_position="before" %}
</li>
{% elif product.link %}
<li class="anchor-menu__list-item">
{% button href=product.link size="big" text=_("Aanvraag starten") primary=True icon="arrow_forward" icon_position="before" %}
</li>
{% if not product.has_cta_tag %}
{% if product.form %}
<li class="anchor-menu__list-item">
{% button href=product.form_link size="big" text=_("Aanvraag starten") primary=True icon="arrow_forward" icon_position="before" %}
</li>
{% elif product.link %}
<li class="anchor-menu__list-item">
{% button href=product.link size="big" text=_("Aanvraag starten") primary=True icon="arrow_forward" icon_position="before" %}
</li>
{% endif %}
{% endif %}
{% endanchor_menu %}
{% endblock sidebar_content %}
Expand All @@ -34,16 +36,6 @@ <h1 class="h1" id="title">
<p class="p">{{ object.summary }}</p>
{{ object|product_ckeditor_content|safe }}

{% if product.form %}
{% button_row mobile=True %}
{% button href=product.form_link text=_("Aanvraag starten") primary=True icon="arrow_forward" icon_position="before" %}
{% endbutton_row %}
{% elif product.link %}
{% button_row mobile=True %}
{% button href=product.link text=_("Aanvraag starten") primary=True icon="arrow_forward" icon_position="before" %}
{% endbutton_row %}
{% endif %}

{% if object.question_set.exists %}
<hr class="divider">
{% faq object.question_set.all %}
Expand Down

0 comments on commit 946935c

Please sign in to comment.