Skip to content

Commit

Permalink
Merge branch 'main' into TP1-168-strange-horizontal-panning-on-opport…
Browse files Browse the repository at this point in the history
…unity-pages-on
  • Loading branch information
ramram-mf authored Jun 10, 2024
2 parents 8262f86 + 867114a commit 550e7bb
Show file tree
Hide file tree
Showing 5 changed files with 77 additions and 25 deletions.
2 changes: 1 addition & 1 deletion dev-requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
45 changes: 45 additions & 0 deletions network-api/networkapi/wagtailcustomization/static/css/admin.css
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Original file line number Diff line number Diff line change
@@ -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

Expand Down Expand Up @@ -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)
Expand All @@ -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
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion requirements.in
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ Faker
future
gunicorn
heroku3
pygit2==1.14.0
pygit2==1.15.0
python-slugify
requests
social-auth-app-django
Expand Down
8 changes: 4 additions & 4 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 550e7bb

Please sign in to comment.