Skip to content

Commit 61f60f9

Browse files
committed
Avoid calling get_ancestors() in template render
We now call it and pass through the result before rendering.
1 parent 50b96b8 commit 61f60f9

6 files changed

Lines changed: 2 additions & 10 deletions

File tree

cbv/templates/cbv/klass_detail.html

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,6 @@ <h1><small>class</small>&nbsp;{{ klass.name }}</h1>
6666
{% block content %}
6767
<div class="span12">
6868
<div class="row">
69-
{% with klass.get_ancestors as direct_ancestors %}
7069
{% for ancestor in all_ancestors %}
7170
{% if forloop.first %}
7271
<div class="span4">
@@ -91,7 +90,6 @@ <h2>Descendants</h2>
9190
<li><a href="{{ child.get_absolute_url }}">{{ child.name }}</a></li>
9291
{% if forloop.last %}</ul></div>{% endif %}
9392
{% endfor %}
94-
{% endwith %}
9593
</div>
9694

9795
<div class="row">

cbv/views.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,13 @@ def get_context_data(self, **kwargs):
4545
nav = nav_builder.get_nav_data(
4646
klass.module.project_version, klass.module, klass
4747
)
48+
direct_ancestors = list(klass.get_ancestors())
4849
return {
4950
"all_ancestors": list(klass.get_all_ancestors()),
5051
"all_children": list(klass.get_all_children()),
5152
"attributes": klass.get_prepared_attributes(),
5253
"canonical_url": self.request.build_absolute_uri(canonical_url_path),
54+
"direct_ancestors": direct_ancestors,
5355
"klass": klass,
5456
"methods": list(klass.get_methods()),
5557
"nav": nav,

tests/_page_snapshots/fuzzy-klass-detail-old.html

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -407,7 +407,6 @@ <h1><small>class</small>&nbsp;FormView</h1>
407407
<div class="row">
408408
<div class="span12">
409409
<div class="row">
410-
411410

412411

413412
<div class="span4">
@@ -484,7 +483,6 @@ <h2>Descendants</h2>
484483
<li><a href="/projects/Django/3.2/django.contrib.auth.views/PasswordResetView/">PasswordResetView</a></li>
485484
</ul></div>
486485

487-
488486
</div>
489487

490488
<div class="row">

tests/_page_snapshots/fuzzy-klass-detail.html

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -407,7 +407,6 @@ <h1><small>class</small>&nbsp;FormView</h1>
407407
<div class="row">
408408
<div class="span12">
409409
<div class="row">
410-
411410

412411

413412
<div class="span4">
@@ -484,7 +483,6 @@ <h2>Descendants</h2>
484483
<li><a href="/projects/Django/4.0/django.contrib.auth.views/PasswordResetView/">PasswordResetView</a></li>
485484
</ul></div>
486485

487-
488486
</div>
489487

490488
<div class="row">

tests/_page_snapshots/klass-detail-old.html

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -403,7 +403,6 @@ <h1><small>class</small>&nbsp;FormView</h1>
403403
<div class="row">
404404
<div class="span12">
405405
<div class="row">
406-
407406

408407

409408
<div class="span4">
@@ -480,7 +479,6 @@ <h2>Descendants</h2>
480479
<li><a href="/projects/Django/3.2/django.contrib.auth.views/PasswordResetView/">PasswordResetView</a></li>
481480
</ul></div>
482481

483-
484482
</div>
485483

486484
<div class="row">

tests/_page_snapshots/klass-detail.html

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -403,7 +403,6 @@ <h1><small>class</small>&nbsp;FormView</h1>
403403
<div class="row">
404404
<div class="span12">
405405
<div class="row">
406-
407406

408407

409408
<div class="span4">
@@ -480,7 +479,6 @@ <h2>Descendants</h2>
480479
<li><a href="/projects/Django/4.0/django.contrib.auth.views/PasswordResetView/">PasswordResetView</a></li>
481480
</ul></div>
482481

483-
484482
</div>
485483

486484
<div class="row">

0 commit comments

Comments
 (0)