Skip to content

Commit 7c484b8

Browse files
renzonrenzon
authored andcommitted
Included Module path to sections and chapters
close #1690
1 parent 1be7fc4 commit 7c484b8

12 files changed

Lines changed: 95 additions & 25 deletions

pythonpro/modules/chapters_urls.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,5 @@
44

55
app_name = 'chapters'
66
urlpatterns = [
7-
path('<slug:slug>/', chapters_views.detail, name='detail'),
7+
path('<slug:chapter_slug>/', chapters_views.detail_old, name='detail_old'),
88
]
Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,16 @@
11
from django.contrib.auth.decorators import login_required
2-
from django.shortcuts import render
2+
from django.shortcuts import render, redirect
33

44
from pythonpro.modules import facade
55

66

77
@login_required
8-
def detail(request, slug):
9-
ctx = {'chapter': facade.get_chapter_with_contents(slug=slug)}
8+
def detail_old(request, chapter_slug):
9+
chapter = facade.get_chapter_with_contents(slug=chapter_slug)
10+
return redirect(chapter.get_absolute_url(), permanent=True)
11+
12+
13+
@login_required
14+
def detail(request, module_slug, chapter_slug):
15+
ctx = {'chapter': facade.get_chapter_with_contents(slug=chapter_slug)}
1016
return render(request, 'chapters/chapter_detail.html', context=ctx)

pythonpro/modules/models.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ class Meta:
129129
ordering = ['module', 'order']
130130

131131
def get_absolute_url(self):
132-
return reverse('sections:detail', kwargs={'slug': self.slug})
132+
return reverse('modules:section_detail', kwargs={'section_slug': self.slug, 'module_slug': self.module_slug()})
133133

134134
def parent(self):
135135
return self.module
@@ -149,7 +149,7 @@ class Meta:
149149
ordering = ['section', 'order']
150150

151151
def get_absolute_url(self):
152-
return reverse('chapters:detail', kwargs={'slug': self.slug})
152+
return reverse('modules:chapter_detail', kwargs={'chapter_slug': self.slug, 'module_slug': self.module_slug()})
153153

154154
def parent(self):
155155
return self.section

pythonpro/modules/module_urls.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
from django.urls import path
22

3-
from . import modules_views, topics_views
3+
from . import modules_views, sections_views, topics_views, chapters_views
44

55
app_name = 'modules'
66
urlpatterns = [
77
path('', modules_views.index, name='index'),
88
path('<slug:slug>/', modules_views.detail, name='detail'),
99
path('enrol/<slug:slug>/', modules_views.enrol, name='enrol'),
1010
path('<slug:module_slug>/topicos/<slug:topic_slug>', topics_views.detail, name='topic_detail'),
11+
path('<slug:module_slug>/secoes/<slug:section_slug>', sections_views.detail, name='section_detail'),
12+
path('<slug:module_slug>/capitulos/<slug:chapter_slug>', chapters_views.detail, name='chapter_detail'),
1113
]

pythonpro/modules/sections_urls.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,5 @@
44

55
app_name = 'sections'
66
urlpatterns = [
7-
path('<slug:slug>/', sections_views.detail, name='detail'),
7+
path('<slug:slug>/', sections_views.detail_old, name='detail_old'),
88
]
Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,16 @@
11
from django.contrib.auth.decorators import login_required
2-
from django.shortcuts import render
2+
from django.shortcuts import redirect, render
33

44
from pythonpro.modules import facade
55

66

77
@login_required
8-
def detail(request, slug):
9-
ctx = {'section': facade.get_section_with_contents(slug=slug)}
8+
def detail_old(request, slug):
9+
section = facade.get_section_with_contents(slug=slug)
10+
return redirect(section.get_absolute_url(), permanent=True)
11+
12+
13+
@login_required
14+
def detail(request, module_slug, section_slug):
15+
ctx = {'section': facade.get_section_with_contents(slug=section_slug)}
1016
return render(request, 'sections/section_detail.html', ctx)

pythonpro/modules/tests/test_chapters_view.py

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from model_mommy import mommy
44

55
from pythonpro.django_assertions import dj_assert_contains
6-
from pythonpro.modules.models import Section, Module, Chapter
6+
from pythonpro.modules.models import Chapter, Module, Section
77

88

99
@pytest.fixture
@@ -27,10 +27,13 @@ def chapters(section):
2727

2828

2929
@pytest.fixture
30-
def resp_section(client, django_user_model, section, chapters):
30+
def resp_section(client, django_user_model, section: Section, chapters):
3131
user = mommy.make(django_user_model)
3232
client.force_login(user)
33-
return client.get(reverse('sections:detail', kwargs={'slug': section.slug}))
33+
return client.get(reverse(
34+
'modules:section_detail',
35+
kwargs={'section_slug': section.slug, 'module_slug': section.module_slug()}),
36+
secure=True)
3437

