Skip to content

Commit af929f0

Browse files
alexgminbmispelon
authored andcommitted
Revert "Added code references to search results. (#1947)"
This reverts commit fa56d9b.
1 parent 64003b4 commit af929f0

File tree

10 files changed

+34
-453
lines changed

10 files changed

+34
-453
lines changed

djangoproject/scss/_style.scss

-33
Original file line numberDiff line numberDiff line change
@@ -2635,39 +2635,6 @@ table.docutils th {
26352635
color: var(--search-mark-text);
26362636
}
26372637
}
2638-
2639-
.code-links {
2640-
margin-top: 15px;
2641-
margin-left: 10px;
2642-
list-style-type: none;
2643-
padding-left: 0;
2644-
2645-
a {
2646-
&:active,
2647-
&:focus,
2648-
&:hover {
2649-
code {
2650-
color: var(--primary);
2651-
}
2652-
.meta {
2653-
color: var(--text-light);
2654-
}
2655-
}
2656-
}
2657-
2658-
code {
2659-
color: var(--primary-accent);
2660-
font-weight: 700;
2661-
}
2662-
2663-
div {
2664-
margin: 0;
2665-
.meta {
2666-
margin: 5px 0 0;
2667-
color: var(--body-fg);
2668-
}
2669-
}
2670-
}
26712638
}
26722639

