Skip to content

Commit

Permalink
Merge branch 'main' into issue-11795-hero-gap
Browse files Browse the repository at this point in the history
  • Loading branch information
robdivincenzo authored Feb 14, 2024
2 parents 0a544d1 + f99c0bc commit c0d3e6b
Show file tree
Hide file tree
Showing 21 changed files with 549 additions and 300 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{% load bg_nav_tags i18n static wagtailcore_tags wagtailroutablepage_tags wagtailmetadata_tags %}

<nav id="multipage-nav" class="pni-category-nav text-center d-none d-md-block tw-no-scrollbar tw-border-b tw-border-blue-10" title="{% trans "site navigation" context "Tooltip on menu items" %}">
<div class="container tw-py-4" id="product-review">
<div class="row">
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{% load i18n %}

<a href="https://mozillafoundation.typeform.com/to/oWfci8Ee" target="_blank" class="tw-font-sans tw-text-blue-80 tw-underline tw-decoration-blue-80">{% trans "Submit a product here." %}</a>
<a href="https://mozillafoundation.tfaforms.net/34" target="_blank" class="tw-font-sans tw-text-blue-80 tw-underline tw-decoration-blue-80">{% trans "Submit a product here." %}</a>
4 changes: 3 additions & 1 deletion network-api/networkapi/templates/pages/buyersguide/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@

{% get_bg_home_page as home_page %}

{% bg_categories_in_subnav as categories %}

<div class="primary-nav-container-wrapper">
{% include "fragments/buyersguide/primary_nav.html" %}
</div>
Expand All @@ -89,7 +91,7 @@
{% endblock %}

{% block category_nav %}
{% include "fragments/buyersguide/pni_category_nav.html" with show_all_reviews_as_active_category=False categories=categories current_category=current_category %}
{% include "fragments/buyersguide/pni_category_nav.html" with show_all_reviews_as_active_category=False current_category=current_category %}
{% endblock %}

<!-- Need to position relatives to deal with potential CSS transformations that change some stacking context of elements -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@
</div>
</div>
{% get_bg_home_page as home_page %}
{% bg_non_hidden_categories as categories %}
<div class="project-list-section">
<div class="container">
<div class="row tw-mb-6 medium:tw-mb-4">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
{% block body_id %}home{% endblock %}

{% block category_nav %}
{% include "fragments/buyersguide/pni_category_nav.html" with show_all_reviews_as_active_category=True categories=categories current_category=current_category %}
{% include "fragments/buyersguide/pni_category_nav.html" with show_all_reviews_as_active_category=True current_category=current_category %}
{% endblock %}

{% block hero %}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{% extends "pages/buyersguide/catalog.html" %}
{% load wagtailcore_tags %}

{% block body_id %}home{% endblock body_id %}

{% block category_nav %}
{% include "fragments/buyersguide/pni_category_nav.html" with show_all_reviews_as_active_category=True current_category=current_category %}
{% endblock category_nav %}
30 changes: 30 additions & 0 deletions network-api/networkapi/wagtailpages/factory/buyersguide.py
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,27 @@ class Meta:
donation_modal = SubFactory(DonationModalFactory)


class BuyersGuideCategoryNavFactory(DjangoModelFactory):
class Meta:
model = pagemodels.BuyersGuideCategoryNav

@classmethod
def _get_or_create(cls, model_class, *args, **kwargs):
return pagemodels.BuyersGuideCategoryNav.load()

@classmethod
def _create(cls, model_class, *args, **kwargs):
return pagemodels.BuyersGuideCategoryNav.load()


class BuyersGuideCategoryNavRelationFactory(DjangoModelFactory):
class Meta:
model = pagemodels.BuyersGuideCategoryNavRelation

nav = SubFactory(BuyersGuideCategoryNavFactory)
category = SubFactory(BuyersGuideProductCategoryFactory)


def create_general_product_visual_regression_product(seed, pni_homepage):
# There are no random fields here: *everything* is prespecified
GeneralProductPageFactory.create(
Expand Down Expand Up @@ -521,6 +542,15 @@ def generate(seed):
sort_order=index,
)

print("Generating PNI categories navigation bar")
# Alphabetically ordered by default
categories = pagemodels.BuyersGuideProductCategory.objects.all().order_by("name")
for index, category in enumerate(categories):
BuyersGuideCategoryNavRelationFactory(
category=category,
sort_order=index,
)

# The following section is commented, because the homepage redesign needs to be implemented.
# Until then, we want the generated homepage to be closer to the production site, where none of these
# relations are used.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
# Generated by Django 4.2.9 on 2024-02-09 20:24

