tree view for topics

This commit is contained in:
CDaut 2022-06-17 18:30:13 +02:00 committed by CDaut
parent c50d047233
commit deae2d39e5
7 changed files with 48 additions and 3 deletions

View file

@ -0,0 +1,16 @@
from django import template
from blog.models import Topic
from django.db.models import QuerySet
register = template.Library()
@register.filter
def has_children(value) -> bool:
return not len(Topic.objects.filter(rootTopic=value)) == 0
@register.filter
def all_children(value) -> QuerySet:
return Topic.objects.filter(rootTopic=value)

View file

@ -15,7 +15,8 @@ def viewblog(request) -> HttpResponse:
@login_required @login_required
def order(request): def order(request):
return render(request, 'blog/order.html') context = {'roottopics': Topic.objects.all().filter(rootTopic=None)}
return render(request, 'blog/order.html', context)
@login_required @login_required
@ -42,7 +43,6 @@ def addpost(request) -> HttpResponse:
def createmocks(request, objtype, n) -> HttpResponse: def createmocks(request, objtype, n) -> HttpResponse:
topics = TopicFactory.create_batch(n) topics = TopicFactory.create_batch(n)
for topic in topics: for topic in topics:

View file

@ -0,0 +1,11 @@
.topic_list {
}
.topic_list_element {
box-shadow: 3px 3px 11px 4px rgb(231, 231, 231);
-webkit-box-shadow: 3px 3px 11px 4px rgb(231, 231, 231);
-moz-box-shadow: 3px 3px 11px 4px rgb(231, 231, 231);
padding: 0.5em;
margin: 0.5em;
}

View file

@ -37,7 +37,7 @@
<div class="divider"></div> <div class="divider"></div>
</li> </li>
<li> <li>
<a class="waves-effect" href="{% url 'mock' n=10 %}">Mock 10 topics</a> <a class="waves-effect" href="{% url 'mock' object='topic' n=10 %}">Mock 10 topics</a>
</li> </li>
<li> <li>
<a class="waves-effect" href="{% url 'admin:index' %}">Mock Posts</a> <a class="waves-effect" href="{% url 'admin:index' %}">Mock Posts</a>

View file

@ -4,6 +4,12 @@
Order Topics Order Topics
{% endblock %} {% endblock %}
{% block includehere %} {% block includehere %}
<link rel="stylesheet" href="{% static 'order_style.css' %}">
{% endblock %} {% endblock %}
{% block content %} {% block content %}
<ul>
{% for topic in roottopics %}
{% include "blog/tree_view_template.html" %}
{% endfor %}
</ul>
{% endblock %} {% endblock %}

View file

@ -0,0 +1,12 @@
{% load tree_utils %}
<li class="topic_list_element"> {{ topic.name }}
{% if topic|has_children %}
<ul class="topic_list">
{% for child in topic|all_children %}
{% with topic=child template_name="blog/tree_view_template.html" %}
{% include template_name %}
{% endwith %}
{% endfor %}
</ul>
{% endif %}
</li>