-
Notifications
You must be signed in to change notification settings - Fork 633
/
kolibri_plugin.py
73 lines (58 loc) · 2.09 KB
/
kolibri_plugin.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
from __future__ import absolute_import
from __future__ import print_function
from __future__ import unicode_literals
from django.urls import reverse
from kolibri.core.auth.constants.user_kinds import ANONYMOUS
from kolibri.core.auth.constants.user_kinds import LEARNER
from kolibri.core.content.hooks import ContentNodeDisplayHook
from kolibri.core.device.utils import allow_learner_unassigned_resource_access
from kolibri.core.device.utils import get_device_setting
from kolibri.core.device.utils import is_landing_page
from kolibri.core.device.utils import LANDING_PAGE_LEARN
from kolibri.core.hooks import NavigationHook
from kolibri.core.hooks import RoleBasedRedirectHook
from kolibri.core.webpack import hooks as webpack_hooks
from kolibri.plugins import KolibriPluginBase
from kolibri.plugins.hooks import register_hook
class Learn(KolibriPluginBase):
untranslated_view_urls = "api_urls"
translated_view_urls = "urls"
@register_hook
class LearnRedirect(RoleBasedRedirectHook):
@property
def roles(self):
if is_landing_page(LANDING_PAGE_LEARN):
return (ANONYMOUS, LEARNER)
return (LEARNER,)
@property
def url(self):
return self.plugin_url(Learn, "learn")
@register_hook
class LearnNavItem(NavigationHook):
bundle_id = "side_nav"
@register_hook
class LearnAsset(webpack_hooks.WebpackBundleHook):
bundle_id = "app"
@property
def plugin_data(self):
return {
"allowGuestAccess": get_device_setting("allow_guest_access"),
"allowLearnerUnassignedResourceAccess": allow_learner_unassigned_resource_access(),
}
@register_hook
class LearnContentNodeHook(ContentNodeDisplayHook):
def node_url(self, node):
kind_slug = None
if not node.parent:
kind_slug = ""
elif node.kind == "topic":
kind_slug = "t/"
else:
kind_slug = "c/"
if kind_slug is not None:
return (
reverse("kolibri:kolibri.plugins.learn:learn")
+ "#/topics/"
+ kind_slug
+ node.id
)