tree view for topics
This commit is contained in:
parent
c50d047233
commit
deae2d39e5
7 changed files with 48 additions and 3 deletions
0
markdownblog/blog/templatetags/__init__.py
Normal file
0
markdownblog/blog/templatetags/__init__.py
Normal file
16
markdownblog/blog/templatetags/tree_utils.py
Normal file
16
markdownblog/blog/templatetags/tree_utils.py
Normal 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)
|
||||
|
|
@ -15,7 +15,8 @@ def viewblog(request) -> HttpResponse:
|
|||
|
||||
@login_required
|
||||
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
|
||||
|
|
@ -42,7 +43,6 @@ def addpost(request) -> HttpResponse:
|
|||
|
||||
|
||||
def createmocks(request, objtype, n) -> HttpResponse:
|
||||
|
||||
topics = TopicFactory.create_batch(n)
|
||||
|
||||
for topic in topics:
|
||||
|
|
|
|||
11
markdownblog/markdownblog/static/order_style.css
Normal file
11
markdownblog/markdownblog/static/order_style.css
Normal 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;
|
||||
}
|
||||
|
|
@ -37,7 +37,7 @@
|
|||
<div class="divider"></div>
|
||||
</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>
|
||||
<a class="waves-effect" href="{% url 'admin:index' %}">Mock Posts</a>
|
||||
|
|
|
|||
|
|
@ -4,6 +4,12 @@
|
|||
Order Topics
|
||||
{% endblock %}
|
||||
{% block includehere %}
|
||||
<link rel="stylesheet" href="{% static 'order_style.css' %}">
|
||||
{% endblock %}
|
||||
{% block content %}
|
||||
<ul>
|
||||
{% for topic in roottopics %}
|
||||
{% include "blog/tree_view_template.html" %}
|
||||
{% endfor %}
|
||||
</ul>
|
||||
{% endblock %}
|
||||
|
|
@ -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>
|
||||
Loading…
Add table
Add a link
Reference in a new issue