Skip to content

Commit

Permalink
Merge branch 'develop' into feature/1647-banner
Browse files Browse the repository at this point in the history
  • Loading branch information
pi-sigma committed Aug 28, 2023
2 parents 4e455b5 + ae69cd9 commit 2976730
Show file tree
Hide file tree
Showing 40 changed files with 509 additions and 248 deletions.
2 changes: 1 addition & 1 deletion requirements/base.txt
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ django-js-asset==1.2.2
# django-mptt
django-localflavor==3.1
# via -r requirements/base.in
django-log-outgoing-requests==0.4.0
django-log-outgoing-requests==0.5.0
# via -r requirements/base.in
django-mptt==0.13.4
# via django-filer
Expand Down
2 changes: 1 addition & 1 deletion requirements/ci.txt
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ django-localflavor==3.1
# via
# -c requirements/base.txt
# -r requirements/base.txt
django-log-outgoing-requests==0.4.0
django-log-outgoing-requests==0.5.0
# via
# -c requirements/base.txt
# -r requirements/base.txt
Expand Down
2 changes: 1 addition & 1 deletion requirements/dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@ django-localflavor==3.1
# via
# -c requirements/ci.txt
# -r requirements/ci.txt
django-log-outgoing-requests==0.4.0
django-log-outgoing-requests==0.5.0
# via
# -c requirements/ci.txt
# -r requirements/ci.txt
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{% load l10n form_tags %}

<label class="radio">
<div class="radio">
{% spaceless %}
{% initial_match as checked %}
<input
Expand All @@ -13,4 +13,4 @@
/>
<label class="radio__label" for="id_{{ name }}_{{ index }}">{{ choice.1 }}</label>
{% endspaceless %}
</label>
</div>
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
<div class="form__control {{ extra_classes|default:"" }}">
<label class="label {% if no_label %}label--gapless{% endif %}">
{% if icon %}{% icon icon outlined=True %}{% endif %}
<label class="label__label {% if no_label %}label__label--hidden{% endif %}">
<span class="label__label {% if no_label %}label__label--hidden{% endif %}">
{{ field.label }}
{% if field.field.required %}<span class="label__label--required"> * </span>{% endif %}
</label>
</span>
{{ field|addclass:"input" }}
{% if field.help_text and not no_help %}
<p class="p">{{ field.help_text }}</p>
Expand Down
27 changes: 0 additions & 27 deletions src/open_inwoner/components/templates/components/Form/Label.html

This file was deleted.

95 changes: 52 additions & 43 deletions src/open_inwoner/components/templates/components/Header/Header.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
{% get_solo "configurations.SiteConfiguration" as config %}

{% accessibility_header request=request %}

<header class="header" aria-label="Navigatie header">
<div class="header__container">
<div class="header__menu">
Expand All @@ -28,13 +29,15 @@
<div class="header__submenu">

{% if cms_apps.products %}
<nav class="header__actions" aria-label="Zoek navigatie mobiel">
{% url 'search:search' as search_url %}
{% render_form form=search_form method="GET" form_action=search_url inline=True spaceless=False %}
{% input search_form.query no_label=True %}
{% form_actions primary_icon="search" primary_text=_("Zoeken") hide_primary_text=True %}
{% endrender_form %}
</nav>
{% if request.user.is_authenticated or not config.hide_search_from_anonymous_users %}
<nav class="header__actions" aria-label="Zoek navigatie mobiel">
{% url 'search:search' as search_url %}
{% render_form form=search_form method="GET" form_action=search_url inline=True spaceless=False %}
{% input search_form.query no_label=True %}
{% form_actions primary_icon="search" primary_text=_("Zoeken") hide_primary_text=True %}
{% endrender_form %}
</nav>
{% endif %}
{% endif %}

<nav class="primary-navigation" aria-label="Hoofd navigatie">
Expand All @@ -45,25 +48,27 @@
{% link text=link_text href="/" icon="grid_view" icon_position="before" %}
</li>

{% if cms_apps.products and categories %}
<li class="primary-navigation__list-item dropdown-nav__toggle">
<a href="#" class="link link--toggle link--icon link--icon-position-before" aria-label="{% trans "Onderwerpen" %}" title="{% trans "Onderwerpen" %}" aria-expanded="false">
<span >{% trans "Onderwerpen" %}</span>
<span aria-hidden="true" class="material-icons-outlined ">description</span>
{% icon icon="expand_more" icon_position="after" icon_outlined=True %}
</a>

