Skip to content

Commit 055c694

Browse files
committed
Use the database for docs rendering
1 parent 5dd10c0 commit 055c694

5 files changed

Lines changed: 36 additions & 5 deletions

File tree

docs/management/commands/update_docs.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,9 @@ def zipfile_inclusion_filter(file_path):
278278

279279
json_built_dir = parent_build_dir / "_built" / "json"
280280
documents = gen_decoded_documents(json_built_dir)
281+
with open(json_built_dir / "globalcontext.json") as context:
282+
release.global_context = json.load(context)
283+
release.save()
281284
release.sync_to_db(documents)
282285

283286
def update_git(self, url, destdir, changed_dir="."):
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Generated by Django 6.0.4 on 2026-05-06 09:20
2+
3+
from django.db import migrations, models
4+
5+
6+
class Migration(migrations.Migration):
7+
8+
dependencies = [
9+
("docs", "0007_add_docs_search_vector"),
10+
]
11+
12+
operations = [
13+
migrations.AddField(
14+
model_name="documentrelease",
15+
name="global_context",
16+
field=models.JSONField(default=dict),
17+
),
18+
]

docs/models.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ class DocumentRelease(models.Model):
111111
limit_choices_to={"status": "f"},
112112
on_delete=models.CASCADE,
113113
)
114+
global_context = models.JSONField(default=dict)
114115
is_default = models.BooleanField(default=False)
115116

116117
objects = DocumentReleaseQuerySet.as_manager()

docs/templates/docs/doc.html

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -166,11 +166,11 @@ <h3 id="breadcrumbs-header">{% trans "You are here:" %}</h3>
166166
<ul>
167167
<li>
168168
<a href="{% url 'document-index' lang=lang version=version host 'docs' %}">{% blocktrans %}Django {{ version }} documentation{% endblocktrans %}</a>
169-
{% for p in doc.parents %}
170-
<ul><li><a href="{{ p.link }}">{{ p.title|safe }}</a>
169+
{% for p in doc.breadcrumbs %}
170+
<ul><li><a href="{% url 'document-detail' lang=lang version=version url=p.path host 'docs' %}">{{ p.title|safe }}</a>
171171
{% endfor %}
172172
<ul><li>{% block current-page-title %}{{ doc.title|safe }}{% endblock current-page-title %}</li></ul>
173-
{% for p in doc.parents %}</li></ul>{% endfor %}
173+
{% for p in doc.breadcrumbs %}</li></ul>{% endfor %}
174174
</li>
175175
</ul>
176176
</nav>

docs/views.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,9 +79,18 @@ def load_json_file(path):
7979
version
8080
)
8181

82+
try:
83+
doc = Document.objects.get(
84+
release=release, path__in=[url, f"{url}index"]
85+
).metadata
86+
except Document.DoesNotExist:
87+
# We won't find e.g. the genindex page nor partially
88+
# translated documents in the database.
89+
doc = load_json_file(doc_path)
90+
8291
context = {
83-
"doc": load_json_file(doc_path),
84-
"env": load_json_file(docroot / "globalcontext.json"),
92+
"doc": doc,
93+
"env": release.global_context,
8594
"lang": lang,
8695
"version": version,
8796
"canonical_version": canonical_version,

0 commit comments

Comments
 (0)