Skip to content

Commit 7a0222c

Browse files
committed
Allow special "materials" without an URL (lessons with titles only)
Fixes: #207
1 parent e88d8da commit 7a0222c

3 files changed

Lines changed: 27 additions & 1 deletion

File tree

naucse/models.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,11 @@ def material(root, path, info):
183183
page = lesson.pages[info.get("page", "index")]
184184
return PageMaterial(root, path, page, info.get("type", "lesson"), info.get("title"))
185185
elif "url" in info:
186-
return UrlMaterial(root, path, info["url"], info["title"], info.get("type"))
186+
url = info["url"]
187+
if url:
188+
return UrlMaterial(root, path, url, info["title"], info.get("type"))
189+
else:
190+
return SpecialMaterial(root, path, info["title"], info.get("type"))
187191
else:
188192
raise ValueError("Unknown material type: {}".format(info))
189193

@@ -245,6 +249,17 @@ def __init__(self, root, path, url, title, url_type):
245249
self.title = title
246250

247251

252+
class SpecialMaterial(Material):
253+
prev = None
254+
next = None
255+
type = "special"
256+
has_navigation = False
257+
258+
def __init__(self, root, path, title, url_type):
259+
super().__init__(root, path, url_type)
260+
self.title = title
261+
262+
248263
def merge_dict(base, patch):
249264
"""Recursively merge `patch` into `base`
250265

naucse/templates/_material_macros.html

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
{{- bytesize_icon('eye') -}}
88
{%- elif material.url_type == 'homework' -%}
99
{{- bytesize_icon('edit') -}}
10+
{%- elif material.url_type == 'special' -%}
11+
{{- bytesize_icon('flag') -}}
1012
{%- else %}
1113
{{- bytesize_icon('link') -}}
1214
{%- endif -%}
@@ -19,10 +21,14 @@
1921
{% else %}
2022
{% set url=material.url %}
2123
{% endif %}
24+
{% if url is defined %}
2225
<a href="{{ url }}">
26+
{% endif %}
2327
{{- icon_for_material(material) -}}
2428
{{- material.title -}}
29+
{% if url is defined %}
2530
</a>
31+
{% endif %}
2632
</li>
2733
{%- endmacro -%}
2834

runs/2017/pyladies-brno-podzim-po/info.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,11 @@ plan:
108108

109109
- base: dict
110110
date: 2017-11-20
111+
materials:
112+
- title: Turnaj v piškvorkách
113+
url: null
114+
type: special
115+
- +merge
111116

112117
- base: pyglet
113118
date: 2017-11-27

0 commit comments

Comments
 (0)