{% if categories %}
<ul class="primary-navigation__list subpage-list">
{% for category in categories %}
<li class="primary-navigation__list-item">
{% url 'products:category_detail' slug=category.slug as category_href %}
{% link text=category.name href=category_href %}
</li>
{% endfor %}
</ul>
{% if cms_apps.products %}
{% if request.user.is_authenticated or not config.hide_categories_from_anonymous_users %}
<li class="primary-navigation__list-item dropdown-nav__toggle">
<a href="#" class="link link--toggle link--icon link--icon-position-before" aria-label="{% trans "Onderwerpen" %}" title="{% trans "Onderwerpen" %}" aria-expanded="false">
<span >{% trans "Onderwerpen" %}</span>
<span aria-hidden="true" class="material-icons-outlined ">description</span>
{% icon icon="expand_more" icon_position="after" icon_outlined=True %}
</a>

{% if menu_categories %}
<ul class="primary-navigation__list subpage-list">
{% for category in menu_categories %}
<li class="primary-navigation__list-item">
{% url 'products:category_detail' slug=category.slug as category_href %}
{% link text=category.name href=category_href %}
</li>
{% endfor %}
</ul>
{% endif %}
</li>
{% endif %}
</li>
{% endif %}

{% show_menu_below_id "home" 0 100 100 100 "cms/menu/primary.html" %}
Expand Down Expand Up @@ -103,30 +108,34 @@
{% firstof config.logo.default_alt_text config.name as logo_alt_text %}
<div class="logo__desktop">{% logo src=config.logo.file.url alt="Homepage "|add:logo_alt_text svg_height=75 %}</div>

{% primary_navigation categories=categories request=request has_general_faq_questions=has_general_faq_questions cms_apps=cms_apps show_plans=show_plans %}
{% include "components/Header/PrimaryNavigation.html" %}

{% if cms_apps.products %}
<nav class="header__actions" aria-label="Zoek navigatie desktop">
{% url 'search:search' as search_url %}
{% render_form form=search_form method="GET" form_action=search_url inline=True spaceless=True %}
{% input search_form.query no_label=True %}
{% form_actions primary_icon="search" primary_text=_("Zoeken") hide_primary_text=True %}
{% endrender_form %}
</nav>
{% if request.user.is_authenticated or not config.hide_search_from_anonymous_users %}
<nav class="header__actions" aria-label="Zoek navigatie desktop">
{% url 'search:search' as search_url %}
{% render_form form=search_form method="GET" form_action=search_url inline=True spaceless=True %}
{% input search_form.query no_label=True %}
{% form_actions primary_icon="search" primary_text=_("Zoeken") hide_primary_text=True %}
{% endrender_form %}
</nav>
{% endif %}
{% endif %}

{% navigation_authenticated categories=categories request=request has_general_faq_questions=has_general_faq_questions %}
{% include "components/Header/NavigationAuthenticated.html" %}
</div>
</header>

{% if cms_apps.products %}
<section class="search search__mobile">
<nav class="search__actions " aria-label="Zoek navigatie mobiel">
{% url 'search:search' as search_url %}
{% render_form form=search_form method="GET" form_action=search_url inline=True spaceless=False %}
{% input search_form.query no_label=True %}
{% form_actions primary_icon="search" primary_text=_("Zoeken") hide_primary_text=True %}
{% endrender_form %}
</nav>
</section>
{% if request.user.is_authenticated or not config.hide_search_from_anonymous_users %}
<section class="search search__mobile">
<nav class="search__actions " aria-label="Zoek navigatie mobiel">
{% url 'search:search' as search_url %}
{% render_form form=search_form method="GET" form_action=search_url inline=True spaceless=False %}
{% input search_form.query no_label=True %}
{% form_actions primary_icon="search" primary_text=_("Zoeken") hide_primary_text=True %}
{% endrender_form %}
</nav>
</section>
{% endif %}
{% endif %}
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,21 @@

<nav class="primary-navigation primary-navigation__main" aria-label="Hoofd navigatie">
<ul class="primary-navigation__list">

{% if cms_apps.products and categories %}
<li class="primary-navigation__list-item">
{% button text=_('Onderwerpen') type="button" icon="expand_more" icon_position="after" icon_outlined=True transparent=True extra_classes="primary-navigation--toggle" %}
{% if request.user.is_authenticated or not config.hide_categories_from_anonymous_users %}
<li class="primary-navigation__list-item">
{% button text=_('Onderwerpen') type="button" icon="expand_more" icon_position="after" icon_outlined=True transparent=True extra_classes="primary-navigation--toggle" %}

