Skip to content

Commit

Permalink
Merge pull request #3826 from BirkbeckCTP/b_1_5_1
Browse files Browse the repository at this point in the history
merge of b_1_5_1 for RC-3
  • Loading branch information
mauromsl authored Dec 11, 2023
2 parents 3e38359 + 94bd3b4 commit d4cb596
Show file tree
Hide file tree
Showing 53 changed files with 874 additions and 910 deletions.
51 changes: 51 additions & 0 deletions src/core/homepage_elements/news/forms.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
from django import forms

from utils import setting_handler
from core.homepage_elements.popular import plugin_settings, logic


class NewsForm(forms.Form):
number_of_articles = forms.IntegerField(
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. '
'Note: this setting has no effect on the clean theme '
'which does not display images for news.',
required=False
)

def __init__(self, *args, **kwargs):
self.journal = kwargs.pop('journal', None)
super(NewsForm, self).__init__(*args, **kwargs)
number_of_articles = setting_handler.get_setting(
'plugin:News',
'number_of_articles',
self.journal,
)
display_images = setting_handler.get_setting(
'plugin:News',
'display_images',
self.journal,
)
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 '',
)

10 changes: 9 additions & 1 deletion src/core/homepage_elements/news/hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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 {}
12 changes: 12 additions & 0 deletions src/core/homepage_elements/news/plugin_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,18 @@ def install():
setting,
default_value=DEFAULT_NEWS,
)
setting = setting_handler.create_setting(
setting_group_name=plugin_group_name,
setting_name='display_images',
type='boolean',
pretty_name='Display Images',
description='When enabled the News Plugin will display news images.',
is_translatable=False,
)
setting_handler.get_or_create_default_setting(
setting,
default_value='',
)

for journal in journals:
content_type = ContentType.objects.get_for_model(journal)
Expand Down
12 changes: 3 additions & 9 deletions src/core/homepage_elements/news/templates/news_settings.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,12 @@
{% endblock %}

{% block body %}
<div class="large-12 columns">
<div class="large-12 columns box">
{% include "admin/elements/forms/errors.html" with form=form %}
<form method="POST">
{% csrf_token %}
<small>You can set the number of news articles to display.</small>
<input type="number" name="number_of_articles" value="{{ number_of_articles }}">
{{ form|foundation }}
<button type="submit" class="success button">Save</button>
</form>
</div>
{% endblock body %}

{% block js %}
{% include "elements/jqte.html" %}
{% endblock js %}


31 changes: 15 additions & 16 deletions src/core/homepage_elements/news/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,30 +4,29 @@

from utils import setting_handler, models
from security.decorators import editor_user_required
from core.homepage_elements.news import forms


@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': form,
}

return render(request, template, context)
7 changes: 7 additions & 0 deletions src/core/janeway_global_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -600,6 +600,13 @@ def __len__(self):
'clean',
]

# Repository theme setting determines which themes currently
# support repositories.
REPOSITORY_THEMES = [
'OLH',
'material',
]

INSTALLATION_BASE_THEME = 'OLH'

DEFAULT_AUTO_FIELD = 'django.db.models.AutoField'
Expand Down
52 changes: 29 additions & 23 deletions src/journal/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
from utils import setting_handler, logic, install
from utils.function_cache import cache, mutable_cached_property
from utils.logger import get_logger
from review import models as review_models

logger = get_logger(__name__)

Expand Down Expand Up @@ -511,6 +512,28 @@ def description_for_press(self):
setting_name='journal_description',
)

def setup_default_review_form(self):
default_review_form, c = review_models.ReviewForm.objects.get_or_create(
journal=self,
name='Default Form',
defaults={
'intro': 'Please complete the form below.',
'thanks': 'Thank you for completing the review.',
}
)

if c:
main_element = review_models.ReviewFormElement.objects.create(
name='Review',
kind='textarea',
required=True,
order=1,
width='large-12 columns',
help_text=gettext('Please add as much detail as you can.'),
)

default_review_form.elements.add(main_element)