26732640
.list-links-small {

docs/builder.py

-76
This file was deleted.

docs/management/commands/update_docs.py

+21-26
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
"""
55

66
import json
7-
import multiprocessing
87
import os
98
import shutil
109
import subprocess
@@ -18,9 +17,6 @@
1817
from django.core.management import BaseCommand, call_command
1918
from django.db.models import Q
2019
from django.utils.translation import to_locale
21-
from sphinx.application import Sphinx
22-
from sphinx.config import Config
23-
from sphinx.errors import SphinxError
2420

2521
from ...models import DocumentRelease
2622

@@ -209,30 +205,29 @@ def build_doc_release(self, release, force=False, interactive=False):
209205

210206
if self.verbosity >= 2:
211207
self.stdout.write(f" building {builder} ({source_dir} -> {build_dir})")
212-
# Retrieve the extensions from the conf.py so we can append to them.
213-
conf_extensions = Config.read(source_dir.resolve()).extensions
214-
extensions = [*conf_extensions, "docs.builder"]
215208
try:
216-
Sphinx(
217-
srcdir=source_dir,
218-
confdir=source_dir,
219-
outdir=build_dir,
220-
doctreedir=build_dir.joinpath(".doctrees"),
221-
buildername=builder,
222-
# Translated docs builds generate a lot of warnings, so send
223-
# stderr to stdout to be logged (rather than generating an email)
224-
warning=sys.stdout,
225-
parallel=multiprocessing.cpu_count(),
226-
verbosity=self.verbosity,
227-
confoverrides={
228-
"language": to_locale(release.lang),
229-
"extensions": extensions,
230-
},
231-
).build()
232-
except SphinxError as e:
209+
# Translated docs builds generate a lot of warnings, so send
210+
# stderr to stdout to be logged (rather than generating an
211+
# email)
212+
subprocess.check_call(
213+
[
214+
"sphinx-build",
215+
"-b",
216+
builder,
217+
"-D",
218+
"language=%s" % to_locale(release.lang),
219+
"-j",
220+
"auto",
221+
"-Q" if self.verbosity == 0 else "-q",
222+
str(source_dir), # Source file directory
223+
str(build_dir), # Destination directory
224+
],
225+
stderr=sys.stdout,
226+
)
227+
except subprocess.CalledProcessError:
233228
self.stderr.write(
234-
"sphinx-build returned an error (release %s, builder %s): %s"
235-
% (release, builder, str(e))
229+
"sphinx-build returned an error (release %s, builder %s)"
230+
% (release, builder)
236231
)
237232
return
238233

docs/models.py

+11-14
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import html
33
import json
44
import operator
5-
from functools import partial, reduce
5+
from functools import reduce
66
from pathlib import Path
77

88
from django.conf import settings
@@ -262,12 +262,6 @@ def search(self, query_text, release):
262262
query_text, config=models.F("config"), search_type="websearch"
263263
)
264264
search_rank = SearchRank(models.F("search"), search_query)
265-
search = partial(
266-
SearchHeadline,
267-
start_sel=START_SEL,
268-
stop_sel=STOP_SEL,
269-
config=models.F("config"),
270-
)
271265
base_qs = (
272266
self.prefetch_related(
273267
Prefetch(
@@ -280,18 +274,21 @@ def search(self, query_text, release):
280274
)
281275
.filter(release_id=release.id)
282276
.annotate(
283-
headline=search("title", search_query),
284-
highlight=search(
285-
KeyTextTransform("body", "metadata"),
277+
headline=SearchHeadline(
278+
"title",
286279
search_query,
280+
start_sel=START_SEL,
281+
stop_sel=STOP_SEL,
282+
config=models.F("config"),
287283
),
288-
searched_python_objects=search(
289-
KeyTextTransform("python_objects_search", "metadata"),
284+
highlight=SearchHeadline(
285+
KeyTextTransform("body", "metadata"),
290286
search_query,
291-
highlight_all=True,
287+
start_sel=START_SEL,
288+
stop_sel=STOP_SEL,
289+
config=models.F("config"),
292290
),
293291
breadcrumbs=models.F("metadata__breadcrumbs"),
294-
python_objects=models.F("metadata__python_objects"),
295292
)
296293
.only(
297294
"path",

docs/templates/docs/search_results.html

-15
Original file line numberDiff line numberDiff line change
@@ -48,21 +48,6 @@ <h2 class="result-title">
4848
{% if result.highlight %}
4949
…&nbsp;{{ result.highlight|cut:"¶"|safe }}&nbsp;…
5050
{% endif %}
51-
{% code_links result.searched_python_objects result.python_objects as result_code_links %}
52-
{% if result_code_links %}
53-
<ul class="code-links">
54-
{% for name, value in result_code_links.items %}
55-
<li>
56-
<a href="{% url 'document-detail' lang=result.release.lang version=result.release.version url=result.path host 'docs' %}#{{ value.full_path }}">
57-
<div>
58-
<code>{{ name }}</code>
59-
{% if value.module_path %}<div class="meta">{{ value.module_path }}</div>{% endif %}
60-
</div>
61-
</a>
62-
</li>
63-
{% endfor %}
64-
</ul>
65-
{% endif %}
6651
</dd>
6752
{% endfor %}
6853
</dl>

docs/templatetags/docs.py

+1-66
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
from ..forms import DocSearchForm
1313
from ..models import DocumentRelease
1414
from ..search import START_SEL, STOP_SEL
15-
from ..utils import get_doc_path, get_doc_root, get_module_path
15+
from ..utils import get_doc_path, get_doc_root
1616

1717
register = template.Library()
1818

@@ -121,68 +121,3 @@ def generate_scroll_to_text_fragment(highlighted_text):
121121
# Due to Python code such as timezone.now(), remove the space after a bracket.
122122
single_spaced = re.sub(r"([(\[])\s", r"\1", single_spaced)
123123
return f"#:~:text={quote(single_spaced)}"
124-
125-
126-
@register.simple_tag
127-
def code_links(searched_python_objects, python_objects):
128-
"""
129-
Processes a highlighted search result (from a `SearchHeadline` annotation)
130-
to extract Python object references and map them to their full paths.
131-
132-
Args:
133-
searched_python_objects (str):
134-
A string from a `SearchHeadline` queryset annotation, containing
135-
highlighted Python object names wrapped with `START_SEL` and `STOP_SEL`.
136-
Example:
137-
"QuerySet {START_SEL}select_related{STOP_SEL} prefetch_related"
138-
139-
python_objects (dict):
140-
A dictionary mapping object short names to their full path. This is
141-
generated from PythonObjectsJSONHTMLBuilder.
142-
Example:
143-
{
144-
"QuerySet": "django.db.models.query.QuerySet",
145-
"QuerySet.select_related": (
146-
"django.db.models.query.QuerySet.select_related"
147-
),
148-
"QuerySet.prefetch_related": (
149-
"django.db.models.query.QuerySet.prefetch_related"
150-
),
151-
}
152-
153-
Returns:
154-
dict: A sorted dictionary where:
155-
- Keys are matched Python object short names.
156-
- Values are dictionaries containing:
157-
- `"full_path"` (str): The full path of the object.
158-
- `"module_path"` (str): The module path derived from the object name.
159-
Example:
160-
{
161-
"QuerySet.select_related": {
162-
"full_path": "django.db.models.query.QuerySet.select_related",
163-
"module_path": "django.db.models.query",
164-
}
165-
}
166-
"""
167-
if not searched_python_objects or START_SEL not in searched_python_objects:
168-
return {}
169-
python_objects_matched_short_names = [
170-
word.replace(START_SEL, "").replace(STOP_SEL, "")
171-
for word in searched_python_objects.split(" ")
172-
if START_SEL in word
173-
]
174-
matched_reference = {}
175-
# Map "select_related" to "QuerySet.select_related" in code_references.
176-
reference_map = {key.split(".")[-1]: key for key in python_objects.keys()}
177-
for short_name in python_objects_matched_short_names:
178-
if full_path := python_objects.get(short_name):
179-
matched_reference[short_name] = {
180-
"full_path": full_path,
181-
"module_path": get_module_path(short_name, full_path),
182-
}
183-
elif name := reference_map.get(short_name):
184-
matched_reference[name] = {
185-
"full_path": python_objects[name],
186-
"module_path": get_module_path(name, python_objects[name]),
187-
}
188-
return dict(sorted(matched_reference.items()))

0 commit comments

Comments
 (0)