-
Notifications
You must be signed in to change notification settings - Fork 2
/
hooks.py
115 lines (86 loc) · 3.79 KB
/
hooks.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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
from django.template.loader import render_to_string
from plugins.archive_plugin import plugin_settings
from utils import models, setting_handler
from plugins.archive_plugin import views
def inject_edit_article(context):
"""
Inject a button into dashboard article management page that allows authors to submit an article update
"""
request = context.get('request')
plugin = models.Plugin.objects.get(name=plugin_settings.SHORT_NAME)
edit_article_enabled = setting_handler.get_plugin_setting(plugin, 'edit_article_enabled', request.journal)
if not edit_article_enabled.value:
return ''
return render_to_string(
'archive_plugin/inject_edit_article.html',
context={'article': context.get('article')},
request=request
)
def inject_article_archive_warning(context):
"""
Injects a warning that an article has a more recent published version available.
"""
request = context.get('request')
plugin = models.Plugin.objects.get(name=plugin_settings.SHORT_NAME)
article_archive_enabled = setting_handler.get_plugin_setting(plugin, 'article_archive_enabled', request.journal)
if not article_archive_enabled.value:
return ''
article = context.get('article')
# If the article has never been updated, return nothing
if not article.updates.exists():
return ''
return render_to_string(
'archive_plugin/inject_article_archive_warning.html',
context={'article': context.get('article')},
request=request
)
def inject_article_archive(context):
"""
Injects a link for the user to browse previous version of an article
"""
request = context.get('request')
plugin = models.Plugin.objects.get(name=plugin_settings.SHORT_NAME)
article_archive_enabled = setting_handler.get_plugin_setting(plugin, 'article_archive_enabled', request.journal)
if not article_archive_enabled.value:
return ''
return render_to_string(
'archive_plugin/inject_article_archive.html',
context={'article': context.get('article')},
request=request
)
def inject_journal_archive(context):
"""
Injects a link for the user to browse a list of previous archives of the encyclopedia
"""
request = context.get('request')
plugin = models.Plugin.objects.get(name=plugin_settings.SHORT_NAME)
journal_archive_enabled = setting_handler.get_plugin_setting(plugin, 'journal_archive_enabled', request.journal)
if not journal_archive_enabled.value:
return ''
return render_to_string('archive_plugin/inject_journal_archive.html', request=request)
def inject_request_edit_update(context):
"""
Injects a button for editors to request that an article be edited
"""
request = context.get('request')
plugin = models.Plugin.objects.get(name=plugin_settings.SHORT_NAME)
edit_article_enabled = setting_handler.get_plugin_setting(plugin, 'edit_article_enabled', request.journal)
if not edit_article_enabled.value:
return ''
return render_to_string(
'archive_plugin/inject_request_edit_update.html',
context={'article': context.get('article')},
request=request
)
def reconfigure_archive_search(context):
"""
captures incoming article_list from search and adds filter to query string to show only latest versions of articles.
"""
request = context.get('request')
plugin = models.Plugin.objects.get(name=plugin_settings.SHORT_NAME)
archive_search_filter_enabled = setting_handler.get_plugin_setting(plugin, 'archive_search_filter_enabled', request.journal)
if archive_search_filter_enabled.value:
articles_qs = context.get('articles')
excluded_articles_qs = views.archive_filter_search(articles_qs)
context['articles'] = excluded_articles_qs
return ""