diff --git a/indigo_api/models/tasks.py b/indigo_api/models/tasks.py index e0e40cd90..78ec82f1e 100644 --- a/indigo_api/models/tasks.py +++ b/indigo_api/models/tasks.py @@ -34,9 +34,9 @@ def get_queryset(self): from .documents import Document return super(TaskManager, self).get_queryset() \ - .select_related('created_by_user', 'updated_by_user', 'assigned_to', \ - 'submitted_by_user', 'reviewed_by_user', 'country', \ - 'country__country', 'locality') \ + .select_related('created_by_user', 'updated_by_user', 'assigned_to', + 'submitted_by_user', 'reviewed_by_user', 'country', + 'country__country', 'locality', 'locality__country', 'locality__country__country') \ .prefetch_related(Prefetch('work', queryset=Work.objects.filter())) \ .prefetch_related(Prefetch('document', queryset=Document.objects.no_xml())) \ .prefetch_related('labels') diff --git a/indigo_app/forms.py b/indigo_app/forms.py index 25a372334..ff54ab993 100644 --- a/indigo_app/forms.py +++ b/indigo_app/forms.py @@ -366,7 +366,7 @@ class TaskFilterForm(forms.Form): assigned_to = forms.ModelMultipleChoiceField(queryset=User.objects) submitted_by = forms.ModelMultipleChoiceField(queryset=User.objects) type = forms.MultipleChoiceField(choices=Task.CODES) - country = forms.ModelMultipleChoiceField(queryset=Country.objects) + country = forms.ModelMultipleChoiceField(queryset=Country.objects.select_related('country')) taxonomy_topic = forms.CharField() def __init__(self, country, *args, **kwargs): diff --git a/indigo_app/static/javascript/indigo/views/task_bulk_update.js b/indigo_app/static/javascript/indigo/views/task_bulk_update.js index 7fb5873fc..569f5a6bb 100644 --- a/indigo_app/static/javascript/indigo/views/task_bulk_update.js +++ b/indigo_app/static/javascript/indigo/views/task_bulk_update.js @@ -38,10 +38,10 @@ const formData = this.$form.serialize() + '&unassign'; $.post(this.$form.data('assignees-url'), formData) .then((resp) => { - const html = $.parseHTML(resp.trim())[0]; + const html = $.parseHTML(resp.trim()); const $menu = this.$form.find('.dropdown-menu'); $menu.empty(); - $menu.append(html.children); + $menu.append(html); }); }, }); diff --git a/indigo_app/templates/indigo_api/_task_assign_to_menu.html b/indigo_app/templates/indigo_api/_task_assign_to_menu.html index 88ddf81b0..da4a92a1e 100644 --- a/indigo_app/templates/indigo_api/_task_assign_to_menu.html +++ b/indigo_app/templates/indigo_api/_task_assign_to_menu.html @@ -1,19 +1,19 @@ {% load account i18n %} - +{% for potential_assignee in potential_assignees %} + +{% empty %} + +{% endfor %} diff --git a/indigo_app/templates/indigo_api/_task_card_single.html b/indigo_app/templates/indigo_api/_task_card_single.html index 92fc166f3..e2382538e 100644 --- a/indigo_app/templates/indigo_api/_task_card_single.html +++ b/indigo_app/templates/indigo_api/_task_card_single.html @@ -112,29 +112,37 @@ {% csrf_token %} {% elif task.state == 'open' or task.state == 'pending_review' %} - {% if perms.indigo_api.change_task and task.potential_assignees %} + {% if perms.indigo_api.change_task %}
{% csrf_token %}
{% endif %} diff --git a/indigo_app/templates/indigo_api/_task_detail.html b/indigo_app/templates/indigo_api/_task_detail.html index c6a776f4a..0ee854558 100644 --- a/indigo_app/templates/indigo_api/_task_detail.html +++ b/indigo_app/templates/indigo_api/_task_detail.html @@ -211,25 +211,16 @@
{% trans 'Assigned to' %}
{% endif %} - {% if task.potential_assignees %} - - - {% for potential_assignee in task.potential_assignees %} - {% if potential_assignee == request.user and potential_assignee.too_many_tasks %} -
- - {% trans 'Finish your other assigned tasks before assigning this task to yourself.' %} -
- {% endif %} - {% endfor %} - {% endif %} + {% endif %} diff --git a/indigo_app/urls.py b/indigo_app/urls.py index ea9cc6146..a34965518 100644 --- a/indigo_app/urls.py +++ b/indigo_app/urls.py @@ -51,6 +51,7 @@ path('places//tasks/', tasks.TaskDetailView.as_view(), name='task_detail'), path('places//tasks//edit', tasks.TaskEditView.as_view(), name='task_edit'), path('places//tasks//assign', tasks.TaskAssignView.as_view(), name='assign_task'), + path('places//tasks//assign-to', tasks.TaskAssignToView.as_view(), name='assign_task_to'), path('places//tasks//unassign', tasks.TaskAssignView.as_view(unassign=True), name='unassign_task'), path('places//tasks//projects', tasks.TaskChangeWorkflowsView.as_view(), name='task_workflows'), path('places//tasks//blocking-tasks', tasks.TaskChangeBlockingTasksView.as_view(), name='task_blocked_by'), diff --git a/indigo_app/views/tasks.py b/indigo_app/views/tasks.py index 703c1b711..17bfc04d6 100644 --- a/indigo_app/views/tasks.py +++ b/indigo_app/views/tasks.py @@ -94,8 +94,6 @@ def get_context_data(self, **kwargs): # warn when submitting task on behalf of another user Task.decorate_submission_message(context['tasks'], self) - - Task.decorate_potential_assignees(context['tasks'], self.country, self.request.user) Task.decorate_permissions(context['tasks'], self.request.user) return context @@ -144,8 +142,6 @@ def get_context_data(self, **kwargs): # warn when submitting task on behalf of another user Task.decorate_submission_message([task], self) - - Task.decorate_potential_assignees([task], self.country, self.request.user) Task.decorate_permissions([task], self.request.user) # add work to context @@ -348,6 +344,19 @@ def get_redirect_url(self): return reverse('task_detail', kwargs={'place': self.kwargs['place'], 'pk': self.kwargs['pk']}) +class TaskAssignToView(SingleTaskViewBase, DetailView): + template_name = "indigo_api/_task_assign_to_menu.html" + + def get_context_data(self, **kwargs): + context = super().get_context_data(**kwargs) + Task.decorate_potential_assignees([self.object], self.country, self.request.user) + context["potential_assignees"] = self.object.potential_assignees + context["show"] = True + # prevent the form from being changed + context["task"] = None + return context + + class TaskAssignView(SingleTaskViewBase, View, SingleObjectMixin): # permissions permission_required = ('indigo_api.change_task',) @@ -552,6 +561,7 @@ def get(self, request, *args, **kwargs): def get_queryset(self): tasks = Task.objects \ .filter(assigned_to=None, country__in=self.request.user.editor.permitted_countries.all())\ + .select_related('document__language', 'document__language__language') \ .defer('document__document_xml')\ .order_by('-updated_at')