diff --git a/pythonpro/modules/facade.py b/pythonpro/modules/facade.py
index a3908b82..8dcaab25 100644
--- a/pythonpro/modules/facade.py
+++ b/pythonpro/modules/facade.py
@@ -5,7 +5,6 @@
from django.db.models import Prefetch as _Prefetch
from django.urls import reverse
-
from pythonpro.modules.models import (
Chapter as _Chapter, Module as _Module, Section as _Section, Topic as _Topic,
)
@@ -50,7 +49,13 @@ def get_module_with_contents(slug):
queryset=_Section.objects.order_by('order').prefetch_related(
_Prefetch(
'chapter_set',
- queryset=_Chapter.objects.order_by('order'),
+ queryset=_Chapter.objects.order_by('order').prefetch_related(
+ _Prefetch(
+ 'topic_set',
+ queryset=_Topic.objects.order_by(
+ 'order'),
+ to_attr='topics')
+ ),
to_attr='chapters'
)
),
@@ -141,13 +146,13 @@ def get_tree(module):
sections = list(_Section.objects.filter(module=module).order_by('order').prefetch_related(
_Prefetch(
'chapter_set',
- queryset=_Chapter.objects.order_by(
- 'order').prefetch_related(
+ queryset=_Chapter.objects.order_by('order').prefetch_related(
_Prefetch(
'topic_set',
queryset=_Topic.objects.order_by(
'order'),
- to_attr='topics')),
+ to_attr='topics')
+ ),
to_attr='chapters')))
module.sections = sections
return sections
diff --git a/pythonpro/modules/templates/modules/module_detail.html b/pythonpro/modules/templates/modules/module_detail.html
index 217c641a..feb38689 100644
--- a/pythonpro/modules/templates/modules/module_detail.html
+++ b/pythonpro/modules/templates/modules/module_detail.html
@@ -19,7 +19,8 @@
{{ module.title }}
Duração: 4 semanas
{% endif %}
@@ -44,15 +45,25 @@ {{ module.title }}
{% for chapter in section.chapters %}
- {{ chapter.title }}
+ -
+
+ {% for topic in chapter.topics %}
+ - {{ topic.title }}
+
+ {% empty %}
+ - Nenhum Capítulo definido ainda
+ {% endfor %}
+
+
{% empty %}
- Nenhum Capítulo definido ainda
{% endfor %}
-
+
{% empty %}
Nenhuma seção definida ainda
{% endfor %}
-
+
diff --git a/pythonpro/modules/tests/test_module_detail_view.py b/pythonpro/modules/tests/test_module_detail_view.py
index 81054a17..917f923e 100644
--- a/pythonpro/modules/tests/test_module_detail_view.py
+++ b/pythonpro/modules/tests/test_module_detail_view.py
@@ -5,7 +5,7 @@
from pythonpro.django_assertions import dj_assert_contains, dj_assert_not_contains, dj_assert_template_used
from pythonpro.modules import facade
-from pythonpro.modules.models import Chapter, Module, Section
+from pythonpro.modules.models import Chapter, Module, Section, Topic
def generate_resp(slug, client):
@@ -97,10 +97,10 @@ def python_birds(modules):
@pytest.fixture
def resp_with_sections(client_with_lead, sections, python_birds):
- return _resp_with_sections(client_with_lead, sections, python_birds)
+ return _resp_module_detail(client_with_lead, python_birds)
-def _resp_with_sections(client_with_lead, sections, python_birds):
+def _resp_module_detail(client_with_lead, python_birds):
"""Plain function to avoid _pytest.warning_types.RemovedInPytest4Warning: Fixture "resp" called directly."""
return client_with_lead.get(reverse('modules:detail', kwargs={'slug': python_birds.slug}))
@@ -125,7 +125,7 @@ def chapters(sections):
@pytest.fixture
def resp_with_chapters(client_with_lead, python_birds, sections, chapters):
- return _resp_with_sections(client_with_lead, sections, python_birds)
+ return _resp_module_detail(client_with_lead, python_birds)
def test_chapter_titles(resp_with_chapters, chapters):
@@ -143,3 +143,26 @@ def test_enrol_user_tags(python_birds, client_with_lead, mocker, logged_user):
resp = client_with_lead.get(reverse('modules:enrol', kwargs={'slug': python_birds.slug}))
tag_as.assert_called_once_with(logged_user.email, logged_user.id, python_birds.slug)
assert resp.status_code == 200
+
+
+@pytest.fixture
+def topics(chapters):
+ result = []
+ for chapter in chapters:
+ result.extend(baker.make(Topic, 2, chapter=chapter))
+ return result
+
+
+@pytest.fixture
+def resp_with_topics(client_with_lead, python_birds, topics):
+ return _resp_module_detail(client_with_lead, python_birds)
+
+
+def test_topic_titles(resp_with_topics, topics):
+ for topic in topics:
+ dj_assert_contains(resp_with_topics, topic.title)
+
+
+def test_topic_urls(resp_with_topics, topics):
+ for topic in topics:
+ dj_assert_contains(resp_with_topics, topic.get_absolute_url())