def edit_assignment(request, article_id, copyedit_id): article = get_object_or_404(submission_models.Article, pk=article_id) copyedit = get_object_or_404(models.CopyeditAssignment, pk=copyedit_id) if copyedit.decision: messages.add_message(request, messages.WARNING, 'This task is underway so cannot be edited.') return redirect(reverse('article_copyediting', kwargs={'article_id': article.pk})) form = forms.CopyeditAssignmentForm(instance=copyedit) if request.POST: form = forms.CopyeditAssignmentForm(request.POST, instance=copyedit) if form.is_valid(): form.save() kwargs = {'copyedit_assignment': copyedit, 'request': request, 'skip': True if 'skip' in request.POST else False} event_logic.Events.raise_event(event_logic.Events.ON_COPYEDIT_UPDATED, **kwargs) messages.add_message(request, messages.SUCCESS, 'Copyedit assignment updated.') return redirect(reverse('article_copyediting', kwargs={'article_id': article.pk})) template = 'copyediting/edit_assignment.html' context = { 'article': article, 'copyedit': copyedit, 'form': form, } 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) 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)