This repository was archived by the owner on Sep 30, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path__init__.py
More file actions
83 lines (69 loc) · 3.35 KB
/
__init__.py
File metadata and controls
83 lines (69 loc) · 3.35 KB
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
74
75
76
77
78
79
80
81
82
import logging
import json
import os.path
from . import pages
from inginious.frontend.webapp.plugins.utils import create_static_resource_page
_PLUGIN_PATH = os.path.dirname(__file__)
_BASE_RENDERER_PATH = _PLUGIN_PATH
_BASE_STATIC_FOLDER = os.path.join(_PLUGIN_PATH, 'static')
_logger = logging.getLogger("inginious.frontend.webapp.plugins.task_cache")
def tag_selection_tab(course, taskid, task_data, template_helper):
tab_id = 'tab_task_tags'
link = '<i class="fa fa-tags fa-fw"></i> Tags'
template_helper.add_css("https://cdn.jsdelivr.net/bootstrap.tagsinput/0.4.2/bootstrap-tagsinput.css")
template_helper.add_javascript("https://cdn.jsdelivr.net/bootstrap.tagsinput/0.4.2/bootstrap-tagsinput.min.js")
tags = task_data.get('tags', "")
content = template_helper.get_custom_renderer(_BASE_RENDERER_PATH,
layout=False).tags(course, taskid, task_data, tags)
return tab_id, link, content
def init(plugin_manager, course_factory, client, config):
def on_task_updated(courseid, taskid, new_content):
task_name = new_content["name"]
descriptor = course_factory.get_course(courseid)._task_factory.get_task_descriptor_content(courseid, taskid)
task_author = descriptor["author"]
task_context = descriptor["context"]
tags = new_content.get("tags", "").split(',')
task_data = {
"task_name": task_name,
"task_id": taskid,
"task_author": task_author,
"task_context": task_context,
"course_id": courseid,
"tags": tags
}
data_filter = {
"task_id": taskid,
"course_id": courseid
}
plugin_manager.get_database().tasks_cache.update_one(filter=data_filter,
update={"$set": task_data}, upsert=True)
def on_task_deleted(courseid, taskid):
data_filter = {
"task_id": taskid,
"course_id": courseid
}
plugin_manager.get_database().tasks_cache.delete_many(data_filter)
def on_course_deleted(courseid):
data_filter = {
"course_id": courseid
}
plugin_manager.get_database().tasks_cache.delete_many(data_filter)
def on_course_updated(courseid, new_content):
course_data = {
"course_id": new_content["name"]
}
data_filter = {
"course_id": courseid
}
plugin_manager.get_database().tasks_cache.update_many(filter=data_filter,
update={"$set": course_data})
if "tasks_cache" not in plugin_manager.get_database().collection_names():
plugin_manager.get_database().create_collection("tasks_cache")
plugin_manager.get_database().tasks_cache.create_index([("course_id", 1), ("task_id", 1)], unique=True)
plugin_manager.add_page(r'/static/task_cache/(.*)', create_static_resource_page(_BASE_STATIC_FOLDER))
plugin_manager.add_page('/api/tags', pages.TagsApi)
plugin_manager.add_hook('task_editor_tab', tag_selection_tab)
plugin_manager.add_hook('task_updated', on_task_updated)
plugin_manager.add_hook('task_deleted', on_task_deleted)
plugin_manager.add_hook('course_updated', on_course_updated)
plugin_manager.add_hook('course_deleted', on_course_deleted)