diff --git a/src/core/homepage_elements/news/forms.py b/src/core/homepage_elements/news/forms.py index 5eadcbfa85..21264afea2 100644 --- a/src/core/homepage_elements/news/forms.py +++ b/src/core/homepage_elements/news/forms.py @@ -9,7 +9,10 @@ class NewsForm(forms.Form): help_text='Number of news articles to display on the homepage.' ) display_images = forms.BooleanField( - help_text='When enabled the News Plugin will display news images.' + help_text='When enabled the News Plugin will display news images. ' + 'Note: this setting has no effect on the clean theme ' + 'which does not display images for news.', + required=False ) def __init__(self, *args, **kwargs): @@ -28,4 +31,21 @@ def __init__(self, *args, **kwargs): self.fields['number_of_articles'].initial = number_of_articles.value self.fields['display_images'].initial = True if display_images.value else False + def save(self, commit=True): + number_of_articles = self.cleaned_data.get('number_of_articles') + display_images = self.cleaned_data.get('display_images') + + if commit: + setting_handler.save_setting( + 'plugin:News', + 'number_of_articles', + self.journal, + number_of_articles, + ) + setting_handler.save_setting( + 'plugin:News', + 'display_images', + self.journal, + 'On' if display_images else '', + ) diff --git a/src/core/homepage_elements/news/hooks.py b/src/core/homepage_elements/news/hooks.py index 72d3886ea3..bedc2ed0b4 100755 --- a/src/core/homepage_elements/news/hooks.py +++ b/src/core/homepage_elements/news/hooks.py @@ -21,6 +21,11 @@ def yield_homepage_element_context(request, homepage_elements): request.journal if request.journal else None).value number_of_articles = int( number_of_articles) if number_of_articles else 2 + display_images = setting_handler.get_setting( + 'plugin:News', + 'display_images', + request.journal, + ).value news_items = comms_models.NewsItem.objects.filter( (Q(content_type=request.model_content_type) & Q( @@ -29,6 +34,9 @@ def yield_homepage_element_context(request, homepage_elements): (Q(end_display__gte=timezone.now()) | Q(end_display=None)) ).order_by('-posted')[:number_of_articles] - return {'news_items': news_items} + return { + 'news_items': news_items, + 'display_images': display_images, + } else: return {} diff --git a/src/core/homepage_elements/news/templates/news_settings.html b/src/core/homepage_elements/news/templates/news_settings.html index 611ac60449..648cdd7ba6 100644 --- a/src/core/homepage_elements/news/templates/news_settings.html +++ b/src/core/homepage_elements/news/templates/news_settings.html @@ -14,6 +14,7 @@ {% block body %}