import django.db.models.deletion
import modelcluster.fields
from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
("wagtailpages", "0123_alter_petition_show_comment_field_and_more"),
]

operations = [
migrations.CreateModel(
name="BuyersGuideCategoryNav",
fields=[
("id", models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name="ID")),
],
options={
"verbose_name": "*PNI categories navbar",
"verbose_name_plural": "*PNI categories navbar",
},
),
migrations.AlterModelOptions(
name="buyersguideproductcategory",
options={
"ordering": [models.OrderBy(models.F("parent__name"), nulls_first=True), "name"],
"verbose_name": "Buyers Guide Product Category",
"verbose_name_plural": "Buyers Guide Product Categories",
},
),
migrations.RemoveField(
model_name="buyersguideproductcategory",
name="sort_order",
),
migrations.CreateModel(
name="BuyersGuideCategoryNavRelation",
fields=[
("id", models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name="ID")),
("sort_order", models.IntegerField(blank=True, editable=False, null=True)),
(
"category",
models.ForeignKey(
on_delete=django.db.models.deletion.CASCADE,
related_name="nav_relations",
to="wagtailpages.buyersguideproductcategory",
),
),
(
"nav",
modelcluster.fields.ParentalKey(
on_delete=django.db.models.deletion.CASCADE,
related_name="category_relations",
to="wagtailpages.buyersguidecategorynav",
),
),
],
options={
"verbose_name": "Category Navigation Relation",
"verbose_name_plural": "Category Navigation Relations",
"ordering": ["sort_order"],
"unique_together": {("nav", "category")},
},
),
]
6 changes: 5 additions & 1 deletion network-api/networkapi/wagtailpages/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@
BuyersGuideCampaignPage,
BuyersGuideCampaignPageDonationModalRelation,
)
from .pagemodels.buyersguide.categories import (
BuyersGuideCategoryNav,
BuyersGuideCategoryNavRelation,
BuyersGuideProductCategory,
)
from .pagemodels.buyersguide.consumer_creepometer_page import ConsumerCreepometerPage
from .pagemodels.buyersguide.editorial_content_index import (
BuyersGuideEditorialContentIndexPage,
Expand All @@ -40,7 +45,6 @@
BuyersGuidePageHeroSupportingPageRelation,
)
from .pagemodels.buyersguide.products import (
BuyersGuideProductCategory,
BuyersGuideProductCategoryArticlePageRelation,
BuyersGuideProductPageArticlePageRelation,
GeneralProductPage,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import typing

from django import http
from django.db import models
from modelcluster import fields as cluster_fields
from wagtail import blocks, fields, images
Expand All @@ -14,10 +13,6 @@
from networkapi.wagtailpages.pagemodels.buyersguide.forms import (
BuyersGuideArticlePageForm,
)
from networkapi.wagtailpages.pagemodels.buyersguide.utils import (
get_categories_for_locale,
)
from networkapi.wagtailpages.utils import get_language_from_request

if typing.TYPE_CHECKING:
from networkapi.wagtailpages.models import BuyersGuideContentCategory, Profile
Expand Down Expand Up @@ -110,12 +105,6 @@ class BuyersGuideArticlePage(BasePage):
SynchronizedField("search_image"),
]

def get_context(self, request: http.HttpRequest, *args, **kwargs) -> dict:
context = super().get_context(request, *args, **kwargs)
language_code = get_language_from_request(request)
context["categories"] = get_categories_for_locale(language_code)
return context

def get_author_profiles(self) -> list["Profile"]:
author_profiles = orderables.get_related_items(
self.author_profile_relations.all(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,6 @@

from networkapi.wagtailpages.pagemodels import customblocks
from networkapi.wagtailpages.pagemodels.base import BasePage
from networkapi.wagtailpages.pagemodels.buyersguide.utils import (
get_categories_for_locale,
)
from networkapi.wagtailpages.utils import get_language_from_request

from ..customblocks.full_content_rich_text_options import full_content_rich_text_options

Expand Down Expand Up @@ -125,9 +121,3 @@ def get_donation_modal_json(self):
TranslatableField("search_description"),
SynchronizedField("search_image"),
]

def get_context(self, request, *args, **kwargs):
context = super().get_context(request, *args, **kwargs)
language_code = get_language_from_request(request)
context["categories"] = get_categories_for_locale(language_code)
return context
Loading

0 comments on commit c0d3e6b

Please sign in to comment.