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

[PNI] Search - update basic search behaviour #7649

Merged
merged 11 commits into from
Oct 28, 2021
5 changes: 3 additions & 2 deletions network-api/networkapi/wagtailpages/pagemodels/products.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,7 @@ class BuyersGuideProductCategory(TranslatableMixin, LocalizedSnippet, models.Mod
TranslatableField('description'),
SynchronizedField('slug'),
SynchronizedField('share_image'),
fessehaye marked this conversation as resolved.
Show resolved Hide resolved
SynchronizedField('parent'),
]

@property
Expand Down Expand Up @@ -1638,8 +1639,7 @@ def categories_page(self, request, slug):
self.cutoff_date,
authenticated,
key,
ProductPage.objects.filter(product_categories__category__in=[original_category])
.exclude(product_categories__category__id__in=exclude_cat_ids),
ProductPage.objects.exclude(product_categories__category__id__in=exclude_cat_ids),
language_code=language_code
)

Expand Down Expand Up @@ -1709,6 +1709,7 @@ def get_context(self, request, *args, **kwargs):
)

context['categories'] = get_categories_for_locale(language_code)
context['current_category'] = None
context['products'] = products
context['web_monetization_pointer'] = settings.WEB_MONETIZATION_POINTER
pni_home_page = BuyersGuidePage.objects.first()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
{% else %}{% blocktrans context "“*privacy not included” can be localized. This is a reference to the “*batteries not included” mention on toys." %}*privacy not included | Shop smart and safe{% endblocktrans %} | Mozilla Foundation{% endif %}
{% endblock %}


