mirror of
https://codeberg.org/rimu/pyfedi
synced 2025-01-24 03:43:42 -08:00
topic paths #145
This commit is contained in:
parent
160725b207
commit
6485f201d3
2 changed files with 17 additions and 1 deletions
|
@ -292,6 +292,18 @@ class Topic(db.Model):
|
||||||
parent_id = db.Column(db.Integer)
|
parent_id = db.Column(db.Integer)
|
||||||
communities = db.relationship('Community', lazy='dynamic', backref='topic', cascade="all, delete-orphan")
|
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):
|
class Community(db.Model):
|
||||||
query_class = FullTextSearchQuery
|
query_class = FullTextSearchQuery
|
||||||
|
|
|
@ -10,7 +10,11 @@
|
||||||
{% if len(topics) > 0 %}
|
{% if len(topics) > 0 %}
|
||||||
{% macro render_topic(topic, depth) %}
|
{% macro render_topic(topic, depth) %}
|
||||||
<tr>
|
<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>
|
</tr>
|
||||||
{% if topic['children'] %}
|
{% if topic['children'] %}
|
||||||
{% for topic in topic['children'] %}
|
{% for topic in topic['children'] %}
|
||||||
|
|
Loading…
Add table
Reference in a new issue