From 2d57a8d7fb86e0d41ff18775b426a4267307d4c7 Mon Sep 17 00:00:00 2001 From: Sarah Boyce <42296566+sarahboyce@users.noreply.github.com> Date: Mon, 24 Nov 2025 14:26:15 +0100 Subject: [PATCH] Restored search hotkey for desktop. --- .github/workflows/tests.yml | 3 + Dockerfile | 4 ++ Makefile | 2 +- djangoproject/static/js/djangoproject.js | 14 +++- djangoproject/templates/includes/header.html | 5 +- djangoproject/templates/search_form.html | 7 +- djangoproject/tests.py | 70 ++++++++++++++++++++ djangoproject/utils.py | 16 ++--- docs/forms.py | 10 +++ docs/templatetags/docs.py | 29 ++++++-- docs/tests/test_templates.py | 13 +++- docs/views.py | 15 +++-- requirements/tests.txt | 1 + 13 files changed, 160 insertions(+), 29 deletions(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 0ceef41d84..495962d0a3 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -39,6 +39,9 @@ jobs: run: | python -m pip install --upgrade pip setuptools python -m pip install -r requirements/tests.txt + - name: Install playwright browsers + run: | + python -m playwright install --with-deps - name: Set up databases run: | PGPASSWORD="postgres" createuser -U postgres -d djangoproject --superuser -h localhost diff --git a/Dockerfile b/Dockerfile index 2018de0a66..21a3c6a07b 100644 --- a/Dockerfile +++ b/Dockerfile @@ -31,6 +31,10 @@ COPY ./requirements ./requirements RUN apt-get update \ && apt-get install --assume-yes --no-install-recommends ${BUILD_DEPENDENCIES} \ && python3 -m pip install --no-cache-dir -r ${REQ_FILE} \ + && if [ "${REQ_FILE}" = "requirements/tests.txt" ]; then \ + echo "Installing Playwright browsers..."; \ + playwright install --with-deps; \ + fi \ && apt-get purge --assume-yes --auto-remove ${BUILD_DEPENDENCIES} \ && apt-get distclean diff --git a/Makefile b/Makefile index 910ce300e4..264d28e86a 100644 --- a/Makefile +++ b/Makefile @@ -4,7 +4,7 @@ APP_LIST ?= accounts aggregator blog contact dashboard djangoproject docs founda SCSS = djangoproject/scss STATIC = djangoproject/static -ci: compilemessages test +ci: compilemessages collectstatics test @python -m coverage report compilemessages: diff --git a/djangoproject/static/js/djangoproject.js b/djangoproject/static/js/djangoproject.js index b420896d5e..ade61c7de0 100644 --- a/djangoproject/static/js/djangoproject.js +++ b/djangoproject/static/js/djangoproject.js @@ -67,8 +67,12 @@ document.querySelector('.menu-button').addEventListener('click', function () { // Update search input placeholder text based on the user's operating system (function () { - const el = document.getElementById('id_q'); + const inputs = [ + document.getElementById('id_desktop-q'), + document.getElementById('id_mobile-q'), + ]; + const el = inputs.find((el) => el.checkVisibility()); if (!el) { return; } @@ -94,7 +98,13 @@ window.addEventListener('keydown', function (e) { e.preventDefault(); - const el = document.querySelector('#id_q'); + const inputs = [ + document.getElementById('id_desktop-q'), + document.getElementById('id_mobile-q'), + ]; + + const el = inputs.find((el) => el.checkVisibility()); + if (!el) return; el.select(); el.focus(); diff --git a/djangoproject/templates/includes/header.html b/djangoproject/templates/includes/header.html index aa62a1bc14..a9edcf35e8 100644 --- a/djangoproject/templates/includes/header.html +++ b/djangoproject/templates/includes/header.html @@ -1,4 +1,5 @@ {% load docs %} +{% search_context as cached_search_context %} {% if 'preview.djangoproject.com' in request.get_host %}
{% endif %} @@ -7,7 +8,7 @@

The web framework for perfectionists with deadlines.

- {% search_form %} + {% search_form prefix="mobile" cached_search_context=cached_search_context %}
{% include "includes/toggle_theme.html" %}
@@ -47,7 +48,7 @@ ♥ Donate
  • - {% search_form %} + {% search_form prefix="desktop" cached_search_context=cached_search_context %}
  • {% include "includes/toggle_theme.html" %} diff --git a/djangoproject/templates/search_form.html b/djangoproject/templates/search_form.html index eea6c3717f..3082dc142b 100644 --- a/djangoproject/templates/search_form.html +++ b/djangoproject/templates/search_form.html @@ -1,9 +1,10 @@ -{% load i18n %} +{% load i18n docs %} -
    + + {% build_search_form cached_search_context.release prefix as form %} {{ form.q }} - +