Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 18 additions & 2 deletions pythonpro/domain/content_statistics_domain.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,11 @@
from pythonpro.dashboard.models import TopicInteraction
from pythonpro.email_marketing import facade as email_marketing_facade
from pythonpro.modules.facade import (
get_entire_content_forest, get_topic_with_contents_by_id, get_tree, topics_user_interacted_queryset,
get_entire_content_forest,
get_topic_with_contents_by_id,
get_tree,
topics_user_interacted_queryset,
get_tree_by_module_slug,
)

__all = [
Expand Down Expand Up @@ -54,9 +58,21 @@ def calculate_modules_progresses(user):
return _calculate_modules_statistics(modules, user)


def calculate_module_progresses_using_slug(user, module_slug):
"""
Calculate the user progress on this module
:param module_slug: Module slug progresses will be calculated
:param user:
:return:
"""

module = get_tree_by_module_slug(module_slug)
return _calculate_modules_statistics([module], user)[0]


def calculate_module_progresses(user, module):
"""
Calculate the user progress on all modules
Calculate the user progress on this module
:param module: Module progresses will be calculated
:param user:
:return:
Expand Down
8 changes: 8 additions & 0 deletions pythonpro/modules/facade.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
'get_entire_content_forest',
'get_tree',
'topics_user_interacted_queryset',
'get_tree_by_module_slug',
'add_modules_purchase_link'
]


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

return modules


def get_tree_by_module_slug(module_slug: str):
module = _Module.objects.get(slug=module_slug)
module.sections = get_tree(module)
return module
3 changes: 2 additions & 1 deletion pythonpro/modules/modules_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@
from django.shortcuts import render
from rolepermissions.checkers import has_object_permission

from pythonpro.domain.content_statistics_domain import calculate_module_progresses_using_slug
from pythonpro.email_marketing.facade import tag_as
from pythonpro.modules.facade import get_all_modules, get_module_with_contents, add_modules_purchase_link


@login_required
def detail(request, slug):
module = get_module_with_contents(slug)
module = calculate_module_progresses_using_slug(request.user, slug)
return render(request, 'modules/module_detail.html', context={'module': module})


Expand Down
31 changes: 28 additions & 3 deletions pythonpro/modules/templates/modules/module_detail.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,13 @@
<div class="container">
<div class="row mb-5">
<div class="col">
<h1 class="mt-4 mb-3">{{ module.title }}</h1>
<h1 class="mt-4 mb-3">{{ module.title }} -
{% if module.finished_topics_count == module.topics_count %}
<span class="badge badge-pill btn-success">{{ module.finished_topics_count }}/{{ module.topics_count }}</span>
{% else %}
<span class="badge badge-pill btn-danger">{{ module.finished_topics_count }}/{{ module.topics_count }}</span>
{% endif %}
</h1>
<dt>Objetivo</dt>
<dd>
<ul>
Expand Down Expand Up @@ -40,15 +46,34 @@ <h1 class="mt-4 mb-3">{{ module.title }}</h1>
<dd>
<ol>
{% for section in module.sections %}
<li><a href="{{ section.get_absolute_url }}">{{ section.title }}</a></li>
<li><a href="{{ section.get_absolute_url }}">{{ section.title }}</a> -
{% if section.finished_topics_count == section.topics_count %}
<span class="badge badge-pill btn-success">{{ section.finished_topics_count }}/{{ section.topics_count }}</span>
{% else %}
<span class="badge badge-pill btn-danger">{{ section.finished_topics_count }}/{{ section.topics_count }}</span>
{% endif %}
</li>
<dd>
<ol>
{% for chapter in section.chapters %}
<li><a href="{{ chapter.get_absolute_url }}">{{ chapter.title }}</a></li>
<li><a href="{{ chapter.get_absolute_url }}">{{ chapter.title }} -
{% if chapter.finished_topics_count == chapter.topics_count %}
<span class="badge badge-pill btn-success">{{ chapter.finished_topics_count }}/{{ chapter.topics_count }}</span>
{% else %}
<span class="badge badge-pill btn-danger">{{ chapter.finished_topics_count }}/{{ chapter.topics_count }}</span>
{% endif %}
</a></li>
<dd>
<ol>
{% for topic in chapter.topics %}
<li><a href="{{ topic.get_absolute_url }}">{{ topic.title }}</a>
{% if topic.finished_topics_count == 1 %}
-
<span class="badge badge-pill badge-success">✓</span>
{% else %}
-
<span class="badge badge-pill badge-danger">X</span>
{% endif %}
</li>
{% empty %}
<li>Nenhuma aula foi definida ainda</li>
Expand Down