Skip to content

Commit 95dcd43

Browse files
renzonrenzon
authored andcommitted
Implemented user statistics on module tree
close #2271
1 parent 315f904 commit 95dcd43

File tree

4 files changed

+56
-6
lines changed

4 files changed

+56
-6
lines changed

pythonpro/domain/content_statistics_domain.py

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,11 @@
1414
from pythonpro.dashboard.models import TopicInteraction
1515
from pythonpro.email_marketing import facade as email_marketing_facade
1616
from pythonpro.modules.facade import (
17-
get_entire_content_forest, get_topic_with_contents_by_id, get_tree, topics_user_interacted_queryset,
17+
get_entire_content_forest,
18+
get_topic_with_contents_by_id,
19+
get_tree,
20+
topics_user_interacted_queryset,
21+
get_tree_by_module_slug,
1822
)
1923

2024
__all = [
@@ -54,9 +58,21 @@ def calculate_modules_progresses(user):
5458
return _calculate_modules_statistics(modules, user)
5559

5660

61+
def calculate_module_progresses_using_slug(user, module_slug):
62+
"""
63+
Calculate the user progress on this module
64+
:param module_slug: Module slug progresses will be calculated
65+
:param user:
66+
:return:
67+
"""
68+
69+
module = get_tree_by_module_slug(module_slug)
70+
return _calculate_modules_statistics([module], user)[0]
71+
72+
5773
def calculate_module_progresses(user, module):
5874
"""
59-
Calculate the user progress on all modules
75+
Calculate the user progress on this module
6076
:param module: Module progresses will be calculated
6177
:param user:
6278
:return:

pythonpro/modules/facade.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
'get_entire_content_forest',
2121
'get_tree',
2222
'topics_user_interacted_queryset',
23+
'get_tree_by_module_slug',
24+
'add_modules_purchase_link'
2325
]
2426

2527

@@ -193,3 +195,9 @@ def add_modules_purchase_link(modules):
193195
module.purchase_link = purchase_links[module.slug]
194196

195197
return modules
198+
199+
200+
def get_tree_by_module_slug(module_slug: str):
201+
module = _Module.objects.get(slug=module_slug)
202+
module.sections = get_tree(module)
203+
return module

pythonpro/modules/modules_views.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,14 @@
22
from django.shortcuts import render
33
from rolepermissions.checkers import has_object_permission
44

5+
from pythonpro.domain.content_statistics_domain import calculate_module_progresses_using_slug
56
from pythonpro.email_marketing.facade import tag_as
67
from pythonpro.modules.facade import get_all_modules, get_module_with_contents, add_modules_purchase_link
78

89

910
@login_required
1011
def detail(request, slug):
11-
module = get_module_with_contents(slug)
12+
module = calculate_module_progresses_using_slug(request.user, slug)
1213
return render(request, 'modules/module_detail.html', context={'module': module})
1314

1415

pythonpro/modules/templates/modules/module_detail.html

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,13 @@
88
<div class="container">
99
<div class="row mb-5">
1010
<div class="col">
11-
<h1 class="mt-4 mb-3">{{ module.title }}</h1>
11+
<h1 class="mt-4 mb-3">{{ module.title }} -
12+
{% if module.finished_topics_count == module.topics_count %}
13+
<span class="badge badge-pill btn-success">{{ module.finished_topics_count }}/{{ module.topics_count }}</span>
14+
{% else %}
15+
<span class="badge badge-pill btn-danger">{{ module.finished_topics_count }}/{{ module.topics_count }}</span>
16+
{% endif %}
17+
</h1>
1218
<dt>Objetivo</dt>
1319
<dd>
1420
<ul>
@@ -40,15 +46,34 @@ <h1 class="mt-4 mb-3">{{ module.title }}</h1>
4046
<dd>
4147
<ol>
4248
{% for section in module.sections %}
43-
<li><a href="{{ section.get_absolute_url }}">{{ section.title }}</a></li>
49+
<li><a href="{{ section.get_absolute_url }}">{{ section.title }}</a> -
50+
{% if section.finished_topics_count == section.topics_count %}
51+
<span class="badge badge-pill btn-success">{{ section.finished_topics_count }}/{{ section.topics_count }}</span>
52+
{% else %}
53+
<span class="badge badge-pill btn-danger">{{ section.finished_topics_count }}/{{ section.topics_count }}</span>
54+
{% endif %}
55+
</li>
4456
<dd>
4557
<ol>
4658
{% for chapter in section.chapters %}
47-
<li><a href="{{ chapter.get_absolute_url }}">{{ chapter.title }}</a></li>
59+
<li><a href="{{ chapter.get_absolute_url }}">{{ chapter.title }} -
60+
{% if chapter.finished_topics_count == chapter.topics_count %}
61+
<span class="badge badge-pill btn-success">{{ chapter.finished_topics_count }}/{{ chapter.topics_count }}</span>
62+
{% else %}
63+
<span class="badge badge-pill btn-danger">{{ chapter.finished_topics_count }}/{{ chapter.topics_count }}</span>
64+
{% endif %}
65+
</a></li>
4866
<dd>
4967
<ol>
5068
{% for topic in chapter.topics %}
5169
<li><a href="{{ topic.get_absolute_url }}">{{ topic.title }}</a>
70+
{% if topic.finished_topics_count == 1 %}
71+
-
72+
<span class="badge badge-pill badge-success"></span>
73+
{% else %}
74+
-
75+
<span class="badge badge-pill badge-danger">X</span>
76+
{% endif %}
5277
</li>
5378
{% empty %}
5479
<li>Nenhuma aula foi definida ainda</li>

0 commit comments

Comments
 (0)