class PinnedArticle(models.Model):
journal = models.ForeignKey(
Expand Down Expand Up @@ -1259,30 +1282,13 @@ def setup_submission_items(sender, instance, created, **kwargs):

@receiver(post_save, sender=Journal)
def setup_default_form(sender, instance, created, **kwargs):
if created:
from review import models as review_models

if not review_models.ReviewForm.objects.filter(
journal=instance,
).exists():

default_review_form = review_models.ReviewForm.objects.create(
journal=instance,
name='Default Form',
intro='Please complete the form below.',
thanks='Thank you for completing the review.'
)

main_element = review_models.ReviewFormElement.objects.create(
name='Review',
kind='textarea',
required=True,
order=1,
width='large-12 columns',
help_text=gettext('Please add as much detail as you can.'),
)
# if this is a new journal and there is not default review for already
# create a new one with a default review element.
if created and not review_models.ReviewForm.objects.filter(
journal=instance,
).exists():
instance.setup_default_review_form()

default_review_form.elements.add(main_element)


@receiver(post_save, sender=Journal)
Expand Down
10 changes: 9 additions & 1 deletion src/repository/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,14 @@ class ReviewAdmin(admin_utils.PreprintFKModelAdmin):
date_hierarchy = ('date_assigned')


class ReviewRecommendationAdmin(admin.ModelAdmin):
list_display = ('pk', 'name', 'repository')
list_display_links = ('pk', 'name',)
list_filter = ('repository',)
raw_id_fields = ('repository',)
search_fields = ('name',)


admin_list = [
(models.Repository, RepositoryAdmin),
(models.RepositoryRole, RepositoryRoleAdmin),
Expand All @@ -206,7 +214,7 @@ class ReviewAdmin(admin_utils.PreprintFKModelAdmin):
(models.Subject, SubjectAdmin),
(models.VersionQueue, VersionQueueAdmin),
(models.Review, ReviewAdmin),

(models.ReviewRecommendation, ReviewRecommendationAdmin),
]

[admin.site.register(*t) for t in admin_list]
82 changes: 21 additions & 61 deletions src/repository/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -457,6 +457,7 @@ class Meta:
'domain',
'object_name',
'object_name_plural',
'theme',
'publisher',
)
help_texts = {
Expand Down Expand Up @@ -673,6 +674,9 @@ class ReviewCommentForm(forms.Form):
widget=SummernoteWidget(),
label="Comments",
)
recommendation = forms.ModelChoiceField(
queryset=models.ReviewRecommendation.objects.none(),
)
anonymous = forms.BooleanField(
help_text='Check if you want your comments to be displayed anonymously.',
label="Comment Anonymously",
Expand All @@ -685,6 +689,12 @@ def __init__(self, *args, **kwargs):
if self.review.comment:
self.fields['body'].initial = self.review.comment.body
self.fields['anonymous'].initial = self.review.anonymous
self.fields['recommendation'].initial = self.review.recommendation.pk

self.fields['recommendation'].queryset = models.ReviewRecommendation.objects.filter(
repository=self.review.preprint.repository,
active=True,
)

def save(self):
if self.cleaned_data:
Expand All @@ -700,77 +710,27 @@ def save(self):

self.review.anonymous = self.cleaned_data.get('anonymous', False)
self.review.comment = comment
self.review.recommendation = self.cleaned_data.get('recommendation')
self.review.save()


class ReviewForm(forms.ModelForm):
class RecommendationForm(forms.ModelForm):
class Meta:
model = models.Review
model = models.ReviewRecommendation
fields = (
'reviewer',
'date_due',
'name',
'active',
)
widgets = {
'date_due': utils_forms.HTMLDateInput(),
}

def __init__(self, *args, **kwargs):
self.preprint = kwargs.pop('preprint')
self.manager = kwargs.pop('manager')
super(ReviewForm, self).__init__(*args, **kwargs)
self.fields['reviewer'].queryset = self.preprint.repository.reviewer_accounts()
self.repository = kwargs.pop('repository')
super(RecommendationForm, self).__init__(*args, **kwargs)

def save(self, commit=True):
review = super(ReviewForm, self).save(commit=False)
review.preprint = self.preprint
review.manager = self.manager
review.status = 'new'
recommendation = super(RecommendationForm, self).save(commit=False)
recommendation.repository = self.repository

if commit:
review.save()

return review


class ReviewDueDateForm(forms.ModelForm):
class Meta:
model = models.Review
fields = ('date_due',)
widgets = {
'date_due': utils_forms.HTMLDateInput(),
}

recommendation.save()

class ReviewCommentForm(forms.Form):
body = forms.CharField(
widget=SummernoteWidget(),
label="Comments",
)
anonymous = forms.BooleanField(
help_text='Check if you want your comments to be displayed anonymously.',
label="Comment Anonymously",
required=False,
)

def __init__(self, *args, **kwargs):
self.review = kwargs.pop('review')
super(ReviewCommentForm, self).__init__(*args, **kwargs)
if self.review.comment:
self.fields['body'].initial = self.review.comment.body
self.fields['anonymous'].initial = self.review.anonymous

def save(self):
if self.cleaned_data:
if self.review.comment:
comment = self.review.comment
else:
comment = models.Comment()

comment.author = self.review.reviewer
comment.preprint = self.review.preprint
comment.body = self.cleaned_data.get('body')
comment.save()

self.review.anonymous = self.cleaned_data.get('anonymous', False)
self.review.comment = comment
self.review.save()
return recommendation
Loading

0 comments on commit d4cb596

Please sign in to comment.