3538

3639
def test_chapter_title_on_section(resp_section, chapters):
@@ -44,10 +47,27 @@ def test_chapter_url_on_section(resp_section, chapters):
4447

4548

4649
@pytest.fixture
47-
def resp(client, chapter, django_user_model):
50+
def resp_old_path(client_with_lead, chapter, django_user_model):
51+
return client_with_lead.get(
52+
reverse('chapters:detail_old', kwargs={'chapter_slug': chapter.slug}), secure=True)
53+
54+
55+
def test_redirect_status_code(resp_old_path):
56+
assert resp_old_path.status_code == 301
57+
58+
59+
def test_redirect_url(resp_old_path, chapter):
60+
assert resp_old_path.url == chapter.get_absolute_url()
61+
62+
63+
@pytest.fixture
64+
def resp(client, chapter: Chapter, django_user_model):
4865
user = mommy.make(django_user_model)
4966
client.force_login(user)
50-
return client.get(reverse('chapters:detail', kwargs={'slug': chapter.slug}))
67+
return client.get(reverse(
68+
'modules:chapter_detail',
69+
kwargs={'chapter_slug': chapter.slug, 'module_slug': chapter.module_slug()}),
70+
secure=True)
5171

5272

5373
def test_status_code(resp):

pythonpro/modules/tests/test_module_index_view.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ def resp_not_logged(client, modules):
2727

2828

2929
def _resp_not_logged(client, modules):
30-
return client.get(reverse('modules:index'))
30+
return client.get(reverse('modules:index'), secure=True)
3131

3232

3333
def test_status_code_logged(resp):

pythonpro/modules/tests/test_sections_view.py

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from model_mommy import mommy
44

55
from pythonpro.django_assertions import dj_assert_contains
6-
from pythonpro.modules.models import Section, Module
6+
from pythonpro.modules.models import Module, Section
77

88

99
@pytest.fixture
@@ -17,10 +17,27 @@ def section(module):
1717

1818

1919
@pytest.fixture
20-
def resp(client, django_user_model, section):
20+
def resp_old_path(client_with_lead, section, django_user_model):
21+
return client_with_lead.get(
22+
reverse('sections:detail_old', kwargs={'slug': section.slug}), secure=True)
23+
24+
25+
def test_redirect_status_code(resp_old_path):
26+
assert resp_old_path.status_code == 301
27+
28+
29+
def test_redirect_url(resp_old_path, section):
30+
assert resp_old_path.url == section.get_absolute_url()
31+
32+
33+
@pytest.fixture
34+
def resp(client, django_user_model, section: Section):
2135
user = mommy.make(django_user_model)
2236
client.force_login(user)
23-
return client.get(reverse('sections:detail', kwargs={'slug': section.slug}))
37+
return client.get(reverse(
38+
'modules:section_detail',
39+
kwargs={'section_slug': section.slug, 'module_slug': section.module_slug()}),
40+
secure=True)
2441

2542

2643
def test_status_code(resp):

pythonpro/modules/tests/test_topics_view.py

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,11 @@ def topic(chapter):
3434

3535
@pytest.fixture
3636
def resp_chapter(client_with_lead, django_user_model, chapter, topics):
37-
return client_with_lead.get(reverse('chapters:detail', kwargs={'slug': chapter.slug}), secure=True)
37+
return client_with_lead.get(reverse(
38+
'modules:chapter_detail',
39+
kwargs={'chapter_slug': chapter.slug, 'module_slug': chapter.slug}),
40+
secure=True
41+
)
3842

3943

4044
def test_topic_title_on_chapter(resp_chapter, topics):
@@ -47,14 +51,29 @@ def test_topic_url_on_section(resp_chapter, topics):
4751
dj_assert_contains(resp_chapter, topic.get_absolute_url())
4852

4953

54+
@pytest.fixture
55+
def resp_old_path(client_with_lead, topic, django_user_model):
56+
return client_with_lead.get(
57+
reverse('topics:detail_old', kwargs={'slug': topic.slug}),
58+
secure=True)
59+
60+
61+
def test_redirect_status_code(resp_old_path):
62+
assert resp_old_path.status_code == 301
63+
64+
65+
def test_redirect_url(resp_old_path, topic):
66+
assert resp_old_path.url == topic.get_absolute_url()
67+
68+
5069
@pytest.fixture
5170
def resp(client_with_lead, topic, django_user_model):
5271
return client_with_lead.get(
5372
reverse('modules:topic_detail', kwargs={'module_slug': topic.module_slug(), 'topic_slug': topic.slug}),
5473
secure=True)
5574

5675

57-
def test_status_code(resp):
76+
def test_success_status_code(resp):
5877
assert resp.status_code == 200
5978

6079

0 commit comments

Comments
 (0)