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
4 changes: 2 additions & 2 deletions cbv/templates/cbv/klass_detail.html
Original file line number Diff line number Diff line change
Expand Up @@ -114,10 +114,10 @@ <h2>Attributes</h2>
</code>
</td>
<td>
{% if attribute.klass_id == class.db_id %}
{% if not attribute.class_url %}
{{ class.name }}
{% else %}
<a href="{{ attribute.klass.get_absolute_url }}">{{ attribute.klass.name }}</a>
<a href="{{ attribute.class_url }}">{{ attribute.class_name }}</a>
{% endif %}
</td>
</tr>
Expand Down
24 changes: 23 additions & 1 deletion cbv/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,14 @@ class MethodInstance:
kwargs: str
namesakes: Sequence[MethodInstance]

@attrs.frozen
class Attribute:
name: str
value: str
overridden: bool
class_url: str | None
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Same question here, about using empty string instead of None

class_name: str

def get_context_data(self, **kwargs):
qs = Klass.objects.filter(
name__iexact=self.kwargs["klass"],
Expand Down Expand Up @@ -123,10 +131,24 @@ def get_context_data(self, **kwargs):
)
for method in klass.get_methods()
]
attributes = [
self.Attribute(
name=attribute.name,
value=attribute.value,
overridden=hasattr(attribute, "overridden"),
class_url=(
attribute.klass.get_absolute_url()
if attribute.klass_id != klass.id
else None
),
class_name=attribute.klass.name,
)
for attribute in self._get_prepared_attributes(klass)
]
return {
"all_ancestors": ancestors,
"all_children": children,
"attributes": self._get_prepared_attributes(klass),
"attributes": attributes,
"canonical_url": self.request.build_absolute_uri(canonical_url_path),
"class": class_data,
"methods": methods,
Expand Down