Skip to content

Commit

Permalink
#1020 stops view from trying to create a missing setting which has ca…
Browse files Browse the repository at this point in the history
…used a duplication in some cases.
  • Loading branch information
ajrbyers authored and mauromsl committed Mar 20, 2019
1 parent 9b88af1 commit 7b688a4
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 7 deletions.
12 changes: 8 additions & 4 deletions src/core/homepage_elements/html/plugin_settings.py
Expand Up @@ -19,9 +19,8 @@ def install():
import journal.models as journal_models
import press.models as press_models

print('install for html')

# check whether this homepage element has already been installed for all journals
# check whether this homepage element has
# already been installed for all journals
journals = journal_models.Journal.objects.all()

for journal in journals:
Expand Down Expand Up @@ -62,7 +61,12 @@ def install():
models.PluginSetting.objects.get_or_create(
name='html_block_content',
plugin=plugin,
defaults={'pretty_name': 'HTML Block Content'}
defaults={
'pretty_name': 'HTML Block Content',
'types': 'rich-text',
'description': DESCRIPTION,
'is_translatable': True,
}
)


Expand Down
29 changes: 26 additions & 3 deletions src/core/homepage_elements/html/views.py
Expand Up @@ -14,11 +14,34 @@
@editor_user_required
def html_settings(request):
plugin = models.Plugin.objects.get(name='HTML')
html_block_content = setting_handler.get_plugin_setting(plugin, 'html_block_content', request.journal, create=True,
pretty='HTML Block Content').value

try:
html_block_content = setting_handler.get_plugin_setting(
plugin,
'html_block_content',
request.journal,
create=False,
pretty='HTML Block Content'
).value
except models.PluginSetting.DoesNotExist:
messages.add_message(
request,
messages.ERROR,
"No 'html_block_content' setting found. Have you installed "
"this plugin?",
)
return redirect(
reverse(
'home_settings_index',
)
)

if request.POST:
html_block_content = request.POST.get('html_block_content')
setting_handler.save_plugin_setting(plugin, 'html_block_content', html_block_content, request.journal)
setting_handler.save_plugin_setting(plugin,
'html_block_content',
html_block_content,
request.journal)
messages.add_message(request, messages.INFO, 'HTML Block updated.')
return redirect(reverse('home_settings_index'))

Expand Down

0 comments on commit 7b688a4

Please sign in to comment.