/
extension.py
82 lines (63 loc) · 2.78 KB
/
extension.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
74
75
76
77
78
79
80
81
82
from __future__ import unicode_literals
from djblets.webapi.resources import (register_resource_for_model,
unregister_resource_for_model)
from reviewboard.accounts.forms.pages import AccountPageForm
from reviewboard.accounts.pages import AccountPage
from reviewboard.extensions.base import Extension
from reviewboard.extensions.hooks import (AccountPagesHook,
TemplateHook)
from reviewboard.urls import reviewable_url_names
from checklist.resources import (checklist_item_resource, checklist_resource,
checklist_template_resource)
from checklist.models import ChecklistTemplate, ReviewChecklist
class ChecklistAccountPageForm(AccountPageForm):
form_id = 'checklist_accountpage_form'
form_title = 'Manage Checklist Templates'
save_label = None
js_view_class = 'RB.ChecklistAccountPageView'
class ChecklistAccountPage(AccountPage):
page_id = 'checklist_accountpage'
page_title = 'Checklist Templates'
form_classes = [ChecklistAccountPageForm]
class Checklist(Extension):
metadata = {
'Name': 'Review Checklist',
}
js_model_class = 'Checklist.Extension'
css_bundles = {
'css_default': {
'source_filenames': ['css/style.less'],
'apply_to': reviewable_url_names,
},
'accountpage': {
'source_filenames': ['css/accountpage.less'],
'apply_to': 'user-preferences',
},
}
js_bundles = {
'js_default': {
'source_filenames': ['js/models/checklist.js',
'js/models/checklistAPI.js',
'js/views/checklistView.js'],
},
'accountpage': {
'source_filenames': ['js/models/checklist.js',
'js/models/checklistTemplate.js',
'js/views/checklistAccountPageView.js'],
'apply_to': 'user-preferences',
},
}
resources = [checklist_resource, checklist_item_resource,
checklist_template_resource]
def __init__(self, *args, **kwargs):
super(Checklist, self).__init__(*args, **kwargs)
register_resource_for_model(ReviewChecklist, checklist_resource)
register_resource_for_model(ChecklistTemplate,
checklist_template_resource)
TemplateHook(self, 'base-scripts-post', 'checklist/template.html',
apply_to=reviewable_url_names)
AccountPagesHook(self, [ChecklistAccountPage])
def shutdown(self, *args, **kwargs):
super(Checklist, self).shutdown(*args, **kwargs)
unregister_resource_for_model(ReviewChecklist)
unregister_resource_for_model(ChecklistTemplate)