Skip to content

Commit e0c86e7

Browse files
committed
Use a macro for material_list
1 parent 8027d72 commit e0c86e7

4 files changed

Lines changed: 18 additions & 38 deletions

File tree

naucse/templates/_macros.html

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,13 @@
2525
</a>
2626
</li>
2727
{%- endmacro -%}
28+
29+
{%- macro material_list(materials, filter_type=None) %}
30+
<ul>
31+
{% for mat in materials %}
32+
{% if filter_type == None or mat.url_type == filter_type %}
33+
{{ material_li(mat) }}
34+
{% endif %}
35+
{% endfor %}
36+
</ul>
37+
{%- endmacro -%}

naucse/templates/backpage.html

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{% extends "_base.html" %}
2-
{% from "_macros.html" import material_li %}
2+
{% from "_macros.html" import material_list with context %}
33

44
{% block content %}
55

@@ -22,25 +22,12 @@ <h1>
2222

2323
{% if homework_section %}
2424
<h2>Domácí projekty</h2>
25-
<ul>
26-
{% for mat in session.materials %}
27-
{% if mat.url_type == "homework" %}
28-
{{ material_li(mat) }}
29-
{% endif %}
30-
{% endfor %}
31-
</ul>
25+
{{ material_list(session.materials, filter_type='homework') }}
3226
{% endif %}
3327

3428
{% if link_section %}
3529
<h2>Zajímavé odkazy</h2>
36-
37-
<ul>
38-
{% for mat in session.materials %}
39-
{% if mat.url_type == "link" %}
40-
{{ material_li(mat) }}
41-
{% endif %}
42-
{% endfor %}
43-
</ul>
30+
{{ material_list(session.materials, filter_type='link') }}
4431
{% endif %}
4532

4633
{% block coverpage_content %}

naucse/templates/course.html

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{% extends "_base.html" %}
2-
{% from "_macros.html" import material_li %}
2+
{% from "_macros.html" import material_list with context %}
33

44
{% macro session_heading(session, index, plan) %}
55
{% if plan|length > 1 %}
@@ -46,11 +46,7 @@ <h4>
4646
{{ session_heading(session, loop.index, plan) }}
4747
</a>
4848
</h4>
49-
<ul>
50-
{% for mat in session.materials %}
51-
{{ material_li(mat) }}
52-
{% endfor %}
53-
</ul>
49+
{{ material_list(session.materials) }}
5450
</div>
5551
{% endfor %}
5652

naucse/templates/coverpage.html

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{% extends "_base.html" %}
2-
{% from "_macros.html" import material_li %}
2+
{% from "_macros.html" import material_list with context %}
33

44
{% block content %}
55

@@ -29,24 +29,11 @@ <h1>
2929
{% endif %}
3030

3131
<h2>Materiály</h2>
32-
<ul>
33-
{% for mat in session.materials %}
34-
{% if mat.url_type == "lesson" %}
35-
{{ material_li(mat) }}
36-
{% endif %}
37-
{% endfor %}
38-
</ul>
32+
{{ material_list(session.materials, filter_type='lesson') }}
3933

4034
{% if cheatsheet_section %}
4135
<h2>Taháky</h2>
42-
43-
<ul>
44-
{% for mat in session.materials %}
45-
{% if mat.url_type == "cheatsheet" %}
46-
{{ material_li(mat) }}
47-
{% endif %}
48-
{% endfor %}
49-
</ul>
36+
{{ material_list(session.materials, filter_type='cheatsheet') }}
5037
{% endif %}
5138

5239
{% block coverpage_content %}

0 commit comments

Comments
 (0)