{# TODO: consider using a different ga_identifier? #}


Expand All @@ -23,6 +22,8 @@

{% block wagtail_metadata %}
{% meta_tags %}
<meta name="pni-home-title" content="{% blocktrans context "“*privacy not included” can be localized. This is a reference to the “*batteries not included” mention on toys." %}*privacy not included | Shop smart and safe | Mozilla Foundation{% endblocktrans %}">
<meta name="pni-category-title" content="{% trans "Privacy & Security Guide | Mozilla Foundation" %}">
{% endblock %}


Expand Down Expand Up @@ -86,16 +87,16 @@
<div class="row">
<div class="col">
{% if pagetype == "product" or pagetype == "about" %}
<a class="multipage-link active" data-mobile="{% trans "All Categories" %}" href="{% relocalized_url home_page.localized.url %}">{% trans "All" %}</a>
<a class="multipage-link active" data-name="None" data-mobile="{% trans "All Categories" %}" href="{% relocalized_url home_page.localized.url %}">{% trans "All" %}</a>
{% else %}
<a class="multipage-link {% if not category %} active{% endif %}" data-mobile="{% trans "All Categories" %}" href="{% relocalized_url home_page.localized.url %}">{% trans "All" %}</a>
<a class="multipage-link {% if not category %} active{% endif %}" data-name="None" data-mobile="{% trans "All Categories" %}" href="{% relocalized_url home_page.localized.url %}">{% trans "All" %}</a>
{% endif %}

{% for cat in categories %}
{% with original=cat.original %}
{% if original.published_product_page_count > 0 %}
{% localizedroutablepageurl home_page 'category-view' original.slug as cat_url %}
<a class="multipage-link {% check_active_category current_category cat %}{% if original.featured is True %} featured{% endif %}" href="{{ cat_url }}" data-name="{{ original.name }}">{{ cat.name }}</a>
<a class="multipage-link {% check_active_category current_category cat %}{% if original.featured is True %} featured{% endif %}" href="{{ cat_url }}" data-name="{{ cat.name }}">{{ cat.name }}</a>
{% endif %}
{% endwith %}
{% endfor %}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
{% extends "buyersguide/bg_base.html" %}

{% load env i18n static wagtailimages_tags cache %}
{% load env i18n static wagtailimages_tags cache bg_nav_tags %}

{% block bodyclass %}pni catalog{% endblock %}

{% block main_content_class %}{% endblock %}

{% block hero %}
<input type="hidden" class="category-title" value="{{current_category.localized.name}}">
<header
class="container-fluid text-center page-header bg-gray"
{% if page.get_banner != None %}style="background-image: url({% image page.get_banner max-1920x1280 as img %}{{ img.url }})"{% endif %}
Expand All @@ -20,7 +21,7 @@ <h1 class="h1-heading text-center mt-0">{{ page.header }}</h1>
<p class="body-large mb-0">{{ page.intro_text }}</p>
<div id="product-filter-search" class='col-12 col-md-9 tw-my-5' tabindex="0">
<span class="search-icon">&nbsp;</span>
<input type="text" role="searchbox" id="product-filter-search-input" placeholder="{% trans "Search all products" %}" class="body-large" value="">
<input type="text" role="searchbox" id="product-filter-search-input" placeholder="{% trans "Search all products" %}" class="body-large tw-text-black" value="">
<label for="product-filter-search-input" class="clear-icon">&nbsp;</label>
</div>
</div>
Expand Down Expand Up @@ -68,13 +69,15 @@ <h1 class="h1-heading text-center mt-0">{{ page.header }}</h1>
{# User is not logged in. Return cached results. 24 hour caching applied. #}
{% cache 86400 pni_home_page template_cache_key_fragment %}
{% for product in products %}
{% include "../fragments/buyersguide_item.html" with product=product.localized %}
{% prod_in_cat product category as matched %}
{% include "../fragments/buyersguide_item.html" with product=product.localized matched=matched %}
{% endfor %}
{% endcache %}
{% else %}
{# User is logged in. Don't cache their results so they can see live and draft products here. #}
{% for product in products %}
{% include "../fragments/buyersguide_item.html" with product=product.localized %}
{% prod_in_cat product category as matched %}
{% include "../fragments/buyersguide_item.html" with product=product.localized matched=matched %}
{% endfor %}
{% endif %}
</div>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{% load static i18n wagtailimages_tags l10n localization %}

<figure
class="product-box d-flex flex-column justify-content-between{% if product.draft %} draft-product{% endif %}{% if product.adult_content %} adult-content{% endif %}{% if product.privacy_ding %} privacy-ding{% endif%}"
class="product-box {% if matched == False %}d-none{% else %}d-flex{% endif %} flex-column justify-content-between{% if product.draft %} draft-product{% endif %}{% if product.adult_content %} adult-content{% endif %}{% if product.privacy_ding %} privacy-ding{% endif%}"
data-creepiness="{{ product.creepiness|unlocalize }}">
<div class="top-left-badge-container">
{% if product.privacy_ding %}
Expand Down Expand Up @@ -39,5 +39,10 @@
</a>
<input type="hidden" class="product-blurb" value="{{ product.blurb }}">
<input type="hidden" class="product-worst-case" value="{{ product.worst_case }}">
{% for cat in product.product_categories.all %}
{% with category=cat.category %}
<input type="hidden" class="product-categories" value="{{category.localized.name}}">
fessehaye marked this conversation as resolved.
Show resolved Hide resolved
{% endwith %}
{% endfor %}
</figcaption>
</figure>
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
{% load i18n static %}
{% load i18n static localization %}

<div class="container">
<img class="mb-3 oh-no-face" src="{% static '_images/buyers-guide/faces/oh-no.svg' %}" alt="{% trans "Sad face. No products were found." %}">
<img class="mb-3 oh-no-face" src="{% static '_images/buyers-guide/faces/oh-no.svg' %}" alt="{% trans "Sad face. No products were found." %}">

<h3 class="h3-heading">
{% trans 'Oh no! We didn’t find that here.' %}
</h3>
<h3 class="h3-heading">
{% trans 'Oh no! We didn’t find that here.' %}
</h3>

<p class="mb-0">
{% url 'buyersguide-home' as home_url %}
{% blocktrans trimmed %}
Try going back to <a href="{{ home_url }}" class="go-back-to-all-link">All</a>. You might find it there.
{% endblocktrans %}
</p>
<p class="mb-0">
{% relocalized_url home_page.localized.url as home_url %}
{% blocktrans trimmed with home_url=home_url %}
Try going back to <a href="{{home_url}}" class="go-back-to-all-link">All</a>. You might find it there.
{% endblocktrans %}
</p>
</div>
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,13 @@ def bg_active_nav(current, target):
return 'active' if urlparse(current).path == urlparse(target).path else ''


@register.simple_tag(name='prod_in_cat')
def prod_in_cat(productpage, categorySlug):
if categorySlug == "":
return True
return categorySlug in [cat.category.slug for cat in productpage.product_categories.all()]


"""
# Instantiate a list of category page links based on the current page's relation to them
# NOTE: this points to the new, namespaced category_nav_links. If we need to revert to the old app, change this back.
Expand Down
2 changes: 1 addition & 1 deletion network-api/networkapi/wagtailpages/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ def test_category_filter_view(self):
with self.settings(CACHES={'default': {'BACKEND': 'django.core.cache.backends.dummy.DummyCache'}}):
response = self.client.get(url)
self.assertEqual(response.status_code, 200)
self.assertEqual(len(response.context['products']), 0)
self.assertEqual(len(response.context['products']), 1)

# Add BuyersGuideProductCategory
category_orderable = ProductPageCategory(
Expand Down
Loading