diff --git a/dev-requirements.txt b/dev-requirements.txt index 4f04bd57abb..7eff575ebe4 100644 --- a/dev-requirements.txt +++ b/dev-requirements.txt @@ -24,7 +24,7 @@ django==4.2.11 # via # -c requirements.txt # django-debug-toolbar -django-debug-toolbar==4.3.0 +django-debug-toolbar==4.4.2 # via -r dev-requirements.in djhtml==3.0.6 # via -r dev-requirements.in diff --git a/network-api/networkapi/wagtailcustomization/static/css/admin.css b/network-api/networkapi/wagtailcustomization/static/css/admin.css index 6e27231ba54..3ec0319c307 100644 --- a/network-api/networkapi/wagtailcustomization/static/css/admin.css +++ b/network-api/networkapi/wagtailcustomization/static/css/admin.css @@ -58,3 +58,48 @@ fieldset ul li div label { .required .field > label::after { display: inline-block !important; } + +/* Fix select2 dropdown autocomplete input field low contrast color scheme on dark mode */ +@media (prefers-color-scheme: dark) { + #wagtail .select2 .select2-selection { + color: var(--w-color-text-context); + background-color: var(--w-color-surface-field); + border-color: var(--w-color-border-field-default); + border-radius: 0.3125rem; + } + #wagtail .select2-container .select2-results .select2-results__options { + background-color: var(--w-color-surface-field); + } + /* Hover/Focus; Important for accesibility */ + #wagtail .select2 .select2-selection:hover, + #wagtail .select2 .select2-selection:focus { + border-color: var(--w-color-border-field-hover); + } + /* Options */ + #wagtail .select2-container .select2-results .select2-results__option { + color: var(--w-color-text-context); + background-color: var(--w-color-surface-field); + } + /* Selected/hover option */ + #wagtail + .select2-container + .select2-results + .select2-results__option--highlighted { + color: var(--w-color-text-label-menus-active); + background-color: var(--w-color-surface-button-default); + } + /* Input element */ + #wagtail + .select2-container--default + .select2-search--inline + .select2-search__field { + color: var(--w-color-text-context); + } + /* Focus input outline */ + #wagtail + .select2-container--default + .select2-search--inline + .select2-search__field:focus-visible { + outline: none !important; + } +} diff --git a/network-api/networkapi/wagtailpages/pagemodels/customblocks/recent_blog_entries.py b/network-api/networkapi/wagtailpages/pagemodels/customblocks/recent_blog_entries.py index 86cbbc48f58..93d09d017bf 100644 --- a/network-api/networkapi/wagtailpages/pagemodels/customblocks/recent_blog_entries.py +++ b/network-api/networkapi/wagtailpages/pagemodels/customblocks/recent_blog_entries.py @@ -1,6 +1,8 @@ from django.apps import apps +from django.core.exceptions import ValidationError from django.template.defaultfilters import slugify from wagtail import blocks +from wagtail.blocks import StructBlockValidationError from networkapi.wagtailpages.utils import get_locale_from_request @@ -35,9 +37,23 @@ class RecentBlogEntries(blocks.StructBlock): help_text="Optional divider below content block.", ) - # TODO: add in validation so that if there are no tags or topic - # filled in we don't allow the page to be saved, with a wagtail - # error indication what's wrong. + def clean(self, value): + validation_errors = {} + both_filters_error = ValidationError("Please provide either a Tag or a Topic, not both", code="invalid") + no_filter_error = ValidationError("Please provide a Tag or a Topic", code="required") + + if value["tag_filter"] and value["topic_filter"]: + validation_errors["tag_filter"] = both_filters_error + validation_errors["topic_filter"] = both_filters_error + + if not value["tag_filter"] and not value["topic_filter"]: + validation_errors["tag_filter"] = no_filter_error + validation_errors["topic_filter"] = no_filter_error + + if validation_errors: + raise StructBlockValidationError(validation_errors) + + return super().clean(value) def get_context(self, value, parent_context=None): context = super().get_context(value, parent_context=parent_context) @@ -50,25 +66,16 @@ def get_context(self, value, parent_context=None): topic = value.get("topic_filter", False) # default filter and query - type = "tags" + query_type = "tags" query = "mozilla" entries = [] - # If only tag_filter is chosen we want to load entries by tag and update the url accordingly - if tag and not topic: + if tag: tag = slugify(tag) query = tag blog_page.extract_tag_information(tag) - entries = blog_page.get_entries(context) - - """ - If topic_filter is chosen at all, we want to load entries by topic and - update the url accordingly. Once we add validation, we'll be able to remove - the prioritization of topic and instead notify the user that they must/can - only choose one filter option. - """ - if topic and topic != "All": - type = "topic" + elif topic and topic != "All": + query_type = "topic" query = slugify(topic) try: # verify this topic exists, and set up a filter for it @@ -81,13 +88,13 @@ def get_context(self, value, parent_context=None): # get the entries based on prefiltering entries = blog_page.get_entries(context) - # Updates the href for the 'More from our blog' button + # Update the href for the 'More from our blog' button blog_page_url = blog_page.get_url() - url = f"{blog_page_url}{type}/{query}" + url = f"{blog_page_url}{query_type}/{query}" context["more_entries_link"] = url # We only want to grab no more than the first 6 entries - context["entries"] = entries[0:6] + context["entries"] = entries[:6] # We only want to display the 'More from our blog' button if # there's more than 6 entries diff --git a/requirements.in b/requirements.in index 679e2ce691b..9c6b08f3025 100644 --- a/requirements.in +++ b/requirements.in @@ -20,7 +20,7 @@ Faker future gunicorn heroku3 -pygit2==1.14.0 +pygit2==1.15.0 python-slugify requests social-auth-app-django diff --git a/requirements.txt b/requirements.txt index be415c46603..974a62ad5c7 100644 --- a/requirements.txt +++ b/requirements.txt @@ -20,9 +20,9 @@ beautifulsoup4==4.9.3 # via # -r requirements.in # wagtail -boto3==1.34.98 +boto3==1.34.122 # via -r requirements.in -botocore==1.34.98 +botocore==1.34.122 # via # boto3 # s3transfer @@ -46,7 +46,7 @@ defusedxml==0.7.1 # python3-openid # social-auth-core # willow -dj-database-url==2.1.0 +dj-database-url==2.2.0 # via -r requirements.in django==4.2.11 # via @@ -171,7 +171,7 @@ psycopg2-binary==2.9.9 # via -r requirements.in pycparser==2.21 # via cffi -pygit2==1.14.0 +pygit2==1.15.0 # via # -r requirements.in # wagtail-localize-git