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 %}
+ {% include "admin/elements/forms/errors.html" with form=form %}
{% csrf_token %} {{ form|foundation }} diff --git a/src/core/homepage_elements/news/views.py b/src/core/homepage_elements/news/views.py index c3c2bdc6d6..f999a79cf3 100755 --- a/src/core/homepage_elements/news/views.py +++ b/src/core/homepage_elements/news/views.py @@ -9,27 +9,24 @@ @editor_user_required def news_config(request): - plugin = models.Plugin.objects.get(name='News') - number_of_articles = setting_handler.get_plugin_setting( - plugin, - 'number_of_articles', - request.journal, - create=True, - pretty='Number of Articles', - ).value - number_of_articles = int( - number_of_articles - ) if number_of_articles else 2 + form = forms.NewsForm(journal=request.journal) if request.POST: - number_of_articles = request.POST.get('number_of_articles') - setting_handler.save_plugin_setting(plugin, 'number_of_articles', number_of_articles, request.journal) - messages.add_message(request, messages.INFO, 'Number of articles updated.') - return redirect(reverse('home_settings_index')) + form = forms.NewsForm( + request.POST, + journal=request.journal, + ) + if form.is_valid(): + form.save() + messages.add_message( + request, + messages.INFO, + 'News settings updated.' + ) + return redirect(reverse('home_settings_index')) template = 'news_settings.html' context = { - 'number_of_articles': number_of_articles, - 'form': forms.NewsForm(journal=request.journal) + 'form': form, } return render(request, template, context) diff --git a/src/themes/OLH/templates/journal/homepage_elements/news.html b/src/themes/OLH/templates/journal/homepage_elements/news.html index ee307f527b..10cba84e21 100644 --- a/src/themes/OLH/templates/journal/homepage_elements/news.html +++ b/src/themes/OLH/templates/journal/homepage_elements/news.html @@ -8,15 +8,33 @@

{% trans 'Latest' %} {{ journal_settings.news.news_title }} {% trans "Posts" %}

+
{% for item in news_items %} -
{{ item.title }}
-
{{ item.byline }} {% trans "on" %} {{ item.posted|date:"Y-m-d" }}
-

{{ item.body|striptags|truncatesmart:400 }}

- {% trans "Read More" %} -
+ {% if display_images %} + {% if item.large_image_file or request.journal and request.journal.default_large_image or request.press.default_carousel_image %} +
+ {{ item.title }} +
+ {% endif %} + {% endif %} + {% if display_images %} +
+ {% endif %} +
{{ item.title }}
+
{{ item.byline }} {% trans "on" %} {{ item.posted|date:"Y-m-d" }}
+

{{ item.body|striptags|truncatesmart:400 }}

+ {% trans "Read More" %} + {% if display_images %} +
+ {% endif %} +
{% empty %} -

{% trans "This journal currently has no news items to display" %}.

+

{% trans "This journal currently has no news items to display" %}.

{% endfor %} +
diff --git a/src/themes/material/templates/journal/homepage_elements/news.html b/src/themes/material/templates/journal/homepage_elements/news.html index c9d809a39c..93aa05e012 100644 --- a/src/themes/material/templates/journal/homepage_elements/news.html +++ b/src/themes/material/templates/journal/homepage_elements/news.html @@ -11,6 +11,19 @@ {% trans 'Latest' %} {{ journal_settings.news.news_title }} {% trans "Posts" %} {% for item in news_items %} + {% if display_images %} + {% if item.large_image_file or request.journal and request.journal.default_large_image or request.press.default_carousel_image %} +
+ {{ item.title }} + + + +
+ {% endif %} + {% endif %}
{{ item.title }}