Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 15 additions & 15 deletions cbv/templates/cbv/klass_detail.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@
{% load static %}


{% block title %}{{ klass.name }}{% endblock %}
{% block title %}{{ class.name }}{% endblock %}


{% block meta_description %}
{{ klass.name }} in {{ project }}.
{% if klass.docstring %}
{{ klass.docstring }}
{{ class.name }} in {{ project }}.
{% if class.docstring %}
{{ class.docstring }}
{% endif %}
{% endblock meta_description %}

Expand Down Expand Up @@ -40,8 +40,8 @@


{% block page_header %}
<h1><small>class</small>&nbsp;{{ klass.name }}</h1>
<pre>from {{ klass.import_path }} import {{ klass.name }}</pre>
<h1><small>class</small>&nbsp;{{ class.name }}</h1>
<pre>from {{ class.import_path }} import {{ class.name }}</pre>
<div class="pull-right">
{% with url=yuml_url %}
{% if url %}
Expand All @@ -50,15 +50,15 @@ <h1><small>class</small>&nbsp;{{ klass.name }}</h1>
<span class="btn btn-small btn-info disabled">{% trans "Hierarchy diagram" %}</span>
{% endif %}
{% endwith %}
{% if klass.docs_url %}
<a class="btn btn-small btn-info" href="{{ klass.docs_url }}">{% trans "Documentation" %}</a>
{% if class.docs_url %}
<a class="btn btn-small btn-info" href="{{ class.docs_url }}">{% trans "Documentation" %}</a>
{% else %}
<span class="btn btn-small btn-info disabled">{% trans "Documentation" %}</span>
{% endif %}
<a class="btn btn-small btn-info" href="{{ klass.get_source_url }}">{% trans "Source code" %}</a>
<a class="btn btn-small btn-info" href="{{ class.source_url }}">{% trans "Source code" %}</a>
</div>
{% if klass.docstring %}
<pre class="docstring">{{ klass.docstring }}</pre>
{% if class.docstring %}
<pre class="docstring">{{ class.docstring }}</pre>
{% endif %}
{% endblock %}

Expand All @@ -70,7 +70,7 @@ <h1><small>class</small>&nbsp;{{ klass.name }}</h1>
<div class="span4">
<h2>Ancestors (<abbr title="Method Resolution Order">MRO</abbr>)</h2>
<ol start='0' id="ancestors">
<li><strong>{{ klass.name }}</strong></li>
<li><strong>{{ class.name }}</strong></li>
{% for ancestor in all_ancestors %}
<li>
<a href="{{ ancestor.url }}" class="{% if ancestor.is_direct %}direct{% endif %}">
Expand Down Expand Up @@ -115,8 +115,8 @@ <h2>Attributes</h2>
</code>
</td>
<td>
{% if attribute.klass == klass %}
{{ attribute.klass.name }}
{% if attribute.klass_id == class.db_id %}
{{ class.name }}
{% else %}
<a href="{{ attribute.klass.get_absolute_url }}">{{ attribute.klass.name }}</a>
{% endif %}
Expand Down Expand Up @@ -151,7 +151,7 @@ <h3>
{% if namesakes|length == 1 %}
<small class="pull-right">{{ method.klass.name }}</small>
{% endif %}
<a class="permalink" href="{{ klass.get_absolute_url }}#{{ method.name }}">&para;</a>
<a class="permalink" href="{{ class.url }}#{{ method.name }}">&para;</a>
</h3>
</summary>
<div id="{{ method.name }}" class="accordion-body">
Expand Down
20 changes: 20 additions & 0 deletions cbv/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,16 @@ def get_redirect_url(self, *, url_name: str, **kwargs):
class KlassDetailView(TemplateView):
template_name = "cbv/klass_detail.html"

@attrs.frozen
class Class:
db_id: int
docs_url: str
docstring: str | None
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could an empty string serve the same falsey/emptiness need as None here, and reduce the number of types?

import_path: str
name: str
source_url: str
url: str

@attrs.frozen
class Ancestor:
name: str
Expand Down Expand Up @@ -56,6 +66,15 @@ def get_context_data(self, **kwargs):
nav = nav_builder.get_nav_data(
klass.module.project_version, klass.module, klass
)
class_data = self.Class(
db_id=klass.id,
name=klass.name,
docstring=klass.docstring,
docs_url=klass.docs_url,
import_path=klass.import_path,
source_url=klass.get_source_url(),
url=klass.get_absolute_url(),
)
direct_ancestors = list(klass.get_ancestors())
ancestors = [
self.Ancestor(
Expand All @@ -77,6 +96,7 @@ def get_context_data(self, **kwargs):
"all_children": children,
"attributes": klass.get_prepared_attributes(),
"canonical_url": self.request.build_absolute_uri(canonical_url_path),
"class": class_data,
"klass": klass,
"methods": list(klass.get_methods()),
"nav": nav,
Expand Down