def add_copyeditor_assignment(request, article_id): """ Allows a production or editor user to add a new copyeditingassignment. :param request: HttpRequest object :param article_id: a submission.models.Article PK :return: HttpRequest object """ article = get_object_or_404(submission_models.Article, pk=article_id) copyeditors = logic.get_copyeditors(article) file_list = None form = forms.CopyeditAssignmentForm() if request.POST: form = forms.CopyeditAssignmentForm(request.POST) user = logic.get_user_from_post(request.POST) file_list = [int(file_id) for file_id in request.POST.getlist('files')] if not user: form.add_error(None, 'You must select a user.') if not file_list: form.add_error(None, 'You must select at least one file.') else: if form.is_valid(): copyedit = form.save(commit=False) copyedit.article = article copyedit.editor = request.user copyedit.copyeditor = user copyedit.save() file_list = [ core_models.File.objects.get(pk=file_id) for file_id in request.POST.getlist('files') ] for file in file_list: copyedit.files_for_copyediting.add(file) return redirect( reverse('notify_copyeditor_assignment', kwargs={ 'article_id': article.pk, 'copyedit_id': copyedit.pk })) template = 'copyediting/add_copyeditor_assignment.html' context = { 'article': article, 'copyeditors': copyeditors, 'form': form, 'files': file_list, } return render(request, template, context)
def add_copyeditor_assignment(request, article_id): """ Allows a production or editor user to add a new copyeditingassignment. :param request: HttpRequest object :param article_id: a submission.models.Article PK :return: HttpRequest object """ article = get_object_or_404(submission_models.Article, pk=article_id) copyeditors = logic.get_copyeditors(article) copyeditor_pks = [copyeditor.user.pk for copyeditor in copyeditors] files = article.manuscript_files.all() | article.data_figure_files.all() form = forms.CopyeditAssignmentForm( copyeditor_pks=copyeditor_pks, files=files, ) if request.POST: form = forms.CopyeditAssignmentForm( request.POST, copyeditor_pks=copyeditor_pks, files=files, ) if form.is_valid(): copyedit = form.save( editor=request.user, article=article, ) return redirect( reverse('notify_copyeditor_assignment', kwargs={ 'article_id': article.pk, 'copyedit_id': copyedit.pk, })) template = 'copyediting/add_copyeditor_assignment.html' context = { 'article': article, 'copyeditors': copyeditors, 'form': form, } return render(request, template, context)