Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added settings to limit the number of proofreaders by round. #1306

Merged
merged 2 commits into from
Nov 4, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/core/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,7 @@ def __init__(self, *args, **kwargs):
widget=forms.CheckboxInput(attrs={'is_checkbox': True}),
required=False)

self.fields[field['name']].label = object.setting.pretty_name
self.fields[field['name']].initial = object.processed_value
self.fields[field['name']].help_text = object.setting.description

Expand Down
6 changes: 6 additions & 0 deletions src/core/logic.py
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,12 @@ def get_settings_to_edit(group, journal):
'object': setting_handler.get_setting('email', 'from_address', journal),
})

elif group == 'proofing':
proofing_settings = [
'max_proofreaders'
]
settings = process_setting_list(proofing_settings, 'general', journal)
setting_group = 'general'
else:
settings = []
setting_group = None
Expand Down
25 changes: 25 additions & 0 deletions src/proofing/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from django.utils import timezone

from events import logic as event_logic
from utils import setting_handler


class ProofingAssignment(models.Model):
Expand Down Expand Up @@ -108,6 +109,30 @@ def delete_round_relations(self, request, article, tasks, corrections):
)
correction.delete()

def can_add_another_proofreader(self, journal):
"""
Checks if this round can have another proofreader.
:param journal: Journal object
:return: Boolean, True or False
"""

limit = setting_handler.get_setting(
'general',
'max_proofreaders',
journal,
).processed_value

if not limit == 0:

current_num_proofers = ProofingTask.objects.filter(
round=self,
).count()

if current_num_proofers >= limit:
return False

return True


class ProofingTask(models.Model):
round = models.ForeignKey(ProofingRound)
Expand Down
45 changes: 39 additions & 6 deletions src/proofing/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,9 +122,18 @@ def proofing_article(request, article_id):
:param article_id: Article object PK
:return: HttpRedirect if POST or HttpResponse
"""
article = get_object_or_404(submission_models.Article.objects.select_related('productionassignment'), pk=article_id,
journal=request.journal)
proofreaders = logic.get_all_possible_proofers(journal=request.journal, article=article)
article = get_object_or_404(
submission_models.Article.objects.select_related(
'productionassignment'
),
pk=article_id,
journal=request.journal,
)
current_round = article.proofingassignment.current_proofing_round()
proofreaders = logic.get_all_possible_proofers(
journal=request.journal,
article=article,
)
form = forms.AssignProofreader()
modal = None

Expand All @@ -133,10 +142,34 @@ def proofing_article(request, article_id):
if 'new-round' in request.POST:
logic.handle_closing_active_task(request, article)
new_round = article.proofingassignment.add_new_proofing_round()
messages.add_message(request, messages.SUCCESS, 'New round {0} added.'.format(new_round.number))
return redirect(reverse('proofing_article', kwargs={'article_id': article.pk}))
messages.add_message(
request,
messages.SUCCESS,
'New round {0} added.'.format(new_round.number),
)
return redirect(
reverse(
'proofing_article',
kwargs={'article_id': article.pk},
)
)

if 'new-proofreader' in request.POST:

if not current_round.can_add_another_proofreader(request.journal):
messages.add_message(
request,
messages.WARNING,
'The number of proofreaders per round has been limited.'
' You cannot add another proofreader in this round.',
)
return redirect(
reverse(
'proofing_article',
kwargs={'article_id': article.pk},
)
)

form = forms.AssignProofreader(request.POST)
user = logic.get_user_from_post(request, article)
galleys = logic.get_galleys_from_post(request)
Expand All @@ -150,7 +183,7 @@ def proofing_article(request, article_id):
if form.is_valid():
proofing_task = form.save(commit=False)
proofing_task.proofreader = user
proofing_task.round = article.proofingassignment.current_proofing_round()
proofing_task.round = current_round
proofing_task.save()
proofing_task.galleys_for_proofing.add(*galleys)
return redirect(
Expand Down
9 changes: 8 additions & 1 deletion src/templates/admin/core/manager/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,14 @@ <h2>Submission Setup</h2>

<div class="large-3 columns end">
<div class="box" data-equalizer-watch>

<div class="title-area">
<h2>Workflow Setup</h2>
</div>
<div class="content">
<div class="button-group stacked">
<a class="button" href="{% url 'core_edit_settings_group' "proofing" %}">Proofing Settings</a>
</div>
</div>
<div class="title-area">
<h2>Content</h2>
</div>
Expand Down
11 changes: 11 additions & 0 deletions src/templates/admin/proofing/proofing_article.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
{% load foundation %}
{% load roles %}
{% load render_string %}
{% load i18n %}

{% block title %}Proofing - {{ article.pk }}{% endblock title %}
{% block title-section %}Proofing{% endblock %}
Expand Down Expand Up @@ -255,6 +256,16 @@ <h2>Steps</h2>
</div>
<div class="content">
{% render_string journal_settings.general.proofing_steps %}</div>

{% if not journal_settings.general.max_proofreaders.processed_value %}
<div class="title-area">
<h2>Notes</h2>
</div>
<div class="content">
<p>{% trans "Each proofing round is limited to" %} {{ journal_settings.general.max_proofreaders }} {% trans "proofreaders" %}.</p>
</div>
{% endif %}

</div>
<div class="box">
<div class="title-area">
Expand Down
17 changes: 16 additions & 1 deletion src/utils/install/journal_defaults.json
Original file line number Diff line number Diff line change
Expand Up @@ -428,7 +428,7 @@
"is_translatable": false,
"name": "max_dois",
"pretty_name": "Maximum preprint DOIs per month",
"type": "integer"
"type": "number"
},
"value": {
"default": "100"
Expand Down Expand Up @@ -2593,5 +2593,20 @@
"group": {
"name": "general"
}
},
{
"group": {
"name": "general"
},
"setting": {
"description": "The maximum number of proofreaders allowed per round. To disable this set to 0.",
"is_translatable": false,
"name": "max_proofreaders",
"pretty_name": "Maximum Proofreders per Round",
"type": "number"
},
"value": {
"default": "0"
}
}
]