def start(request, type=None): competing_interests = setting_handler.get_setting( 'general', 'submission_competing_interests', request.journal) form = forms.ArticleStart(ci=competing_interests) if not request.user.is_author(request): request.user.add_account_role('author', request.journal) if request.POST: form = forms.ArticleStart(request.POST, ci=competing_interests) if form.is_valid(): new_article = form.save(commit=False) new_article.owner = request.user new_article.journal = request.journal new_article.current_step = 1 new_article.article_agreement = logic.get_agreement_text( request.journal) new_article.save() if type == 'preprint': preprint_models.Preprint.objects.create(article=new_article) if setting_handler.get_setting('general', 'user_automatically_author', request.journal).processed_value: logic.add_self_as_author(request.user, new_article) return redirect( reverse('submit_info', kwargs={'article_id': new_article.pk})) template = 'submission/start.html' context = {'form': form} return render(request, template, context)
def start(request, type=None): """ Starts the submission process, presents various checkboxes and then creates a new article. :param request: HttpRequest object :param type: string, None or 'preprint' :return: HttpRedirect or HttpResponse """ form = forms.ArticleStart(journal=request.journal) if not request.user.is_author(request): request.user.add_account_role('author', request.journal) if request.POST: form = forms.ArticleStart(request.POST, journal=request.journal) if form.is_valid(): new_article = form.save(commit=False) new_article.owner = request.user new_article.journal = request.journal new_article.current_step = 1 new_article.article_agreement = logic.get_agreement_text( request.journal) new_article.save() if type == 'preprint': preprint_models.Preprint.objects.create(article=new_article) if setting_handler.get_setting('general', 'user_automatically_author', request.journal).processed_value: logic.add_self_as_author(request.user, new_article) return redirect( reverse('submit_info', kwargs={'article_id': new_article.pk})) template = 'admin/submission/start.html' context = {'form': form} return render(request, template, context)
def submit_authors(request, article_id): """ Allows the submitting author to add other authors to the submission. :param request: HttpRequest object :param article_id: Article PK :return: HttpRedirect or HttpResponse """ article = get_object_or_404(models.Article, pk=article_id) if article.current_step < 2 and not request.user.is_staff: return redirect(reverse('submit_info', kwargs={'article_id': article_id})) form = forms.AuthorForm() error, modal = None, None if request.GET.get('add_self', None) == 'True': new_author = logic.add_self_as_author(request.user, article) messages.add_message(request, messages.SUCCESS, '%s added to the article' % new_author.full_name()) return redirect(reverse('submit_authors', kwargs={'article_id': article_id})) if request.POST and 'add_author' in request.POST: form = forms.AuthorForm(request.POST) modal = 'author' author_exists = logic.check_author_exists(request.POST.get('email')) if author_exists: article.authors.add(author_exists) models.ArticleAuthorOrder.objects.get_or_create(article=article, author=author_exists) messages.add_message(request, messages.SUCCESS, '%s added to the article' % author_exists.full_name()) return redirect(reverse('submit_authors', kwargs={'article_id': article_id})) else: if form.is_valid(): new_author = form.save(commit=False) new_author.username = new_author.email new_author.set_password(utils_shared.generate_password()) new_author.save() new_author.add_account_role(role_slug='author', journal=request.journal) article.authors.add(new_author) models.ArticleAuthorOrder.objects.get_or_create(article=article, author=new_author) messages.add_message(request, messages.SUCCESS, '%s added to the article' % new_author.full_name()) return redirect(reverse('submit_authors', kwargs={'article_id': article_id})) elif request.POST and 'search_authors' in request.POST: search = request.POST.get('author_search_text', None) if not search: messages.add_message( request, messages.WARNING, 'An empty search is not allowed.' ) else: try: search_author = core_models.Account.objects.get(Q(email=search) | Q(orcid=search)) article.authors.add(search_author) models.ArticleAuthorOrder.objects.get_or_create(article=article, author=search_author) messages.add_message(request, messages.SUCCESS, '%s added to the article' % search_author.full_name()) except core_models.Account.DoesNotExist: messages.add_message(request, messages.WARNING, 'No author found with those details.') elif request.POST and 'main-author' in request.POST: correspondence_author = request.POST.get('main-author', None) if correspondence_author == 'None': messages.add_message(request, messages.WARNING, 'You must select a main author.') else: author = core_models.Account.objects.get(pk=correspondence_author) article.correspondence_author = author article.current_step = 3 article.save() return redirect(reverse('submit_files', kwargs={'article_id': article_id})) elif request.POST and 'authors[]' in request.POST: author_pks = [int(pk) for pk in request.POST.getlist('authors[]')] for author in article.authors.all(): order = author_pks.index(author.pk) author_order, c = models.ArticleAuthorOrder.objects.get_or_create( article=article, author=author, defaults={'order': order} ) if not c: author_order.order = order author_order.save() return HttpResponse('Complete') template = 'admin/submission//submit_authors.html' context = { 'error': error, 'article': article, 'form': form, 'modal': modal, } return render(request, template, context)
def submit_authors(request, article_id): article = get_object_or_404(models.Article, pk=article_id) if article.current_step < 2 and not request.user.is_staff: return redirect(reverse('submit_info', kwargs={'article_id': article_id})) form = forms.AuthorForm() error, modal = None, None if request.GET.get('add_self', None) == 'True': new_author = logic.add_self_as_author(request.user, article) messages.add_message(request, messages.SUCCESS, '%s added to the article' % new_author.full_name()) return redirect(reverse('submit_authors', kwargs={'article_id': article_id})) if request.POST and 'add_author' in request.POST: form = forms.AuthorForm(request.POST) modal = 'author' author_exists = logic.check_author_exists(request.POST.get('email')) if author_exists: article.authors.add(author_exists) messages.add_message(request, messages.SUCCESS, '%s added to the article' % author_exists.full_name()) return redirect(reverse('submit_authors', kwargs={'article_id': article_id})) else: if form.is_valid(): new_author = form.save(commit=False) new_author.username = new_author.email new_author.set_password(utils_shared.generate_password()) new_author.save() new_author.add_account_role(role_slug='author', journal=request.journal) article.authors.add(new_author) messages.add_message(request, messages.SUCCESS, '%s added to the article' % new_author.full_name()) return redirect(reverse('submit_authors', kwargs={'article_id': article_id})) elif request.POST and 'search_authors' in request.POST: search = request.POST.get('author_search_text') try: search_author = core_models.Account.objects.get(Q(email=search) | Q(orcid=search)) article.authors.add(search_author) messages.add_message(request, messages.SUCCESS, '%s added to the article' % search_author.full_name()) except core_models.Account.DoesNotExist: messages.add_message(request, messages.WARNING, 'No author found with those details.') elif request.POST: correspondence_author = request.POST.get('main-author', None) if correspondence_author == 'None': messages.add_message(request, messages.WARNING, 'You must select a main author.') else: author = core_models.Account.objects.get(pk=correspondence_author) article.correspondence_author = author article.current_step = 3 article.save() return redirect(reverse('submit_files', kwargs={'article_id': article_id})) template = 'submission/submit_authors.html' context = { 'error': error, 'article': article, 'form': form, 'modal': modal, } return render(request, template, context)