diff --git a/pythonpro/domain/content_statistics_domain.py b/pythonpro/domain/content_statistics_domain.py index 817fdcac..1b62e590 100644 --- a/pythonpro/domain/content_statistics_domain.py +++ b/pythonpro/domain/content_statistics_domain.py @@ -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 = [ @@ -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: diff --git a/pythonpro/modules/facade.py b/pythonpro/modules/facade.py index 64824c24..a8a07c05 100644 --- a/pythonpro/modules/facade.py +++ b/pythonpro/modules/facade.py @@ -20,6 +20,8 @@ 'get_entire_content_forest', 'get_tree', 'topics_user_interacted_queryset', + 'get_tree_by_module_slug', + 'add_modules_purchase_link' ] @@ -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 diff --git a/pythonpro/modules/modules_views.py b/pythonpro/modules/modules_views.py index e057ccdf..ddd71aed 100644 --- a/pythonpro/modules/modules_views.py +++ b/pythonpro/modules/modules_views.py @@ -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}) diff --git a/pythonpro/modules/templates/modules/module_detail.html b/pythonpro/modules/templates/modules/module_detail.html index e275674b..56fb8ebe 100644 --- a/pythonpro/modules/templates/modules/module_detail.html +++ b/pythonpro/modules/templates/modules/module_detail.html @@ -8,7 +8,13 @@