{% if categories %}
<ul class="primary-navigation__list subpage-list">
{% for category in categories %}
<li class="primary-navigation__list-item">
{% url 'products:category_detail' slug=category.slug as category_href %}
{% link text=category.name href=category_href %}
</li>
{% endfor %}
</ul>
<ul class="primary-navigation__list subpage-list">
{% for category in categories %}
<li class="primary-navigation__list-item">
{% url 'products:category_detail' slug=category.slug as category_href %}
{% link text=category.name href=category_href %}
</li>
{% endfor %}
</ul>
</li>
{% endif %}
</li>
{% endif %}
</ul>
</nav>
46 changes: 0 additions & 46 deletions src/open_inwoner/components/templatetags/header_tags.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
from django import template

from open_inwoner.configurations.models import SiteConfiguration
from open_inwoner.questionnaire.models import QuestionnaireStep

register = template.Library()

Expand Down Expand Up @@ -38,51 +37,6 @@ def header(categories, request, **kwargs):
+ request: Request | the django request object.
- has_general_faq_questions: boolean | If the FAQ menu item should be shown.
"""
return {
**kwargs,
"categories": categories,
"request": request,
}


@register.inclusion_tag("components/Header/PrimaryNavigation.html")
def primary_navigation(categories, request, **kwargs):
"""
Displaying the primary navigation
Usage:
{% primary_navigation categories=Category.objects.all request=request %}
Variables:
+ categories: Category[] | The categories that should be displayed in the theme dropdown.
+ request: Request | The django request object.
+ questionnaire: QuestionnaireStep | The default QuestionnaireStep, if any.
- has_general_faq_questions: boolean | If the FAQ menu item should be shown.
- show_plans: boolean | If the Plan item should be shown.
"""

return {
**kwargs,
"categories": categories,
"request": request,
}


@register.inclusion_tag("components/Header/NavigationAuthenticated.html")
def navigation_authenticated(categories, request, **kwargs):
"""
Displaying the desktop navigation when user is authenticated
Usage:
{% navigation_authenticated categories=Category.objects.all request=request %}
Variables:
+ categories: Category[] | The categories that should be displayed in the theme dropdown.
+ request: Request | The django request object.
+ questionnaire: QuestionnaireStep | The default QuestionnaireStep, if any.
- has_general_faq_questions: boolean | If the FAQ menu item should be shown.
- show_plans: boolean | If the Plan item should be shown.
"""

return {
**kwargs,
Expand Down
83 changes: 83 additions & 0 deletions src/open_inwoner/components/tests/test_header.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
from django.test import TestCase

from pyquery import PyQuery

from open_inwoner.accounts.tests.factories import UserFactory
from open_inwoner.cms.products.cms_apps import ProductsApphook
from open_inwoner.cms.tests import cms_tools
from open_inwoner.cms.tests.cms_tools import create_apphook_page
from open_inwoner.configurations.models import SiteConfiguration
from open_inwoner.pdc.tests.factories import CategoryFactory


class HeaderTest(TestCase):
@classmethod
def setUpTestData(cls):
cls.user = UserFactory()
cls.user.set_password("12345")
cls.user.email = "[email protected]"
cls.user.save()

cms_tools.create_homepage()

# PrimaryNavigation.html requires apphook + categories
create_apphook_page(ProductsApphook)
cls.published1 = CategoryFactory(
path="0001", name="First one", slug="first-one"
)
cls.published2 = CategoryFactory(
path="0002", name="Second one", slug="second-one"
)

def test_categories_hidden_from_anonymous_users(self):
config = SiteConfiguration.get_solo()
config.hide_categories_from_anonymous_users = True
config.save()

response = self.client.get("/")

doc = PyQuery(response.content)

categories = doc.find("[title='Onderwerpen']")
self.assertEqual(len(categories), 0)

def test_categories_not_hidden_from_anonymous_users(self):
config = SiteConfiguration.get_solo()
config.hide_categories_from_anonymous_users = False
config.save()

response = self.client.get("/")

doc = PyQuery(response.content)

categories = doc.find("[title='Onderwerpen']")
self.assertEqual(len(categories), 2)
self.assertEqual(categories[0].tag, "a")
self.assertEqual(categories[1].tag, "button")

def test_search_bar_hidden_from_anonymous_users(self):
config = SiteConfiguration.get_solo()
config.hide_search_from_anonymous_users = True
config.save()

response = self.client.get("/")

doc = PyQuery(response.content)

search_buttons = doc.find("[title='Zoeken']")

self.assertEqual(len(search_buttons), 0)

def test_search_bar_not_hidden_from_anonymous_users(self):
config = SiteConfiguration.get_solo()
config.hide_search_from_anonymous_users = False
config.save()

response = self.client.get("/")

doc = PyQuery(response.content)

search_buttons = doc.find("[title='Zoeken']")

for button in search_buttons:
self.assertEqual(button.tag, "button")
Loading

0 comments on commit 2976730

Please sign in to comment.