topic paths #145

This commit is contained in:
rimu 2024-04-08 20:01:08 +12:00
parent 160725b207
commit 6485f201d3
2 changed files with 17 additions and 1 deletions

View file

@ -292,6 +292,18 @@ class Topic(db.Model):
parent_id = db.Column(db.Integer)
communities = db.relationship('Community', lazy='dynamic', backref='topic', cascade="all, delete-orphan")
def path(self):
return_value = [self.machine_name]
parent_id = self.parent_id
while parent_id is not None:
parent_topic = Topic.query.get(parent_id)
if parent_topic is None:
break
return_value.append(parent_topic.machine_name)
parent_id = parent_topic.parent_id
return_value = list(reversed(return_value))
return '/'.join(return_value)
class Community(db.Model):
query_class = FullTextSearchQuery

View file

@ -10,7 +10,11 @@
{% if len(topics) > 0 %}
{% macro render_topic(topic, depth) %}
<tr>
<td nowrap="nowrap">{{ '--' * depth }} {{ topic['topic'].name }}</td>
<td nowrap="nowrap">{{ '--' * depth }}
{% if depth == 0 %}<strong>{% endif %}
<a href="/topic/{{ topic['topic'].path() }}">{{ topic['topic'].name }}</a>
{% if depth == 0 %}</strong>{% endif %}
</td>
</tr>
{% if topic['children'] %}
{% for topic in topic['children'] %}