1- from functools import partial
1+ from functools import partial as _partial
22
3- from django .conf import settings
4- from django .core .cache import cache
5- from django .db .models import Prefetch
3+ from django .conf import settings as _settings
4+ from django .core .cache import cache as _cache
5+ from django .db .models import Prefetch as _Prefetch
66
77from pythonpro .modules .models import (
88 Chapter as _Chapter , Module as _Module , Section as _Section , Topic as _Topic ,
99)
1010
11+ __all__ = [
12+ 'get_topic_model' ,
13+ 'get_all_modules' ,
14+ 'get_module_with_contents' ,
15+ 'get_section_with_contents' ,
16+ 'get_chapter_with_contents' ,
17+ 'get_topic_with_contents' ,
18+ 'get_topic_with_contents_by_id' ,
19+ 'get_entire_content_forest' ,
20+ 'get_tree' ,
21+ 'topics_user_interacted_queryset' ,
22+ ]
23+
1124
1225def get_topic_model ():
1326 return _Topic
@@ -18,8 +31,8 @@ def get_all_modules():
1831 Search all modules on database sorted by order
1932 :return: tuple of Module
2033 """
21- lazy_all_modules = partial (tuple , _Module .objects .order_by ('order' ))
22- return cache .get_or_set ('ALL_MODULES' , lazy_all_modules , settings .CACHE_TTL )
34+ lazy_all_modules = _partial (tuple , _Module .objects .order_by ('order' ))
35+ return _cache .get_or_set ('ALL_MODULES' , lazy_all_modules , _settings .CACHE_TTL )
2336
2437
2538def get_module_with_contents (slug ):
@@ -30,10 +43,10 @@ def get_module_with_contents(slug):
3043 """
3144
3245 return _Module .objects .filter (slug = slug ).prefetch_related (
33- Prefetch (
46+ _Prefetch (
3447 'section_set' ,
3548 queryset = _Section .objects .order_by ('order' ).prefetch_related (
36- Prefetch (
49+ _Prefetch (
3750 'chapter_set' ,
3851 queryset = _Chapter .objects .order_by ('order' ),
3952 to_attr = 'chapters'
@@ -50,7 +63,7 @@ def get_section_with_contents(slug):
5063 :return: Section
5164 """
5265 return _Section .objects .filter (slug = slug ).select_related ('module' ).prefetch_related (
53- Prefetch (
66+ _Prefetch (
5467 'chapter_set' ,
5568 queryset = _Chapter .objects .order_by ('order' ),
5669 to_attr = 'chapters'
@@ -66,7 +79,7 @@ def get_chapter_with_contents(slug):
6679 """
6780 return _Chapter .objects .filter (slug = slug ).select_related ('section' ).select_related (
6881 'section__module' ).prefetch_related (
69- Prefetch (
82+ _Prefetch (
7083 'topic_set' ,
7184 queryset = _Topic .objects .order_by ('order' ),
7285 to_attr = 'topics'
@@ -99,13 +112,13 @@ def get_entire_content_forest():
99112 :return:
100113 """
101114 return list (_Module .objects .all ().prefetch_related (
102- Prefetch (
115+ _Prefetch (
103116 'section_set' ,
104117 queryset = _Section .objects .order_by ('order' ).prefetch_related (
105- Prefetch (
118+ _Prefetch (
106119 'chapter_set' ,
107120 queryset = _Chapter .objects .order_by ('order' ).prefetch_related (
108- Prefetch (
121+ _Prefetch (
109122 'topic_set' ,
110123 queryset = _Topic .objects .order_by ('order' ),
111124 to_attr = 'topics'
@@ -124,11 +137,11 @@ def get_tree(module):
124137 :return:
125138 """
126139 sections = list (_Section .objects .filter (module = module ).order_by ('order' ).prefetch_related (
127- Prefetch (
140+ _Prefetch (
128141 'chapter_set' ,
129142 queryset = _Chapter .objects .order_by (
130143 'order' ).prefetch_related (
131- Prefetch (
144+ _Prefetch (
132145 'topic_set' ,
133146 queryset = _Topic .objects .order_by (
134147 'order' ),
0 commit comments