-
Notifications
You must be signed in to change notification settings - Fork 64
/
plugin_settings.py
executable file
·82 lines (67 loc) · 2.53 KB
/
plugin_settings.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
__copyright__ = "Copyright 2017 Birkbeck, University of London"
__author__ = "Martin Paul Eve & Andy Byers"
__license__ = "AGPL v3"
__maintainer__ = "Birkbeck Centre for Technology and Publishing"
from django.db.utils import OperationalError
from django.contrib.contenttypes.models import ContentType
from utils import models
PLUGIN_NAME = 'HTML'
DESCRIPTION = 'This is a homepage element that renders an HTML block'
AUTHOR = 'Andy Byers'
VERSION = 1.0
def install():
import core.models as core_models
import journal.models as journal_models
import press.models as press_models
# check whether this homepage element has
# already been installed for all journals
journals = journal_models.Journal.objects.all()
for journal in journals:
content_type = ContentType.objects.get_for_model(journal)
element, created = core_models.HomepageElement.objects.get_or_create(
name=PLUGIN_NAME,
configure_url='html_settings',
template_path='journal/homepage_elements/html_block.html',
content_type=content_type,
object_id=journal.pk,
has_config=True)
element.save()
presses = press_models.Press.objects.all()
for press in presses:
content_type = ContentType.objects.get_for_model(press)
element, created = core_models.HomepageElement.objects.get_or_create(
name=PLUGIN_NAME,
configure_url='html_settings',
template_path='journal/homepage_elements/html_block.html',
content_type=content_type,
object_id=press.pk,
has_config=True,
available_to_press=True)
element.save()
plugin, c = models.Plugin.objects.get_or_create(
name=PLUGIN_NAME,
version=VERSION,
enabled=True,
display_name='HTML',
press_wide=True,
)
models.PluginSetting.objects.get_or_create(
name='html_block_content',
plugin=plugin,
defaults={
'pretty_name': 'HTML Block Content',
'types': 'rich-text',
'description': DESCRIPTION,
'is_translatable': True,
}
)
def hook_registry():
try:
return {'yield_homepage_element_context': {'module': 'core.homepage_elements.html.hooks',
'function': 'yield_homepage_element_context'}
}
except OperationalError:
# if we get here the database hasn't yet been created
return {}
except BaseException:
return {}