def add_chapter(request, submission_id): book = get_object_or_404(models.Book, pk=submission_id) chapter_form = core_forms.ChapterForm() if request.POST: chapter_form = forms.ChapterForm(request.POST, request.FILES) if chapter_form.is_valid(): new_file = handle_file(request.FILES.get('chapter_file'), book, 'chapter', request.user) new_chapter = chapter_form.save(commit=False) new_chapter.book = book label = request.POST.get('file_label') if label: new_file.label = label else: new_file.label = None new_file.save() new_chapter.file = new_file new_chapter.save() log.add_log_entry(book=book, user=request.user, kind='production', message='%s %s loaded a new chapter, %s' % (request.user.first_name, request.user.last_name, new_chapter.identifier), short_name='New Chapter Loaded') return redirect(reverse('editor_production', kwargs={'submission_id': book.id})) template = 'editor/submission.html' context = { 'submission': book, 'chapter_form': chapter_form, 'author_include': 'editor/production/view.html', 'submission_files': 'editor/production/add_chapter.html', 'active': 'production', 'submission': book, 'format_list': models.Format.objects.filter(book=book).select_related('file'), 'chapter_list': models.Chapter.objects.filter(book=book).select_related('file'), 'active_page': 'production', } return render(request, template, context)
def editor_submission(request, submission_id): book = get_object_or_404(models.Book, pk=submission_id) if request.POST and 'review' in request.POST: core_logic.create_new_review_round(book) book.stage.review = timezone.now() book.stage.current_stage = 'review' book.stage.save() if book.stage.current_stage == 'review': log.add_log_entry(book=book, user=request.user, kind='review', message='Submission moved to Review', short_name='Submission in Review') messages.add_message(request, messages.SUCCESS, 'Submission has been moved to the review stage.') return redirect(reverse('editor_review', kwargs={'submission_id': book.id})) template = 'editor/submission.html' context = { 'submission': book, 'active': 'user_submission', 'author_include': 'editor/submission_details.html', 'submission_files': 'editor/submission_files.html', 'active_page': 'editor_submission', } return render(request, template, context)
def editor_review(request, submission_id): book = get_object_or_404(models.Book, pk=submission_id) review_rounds = models.ReviewRound.objects.filter(book=book).order_by('-round_number') if request.POST and 'new_round' in request.POST: new_round = logic.create_new_review_round(book) return redirect(reverse('editor_review_round', kwargs={'submission_id': submission_id, 'round_number': new_round.round_number})) elif request.POST and 'move_to_editing' in request.POST: if not book.stage.editing: log.add_log_entry(book=book, user=request.user, kind='editing', message='Submission moved to Editing.', short_name='Submission in Editing') book.stage.editing = timezone.now() book.stage.current_stage = 'editing' book.stage.save() return redirect(reverse('editor_editing', kwargs={'submission_id': submission_id})) template = 'editor/submission.html' context = { 'submission': book, 'author_include': 'editor/review_revisions.html', 'review_rounds': review_rounds, 'revision_requests': revision_models.Revision.objects.filter(book=book, revision_type='review'), 'active_page': 'editor_review', } return render(request, template, context)
def view_new_submission(request, submission_id): submission = get_object_or_404(models.Book, pk=submission_id) if request.POST and 'review' in request.POST: logic.create_new_review_round(submission) submission.stage.review = timezone.now() submission.stage.current_stage = 'review' submission.stage.save() if submission.stage.current_stage == 'review': log.add_log_entry(book=submission, user=request.user, kind='review', message='Submission moved to Review', short_name='Submission in Review') messages.add_message(request, messages.SUCCESS, 'Submission has been moved to the review stage.') return redirect(reverse('editor_review', kwargs={'submission_id': submission.id})) template = 'editor/new/view_new_submission.html' context = { 'submission': submission, 'active': 'new', 'revision_requests': revision_models.Revision.objects.filter(book=submission, revision_type='submission') } return render(request, template, context)
def add_physical(request, submission_id): book = get_object_or_404(models.Book, pk=submission_id) format_form = forms.PhysicalFormatForm() if request.POST: format_form = forms.PhysicalFormatForm(request.POST, request.FILES) if format_form.is_valid(): new_format = format_form.save(commit=False) new_format.book = book new_format.save() log.add_log_entry(book=book, user=request.user, kind='production', message='%s %s loaded a new format, %s' % (request.user.first_name, request.user.last_name, new_format.name), short_name='New Format Loaded') return redirect(reverse('editor_production', kwargs={'submission_id': book.id})) template = 'editor/submission.html' context = { 'submission': book, 'physical_form': format_form, 'author_include': 'editor/production/view.html', 'submission_files': 'editor/production/physical_format.html', 'active': 'production', 'submission': book, 'format_list': models.Format.objects.filter(book=book).select_related('file'), 'chapter_list': models.Chapter.objects.filter(book=book).select_related('file'), 'active_page': 'production', } return render(request, template, context)
def submission_five(request, book_id): book = get_object_or_404(core_models.Book, pk=book_id, owner=request.user) logic.check_stage(book, 6) if request.method == 'POST' and 'complete' in request.POST: book.submission_date = timezone.now() book.slug = slugify(book.title) stage = core_models.Stage(current_stage='submission', submission=book.submission_date) stage.save() book.stage = stage book.save() log.add_log_entry(book, request.user, 'submission', 'Submission of %s completed' % book.title, 'Submission Completed') # Send ack email press_editors = core_models.User.objects.filter(profile__roles__slug='press-editor') logic.send_acknowldgement_email(book, press_editors) return redirect(reverse('author_dashboard')) template = 'submission/submission_five.html' context = { 'book': book, 'active': 6, 'manuscript_files': core_models.File.objects.filter(book=book, kind='manuscript'), 'additional_files': core_models.File.objects.filter(book=book, kind='additional'), } return render(request, template, context)
def copyedit_review(request, submission_id, copyedit_id): book = get_object_or_404(models.Book, pk=submission_id, owner=request.user) copyedit = get_object_or_404(models.CopyeditAssignment, pk=copyedit_id, book__owner=request.user, book=book, author_invited__isnull=False, author_completed__isnull=True) form = core_forms.CopyeditAuthor(instance=copyedit) if request.POST: form = core_forms.CopyeditAuthor(request.POST, instance=copyedit) if form.is_valid(): form.save() for _file in request.FILES.getlist('copyedit_file_upload'): new_file = handle_copyedit_file(_file, book, copyedit, 'copyedit') copyedit.author_files.add(new_file) copyedit.author_completed = timezone.now() copyedit.save() log.add_log_entry(book=book, user=request.user, kind='editing', message='Copyedit Author review compeleted by %s %s.' % (request.user.first_name, request.user.last_name), short_name='Copyedit Author Review Complete') messages.add_message(request, messages.SUCCESS, 'Copyedit task complete. Thanks.') new_task = task.create_new_task(book, copyedit.book.owner, copyedit.requestor, "Author Copyediting completed for %s" % book.title, workflow='editing') return redirect(reverse('editing', kwargs={"submission_id": submission_id,})) template = 'author/submission.html' context = { 'submission': book, 'copyedit': copyedit, 'author_include': 'author/copyedit.html', 'submission_files': 'author/copyedit_review.html', 'form': form, } return render(request, template, context)
def assign_copyeditor(request, submission_id): book = get_object_or_404(models.Book, pk=submission_id) copyeditors = models.User.objects.filter(profile__roles__slug='copyeditor') if not book.stage.current_stage == 'editing': messages.add_message(request, messages.WARNING, 'You cannot assign a Copyeditor, this book is not in the Editing phase.') return redirect(reverse('editor_editing', kwargs={'submission_id': book.id})) if request.POST: copyeditor_list = User.objects.filter(pk__in=request.POST.getlist('copyeditor')) file_list = models.File.objects.filter(pk__in=request.POST.getlist('file')) due_date = request.POST.get('due_date') email_text = request.POST.get('message') attachment = handle_attachment(request, book) for copyeditor in copyeditor_list: logic.handle_copyeditor_assignment(request,book, copyeditor, file_list, due_date, email_text, requestor=request.user, attachment=attachment) log.add_log_entry(book=book, user=request.user, kind='editing', message='Copyeditor %s %s assigend to %s' % (copyeditor.first_name, copyeditor.last_name, book.title), short_name='Copyeditor Assigned') return redirect(reverse('editor_editing', kwargs={'submission_id': submission_id})) template = 'editor/submission.html' context = { 'submission': book, 'copyeditors': copyeditors, 'author_include': 'editor/editing.html', 'submission_files': 'editor/assign_copyeditor.html', 'email_text': models.Setting.objects.get(group__name='email', name='copyedit_request'), 'active_page': 'editing' , } return render(request, template, context)
def author_production(request, submission_id): book = get_object_or_404(models.Book, pk=submission_id) if request.POST and request.GET.get('start', None): if request.GET.get('start') == 'typesetting': book.stage.typesetting = timezone.now() book.stage.save() elif request.POST and 'proof_id' in request.POST: proof_id = request.POST.get('proof_id') author_feedback = request.POST.get('author_feedback') proof = get_object_or_404(editor_models.CoverImageProof, pk=proof_id) proof.completed = timezone.now() proof.note_to_editor = author_feedback proof.save() log.add_log_entry(book=book, user=request.user, kind='production', message='%s %s completed Cover Image Proofs' % (request.user.first_name, request.user.last_name), short_name='Cover Image Proof Request') new_task = task.create_new_task(book, request.user, proof.editor, "Cover Proofing completed for %s" % book.title, workflow='production') return redirect(reverse('author_production', kwargs={'submission_id': submission_id})) template = 'author/submission.html' context = { 'author_include': 'author/production/view.html', 'active': 'production', 'submission': book, 'format_list': models.Format.objects.filter(book=book).select_related('file'), 'chapter_list': models.Chapter.objects.filter(book=book).select_related('file'), } return render(request, template, context)
def task_hub_decline(request, assignment_type, assignment_id,): assignment = logic.get_assignment(assignment_type, assignment_id) email_text = get_email_content( request = request, setting_name='task_decline', context={'sender':request.user,'receiver':assignment.requestor} ) if request.POST: if assignment_type == 'copyedit': format_kind = "copyedit" assignment_user = assignment.copyeditor elif assignment_type == 'typesetting': format_kind = "typeset" assignment_user = assignment.typesetter elif assignment_type == 'indexing': format_kind = "index" assignment_user = assignment.indexer log.add_log_entry(book=assignment.book, user=request.user, kind=format_kind, message='%s assignment declined by %s.' % (assignment_type.title(),assignment_user.profile.full_name()), short_name='Assignment declined.') core_logic.send_task_decline(assignment=assignment, type=assignment_type, email_text=request.POST.get('decline-email'), sender=request.user, request = request) return redirect(reverse('user_dashboard')) template = 'onetasker/taskhub.html' context = { 'submission': assignment.book, 'assignment': assignment, 'send_email':True, 'center_block': 'onetasker/decline_contact.html', 'email_text': email_text, } return render(request, template, context)
def typeset_review(request, submission_id, typeset_id): book = get_object_or_404(models.Book, pk=submission_id) typeset = get_object_or_404(models.TypesetAssignment, pk=typeset_id, book__owner=request.user, book=book) form = core_forms.TypesetAuthor(instance=typeset) if request.POST: form = core_forms.TypesetAuthor(request.POST, instance=typeset) if form.is_valid(): form.save() for _file in request.FILES.getlist('typeset_file_upload'): new_file = handle_typeset_file(_file, book, typeset, 'typeset') typeset.author_files.add(new_file) typeset.author_completed = timezone.now() typeset.save() log.add_log_entry(book=book, user=request.user, kind='production', message='Author Typesetting review %s %s completed.' % (request.user.first_name, request.user.last_name), short_name='Author Typesetting Review Completed') messages.add_message(request, messages.SUCCESS, 'Typesetting task complete. Thanks.') new_task = task.create_new_task(book, typeset.book.owner, typeset.requestor, "Author Typesetting completed for %s" % book.title, workflow='production') return redirect(reverse('editing', kwargs={"submission_id": submission_id,})) template = 'author/submission.html' context = { 'submission': book, 'typeset': typeset, 'author_include': 'author/typeset.html', 'submission_files': 'author/typeset_review.html', 'form': form, } return render(request, template, context)
def handle_editorial_review_assignment(request,book, editors, access_key, due_date, user, email_text, attachment=None): obj, created = models.EditorialReviewAssignment.objects.get_or_create( management_editor = user, completed = None, book=book, defaults={'due':due_date} ) if obj.editorial_board_access_key: obj.publishing_committee_access_key = access_key else: obj.editorial_board_access_key = access_key obj.save() message = "A new Editorial Review Assignment for %s has been assigned to you by %s ." % (book.title,request.user.username) for editor in editors: if not obj.editorial_board.filter(username=editor.username).exists(): notification = models.Task(assignee=editor,creator=request.user,text=message,workflow='editorial-review', editorial_review = obj, book=book) notification.save() obj.editorial_board.add(editor) obj.save() log.add_log_entry(book=book, user=user, kind='review', message='Editorial member %s %s assigned.' % (editor.first_name, editor.last_name), short_name='Editorial Review Assignment') else: messages.add_message(request, messages.WARNING, 'Editorial Review Assignment for user <%s> already exists. User might already exist in one of the selected committees' % editor.username) if created: book.editorial_review_assignments.add(obj) send_editorial_review_request(book, obj, email_text, user, attachment) return obj else: return obj
def handle_editorial_review_assignment( request, book, editors, access_key, due_date, user, email_text, attachment=None, ): obj, created = models.EditorialReviewAssignment.objects.get_or_create( management_editor=user, completed=None, book=book, defaults={'due': due_date}) if obj.editorial_board_access_key: obj.publishing_committee_access_key = access_key else: obj.editorial_board_access_key = access_key obj.save() message = ("A new Editorial Review Assignment for %s has been " "assigned to you by %s ." % (book.title, request.user.username)) for editor in editors: if not obj.editorial_board.filter(username=editor.username).exists(): notification = models.Task( assignee=editor, creator=request.user, text=message, workflow='editorial-review', editorial_review=obj, book=book, ) notification.save() obj.editorial_board.add(editor) obj.save() log.add_log_entry( book=book, user=user, kind='review', message='Editorial member %s %s assigned.' % (editor.first_name, editor.last_name), short_name='Editorial Review Assignment', ) else: messages.add_message( request, messages.WARNING, 'Editorial Review Assignment for user <%s> already exists. ' 'User might already exist in one of the ' 'selected committees' % editor.username) if created: book.editorial_review_assignments.add(obj) send_editorial_review_request(book, obj, email_text, user, attachment) return obj return obj
def editor_add_reviewers(request, submission_id, review_type, round_number): submission = get_object_or_404(models.Book, pk=submission_id) reviewers = models.User.objects.filter(profile__roles__slug='reviewer') review_forms = review_models.Form.objects.all() committees = manager_models.Group.objects.filter(group_type='review_committee') review_round = get_object_or_404(models.ReviewRound, book=submission, round_number=round_number) if request.POST: reviewers = User.objects.filter(pk__in=request.POST.getlist('reviewer')) committees = manager_models.Group.objects.filter(pk__in=request.POST.getlist('committee')) review_form = review_models.Form.objects.get(ref=request.POST.get('review_form')) due_date = request.POST.get('due_date') email_text = request.POST.get('message') if request.FILES.get('attachment'): attachment = handle_file(request.FILES.get('attachment'), submission, 'misc', request.user) else: attachment = None # Handle reviewers for reviewer in reviewers: logic.handle_review_assignment(request,submission, reviewer, review_type, due_date, review_round, request.user, email_text, attachment) # Handle committees for committee in committees: members = manager_models.GroupMembership.objects.filter(group=committee) for member in members: logic.handle_review_assignment(request,submission, member.user, review_type, due_date, review_round, request.user, email_text, attachment) # Tidy up and save if review_type == 'internal' and not submission.stage.internal_review: submission.stage.internal_review = timezone.now() submission.stage.save() log.add_log_entry(book=submission, user=request.user, kind='review', message='Internal Review Started', short_name='Submission entered Internal Review') elif review_type == 'external' and not submission.stage.external_review: submission.stage.external_review = timezone.now() submission.stage.save() log.add_log_entry(book=submission, user=request.user, kind='review', message='External Review Started', short_name='Submission entered External Review') submission.review_form = review_form submission.save() return redirect(reverse('editor_review_round', kwargs={'submission_id': submission_id, 'round_number': submission.get_latest_review_round()})) template = 'editor/add_reviewers.html' context = { 'reviewers': reviewers, 'committees': committees, 'active': 'new', 'email_text': models.Setting.objects.get(group__name='email', name='review_request'), 'review_forms': review_forms, 'submission': submission, } return render(request, template, context)
def update_editorial_review_due_date(request, submission_id, review_id): """Update the due date of an editorial review.""" submission = get_object_or_404(core_models.Book, pk=submission_id) review_assignment = get_object_or_404(models.EditorialReview, pk=review_id) previous_due_date = review_assignment.due if request.POST: email_text = core_models.Setting.objects.get( group__name='email', name='review_due_ack', ).value due_date = request.POST.get('due_date', None) notify = request.POST.get('email', None) if due_date: if not str(due_date) == str(previous_due_date): review_assignment.due = due_date review_assignment.save() message = 'Due date changed from {previous_due} to {new_due}' \ ' for editorial review assignment: {review}'.format( previous_due=previous_due_date, new_due=due_date, review=review_assignment, ) short_message = 'Due Date Changed' log.add_log_entry( book=review_assignment.content_object, user=request.user, kind='Editorial Review', message=message, short_name=short_message, ) if notify: editor_logic.send_review_update( submission, review_assignment, email_text, request.user, attachment=None, ) messages.add_message(request, messages.SUCCESS, 'Due date updated.') return redirect( reverse('editor_view_editorial_review', kwargs={ 'submission_id': submission_id, 'editorial_review_id': review_id })) template = 'editorialreview/update_editorial_review_due_date.html' context = {'submission': submission, 'review': review_assignment} return render(request, template, context)
def start_submission(request, book_id=None): direct_submissions = core_models.Setting.objects.get(group__name='general', name='direct_submissions').value default_review_type = core_models.Setting.objects.get(group__name='general', name='default_review_type').value review_type_selection = core_models.Setting.objects.get(group__name='general', name='review_type_selection').value ci_required = core_models.Setting.objects.get(group__name='general', name='ci_required') checklist_items = submission_models.SubmissionChecklistItem.objects.all() if book_id: book = get_object_or_404(core_models.Book, pk=book_id, owner=request.user) if not book.proposal and not direct_submissions: return redirect(reverse('proposal_start')) book_form = forms.SubmitBookStageOne(instance=book, ci_required=ci_required.value) checklist_form = forms.SubmissionChecklist(checklist_items=checklist_items, book=book) else: if not direct_submissions: return redirect(reverse('proposal_start')) book = None book_form = forms.SubmitBookStageOne() checklist_form = forms.SubmissionChecklist(checklist_items=checklist_items) if request.method == 'POST': if book: book_form = forms.SubmitBookStageOne(request.POST, instance=book, ci_required=ci_required.value, review_type_required = review_type_selection) else: book_form = forms.SubmitBookStageOne(request.POST, ci_required=ci_required.value, review_type_required = review_type_selection) checklist_form = forms.SubmissionChecklist(request.POST, checklist_items=checklist_items) if book_form.is_valid() and checklist_form.is_valid(): book = book_form.save(commit=False) book.owner = request.user if not review_type_selection: book.review_type = default_review_type if not book.submission_stage > 2: book.submission_stage = 2 book.save() log.add_log_entry(book, request.user, 'submission', 'Submission Started', 'Submission Started') book.save() if not book_id and book: if book.book_type == 'monograph': logic.copy_author_to_submission(request.user, book) elif book.book_type == 'edited_volume': logic.copy_editor_to_submission(request.user, book) return redirect(reverse('submission_two', kwargs={'book_id': book.id})) template = "submission/start_submission.html" context = { 'book_form': book_form, 'checklist_form': checklist_form, 'book': book, 'active': 1, } return render(request, template, context)
def typeset_review(request, submission_id, typeset_id): book = get_object_or_404(models.Book, pk=submission_id) typeset = get_object_or_404( models.TypesetAssignment, pk=typeset_id, book__owner=request.user, book=book, ) form = core_forms.TypesetAuthor(instance=typeset) if request.POST: form = core_forms.TypesetAuthor(request.POST, instance=typeset) if form.is_valid(): form.save() for _file in request.FILES.getlist('typeset_file_upload'): new_file = handle_typeset_file(_file, book, typeset, 'typeset') typeset.author_files.add(new_file) typeset.author_completed = timezone.now() typeset.save() log.add_log_entry( book=book, user=request.user, kind='production', message='Author Typesetting review %s %s completed.' % (request.user.first_name, request.user.last_name), short_name='Author Typesetting Review Completed', ) messages.add_message( request, messages.SUCCESS, 'Typesetting task complete. Thanks.', ) task.create_new_task(book, typeset.book.owner, typeset.requestor, "Author Typesetting completed for %s" % book.title, workflow='production') return redirect( reverse('editing', kwargs={ "submission_id": submission_id, })) template = 'author/submission.html' context = { 'submission': book, 'typeset': typeset, 'author_include': 'author/typeset.html', 'submission_files': 'author/typeset_review.html', 'form': form, } return render(request, template, context)
def task_hub_decline(request, assignment_type, assignment_id,): assignment = logic.get_assignment(assignment_type, assignment_id) email_text = get_email_content( request=request, setting_name='task_decline', context={'sender': request.user, 'receiver': assignment.requestor} ) if request.POST: if assignment_type == 'copyedit': format_kind = "copyedit" assignment_user = assignment.copyeditor elif assignment_type == 'typesetting': format_kind = "typeset" assignment_user = assignment.typesetter elif assignment_type == 'indexing': format_kind = "index" assignment_user = assignment.indexer log.add_log_entry( book=assignment.book, user=request.user, kind=format_kind, message='%s assignment declined by %s.' % ( assignment_type.title(), assignment_user.profile.full_name() ), short_name='Assignment declined.' ) core_logic.send_task_decline( assignment=assignment, _type=assignment_type, email_text=request.POST.get('decline-email'), sender=request.user, request=request, ) return redirect(reverse('user_dashboard')) template = 'onetasker/taskhub.html' context = { 'submission': assignment.book, 'assignment': assignment, 'send_email': True, 'center_block': 'onetasker/decline_contact.html', 'email_text': email_text, } return render(request, template, context)
def reviewer_decision(request, review_type, submission_id, review_assignment, decision=None,access_key=None): # Check the review assignment as not been completed and is being accessed by the assigned user submission = get_object_or_404(core_models.Book, pk=submission_id) if access_key: review_assignment = get_object_or_404(core_models.ReviewAssignment, access_key=access_key,pk=review_assignment, declined__isnull=True, review_type=review_type) else: review_assignment = get_object_or_404(core_models.ReviewAssignment, Q(user=request.user), Q(book=submission),Q(pk=review_assignment), Q(declined__isnull=True), Q(review_type=review_type),Q(access_key__isnull=True) | Q(access_key__exact='')) # editors = logic.get_editors(review_assignment) if decision and decision == 'accept': review_assignment.accepted = timezone.now() message = "Review Assignment request for '%s' has been accepted by %s %s." % (submission.title,review_assignment.user.first_name, review_assignment.user.last_name) log.add_log_entry(book=submission, user=request.user, kind='review', message=message, short_name='Assignment accepted') logic.notify_editors(submission,message,editors,request.user,'review') elif decision and decision == 'decline': review_assignment.declined = timezone.now() message = "Review Assignment request for '%s' has been declined by %s %s." % (submission.title,review_assignment.user.first_name, review_assignment.user.last_name) logic.notify_editors(submission,message,editors,request.user,'review') log.add_log_entry(book=submission, user=request.user, kind='review', message=message, short_name='Assignment declined') # If we didn't get a decision above, offer the user a choice. if request.POST: if 'accept' in request.POST: review_assignment.accepted = timezone.now() message = "Review Assignment request for '%s' has been accepted by %s %s." % (submission.title,review_assignment.user.first_name, review_assignment.user.last_name) log.add_log_entry(book=submission, user=request.user, kind='review', message=message, short_name='Assignment accepted') logic.notify_editors(submission,message,editors,request.user,'review') elif 'decline' in request.POST: review_assignment.declined = timezone.now() message = "Review Assignment request for '%s' has been declined by %s %s." % (submission.title,review_assignment.user.first_name, review_assignment.user.last_name) logic.notify_editors(submission,message,editors,request.user,'review') log.add_log_entry(book=submission, user=request.user, kind='review', message=message, short_name='Assignment declined') if request.POST or decision: review_assignment.save() if review_assignment.accepted: if access_key: return redirect(reverse('review_with_access_key', kwargs={'review_type': review_type, 'submission_id': submission.pk,'access_key':access_key,'review_round':review_assignment.review_round.round_number})) else: return redirect(reverse('review_without_access_key', kwargs={'review_type': review_type, 'submission_id': submission.pk,'review_round':review_assignment.review_round.round_number})) elif review_assignment.declined: return redirect(reverse('reviewer_dashboard')) template = 'review/reviewer_decision.html' context = { 'submission': submission, 'review_assignment': review_assignment, 'has_additional_files': logic.has_additional_files(submission), 'editors': editors } return render(request, template, context)
def author_production(request, submission_id): book = get_object_or_404(models.Book, pk=submission_id) if request.POST and request.GET.get('start', None): if request.GET.get('start') == 'typesetting': book.stage.typesetting = timezone.now() book.stage.save() elif request.POST and 'proof_id' in request.POST: proof_id = request.POST.get('proof_id') author_feedback = request.POST.get('author_feedback') proof = get_object_or_404(editor_models.CoverImageProof, pk=proof_id) proof.completed = timezone.now() proof.note_to_editor = author_feedback proof.save() log.add_log_entry(book=book, user=request.user, kind='production', message='%s %s completed Cover Image Proofs' % ( request.user.first_name, request.user.last_name, ), short_name='Cover Image Proof Request') task.create_new_task( book, request.user, proof.editor, "Cover Proofing completed for %s" % book.title, workflow='production', ) return redirect( reverse('author_production', kwargs={'submission_id': submission_id})) template = 'author/submission.html' context = { 'author_include': 'author/production/view.html', 'active': 'production', 'submission': book, 'format_list': models.Format.objects.filter(book=book).select_related('file'), 'chapter_list': models.Chapter.objects.filter(book=book), } return render(request, template, context)
def serve_versioned_file(request, submission_id, revision_id): book = get_object_or_404(models.Book, pk=submission_id) versions_file = get_object_or_404(models.FileVersion, pk=revision_id) file_path = os.path.join(settings.BOOK_DIR, submission_id, versions_file.uuid_filename) try: fsock = open(file_path, 'r') mimetype = mimetypes.guess_type(file_path) response = StreamingHttpResponse(fsock, content_type=mimetype) response['Content-Disposition'] = "attachment; filename=%s" % (versions_file.uuid_filename) log.add_log_entry(book=book, user=request.user, kind='file', message='File %s downloaded.' % versions_file.uuid_filename, short_name='Download') return response except IOError: messages.add_message(request, messages.ERROR, 'File not found. %s/%s' % (file_path, versions_file.uuid_filename)) return HttpResponseRedirect(request.META.get('HTTP_REFERER'))
def handle_copyeditor_assignment( request, book, copyedit, files, due_date, note, email_text, requestor, attachment=None, ): try: new_copyeditor = models.CopyeditAssignment( book=book, copyeditor=copyedit, requestor=requestor, note=note, due=due_date, ) new_copyeditor.save() [new_copyeditor.files.add(_file) for _file in files] new_copyeditor.save() log.add_log_entry( book=book, user=requestor, kind='copyedit', message='Copyeditor %s %s assigned. Due %s' % ( copyedit.first_name, copyedit.last_name, due_date, ), short_name='Copyedit Assignment', ) send_copyedit_assignment( book, new_copyeditor, email_text, requestor, attachment=attachment, ) except: messages.add_message( request, messages.WARNING, 'Copyedit Assignment for user <%s> already exists. ' 'User might already exist in one of the selected ' 'committees' % copyedit.username)
def handle_review_assignment(request,book, reviewer, review_type, due_date, review_round, user, email_text, attachment=None): obj, created = models.ReviewAssignment.objects.get_or_create( review_type=review_type, user=reviewer, book=book, review_round=review_round,defaults={'due':due_date} ) if created: book.review_assignments.add(obj) log.add_log_entry(book=book, user=user, kind='review', message='Reviewer %s %s assigned. Round %d' % (reviewer.first_name, reviewer.last_name, review_round.round_number), short_name='Review Assignment') send_review_request(book, obj, email_text, user, attachment) return created else: messages.add_message(request, messages.WARNING, 'Review Assignment for user <%s> already exists. User might already exist in one of the selected committees' % reviewer.username) return obj
def submission_five(request, book_id): book = get_object_or_404(core_models.Book, pk=book_id, owner=request.user) logic.check_stage(book, 6) if request.method == 'POST' and 'complete' in request.POST: book.submission_date = timezone.now() book.slug = slugify(book.title) stage = core_models.Stage( current_stage='submission', submission=book.submission_date, ) stage.save() book.stage = stage book.save() log.add_log_entry( book, request.user, 'submission', 'Submission of %s completed' % book.title, 'Submission Completed', ) press_editors = core_models.User.objects.filter( # Send ack email. profile__roles__slug='press-editor') logic.send_acknowldgement_email(book, press_editors) return redirect(reverse('author_dashboard')) template = 'submission/submission_five.html' context = { 'book': book, 'active': 6, 'manuscript_files': core_models.File.objects.filter( book=book, kind='manuscript', ), 'additional_files': core_models.File.objects.filter( book=book, kind='additional', ), } return render(request, template, context)
def handle_review_assignment( request, book, reviewer, review_type, due_date, review_round, user, email_text, review_form, attachment=None, access_key=None, ): obj, created = models.ReviewAssignment.objects.get_or_create( review_type=review_type, user=reviewer, book=book, review_round=review_round, defaults={ 'due': due_date, 'review_form': review_form, 'access_key': access_key, }) if created: book.review_assignments.add(obj) log.add_log_entry( book=book, user=user, kind='review', message='Reviewer %s %s assigned. Round %d' % (reviewer.first_name, reviewer.last_name, review_round.round_number), short_name='Review Assignment', ) send_review_request(book, obj, email_text, user, attachment, access_key) return created else: messages.add_message( request, messages.WARNING, 'Review Assignment for user <%s> already exists. ' 'User might already exist in one of the ' 'selected committees' % reviewer.username) return obj
def handle_indexer_assignment( request, book, index, files, due_date, note, email_text, requestor, attachment, ): try: new_indexer = models.IndexAssignment( book=book, indexer=index, requestor=requestor, note=note, due=due_date, ) new_indexer.save() [new_indexer.files.add(_file) for _file in files] new_indexer.save() send_invite_indexer( book, new_indexer, email_text, requestor, attachment, ) log.add_log_entry( book=book, user=requestor, kind='index', message='Indexer %s %s assigned. Due %s' % (index.first_name, index.last_name, due_date), short_name='Indexing Assignment', ) except: messages.add_message( request, messages.WARNING, 'Indexing Assignment for user <%s> already exists. User might ' 'already exist in one of the selected committees' % index.username)
def handle_typeset_assignment( request, book, typesetter, files, due_date, email_text, requestor, attachment, ): try: new_typesetter = models.TypesetAssignment( book=book, typesetter=typesetter, requestor=requestor, due=due_date, note=email_text, ) new_typesetter.save() [new_typesetter.files.add(_file) for _file in files] new_typesetter.save() send_invite_typesetter( book, new_typesetter, email_text, requestor, attachment, ) log.add_log_entry( book=book, user=requestor, kind='typeset', message='Typesetter %s %s assigned. Due %s' % (typesetter.first_name, typesetter.last_name, due_date), short_name='Typeset Assignment') except: messages.add_message( request, messages.WARNING, 'Typeset Assignment for user <%s> already exists. ' 'User might already exist in one of the selected ' 'committees' % typesetter.username)
def handle_copyeditor_assignment(request,book, copyedit, files, due_date, email_text, requestor, attachment=None): try: new_copyeditor = models.CopyeditAssignment( book = book, copyeditor = copyedit, requestor = requestor, due = due_date, ) new_copyeditor.save() for _file in files: new_copyeditor.files.add(_file) new_copyeditor.save() log.add_log_entry(book=book, user=requestor, kind='copyedit', message='Copyeditor %s %s assigned. Due %s' % (copyedit.first_name, copyedit.last_name, due_date), short_name='Copyedit Assignment') send_copyedit_assignment(book, new_copyeditor, email_text, requestor, attachment=attachment) except: messages.add_message(request, messages.WARNING, 'Copyedit Assignment for user <%s> already exists. User might already exist in one of the selected committees' % copyedit.username)
def serve_marc21_file(request, submission_id,type): book = get_object_or_404(models.Book, pk=submission_id) if type=='xml': file_pk=logic.book_to_mark21_file(book,request.user,True) else: file_pk=logic.book_to_mark21_file(book,request.user) _file = get_object_or_404(models.File, pk=file_pk) file_path = os.path.join(settings.BOOK_DIR, submission_id, _file.uuid_filename) print file_path try: fsock = open(file_path, 'r') mimetype = mimetypes.guess_type(file_path) response = StreamingHttpResponse(fsock, content_type=mimetype) response['Content-Disposition'] = "attachment; filename=%s" % (_file.original_filename) log.add_log_entry(book=book, user=request.user, kind='file', message='File %s downloaded.' % _file.uuid_filename, short_name='Download') return response except IOError: messages.add_message(request, messages.ERROR, 'File not found. %s' % (file_path)) return HttpResponseRedirect(request.META.get('HTTP_REFERER'))
def handle_indexer_assignment(request,book, index, files, due_date, email_text, requestor, attachment): try: new_indexer = models.IndexAssignment( book=book, indexer=index, requestor=requestor, due=due_date, ) new_indexer.save() for _file in files: new_indexer.files.add(_file) new_indexer.save() send_invite_indexer(book, new_indexer, email_text, requestor, attachment) log.add_log_entry(book=book, user=requestor, kind='index', message='Indexer %s %s assigned. Due %s' % (index.first_name, index.last_name, due_date), short_name='Indexing Assignment') except: messages.add_message(request, messages.WARNING, 'Indexing Assignment for user <%s> already exists. User might already exist in one of the selected committees' % index.username)
def editor_editing(request, submission_id): book = get_object_or_404(models.Book, pk=submission_id) if request.POST and request.GET.get('start', None): action = request.GET.get('start') if action == 'copyediting': book.stage.copyediting = timezone.now() log.add_log_entry(book=book, user=request.user, kind='editing', message='Copyediting has commenced.', short_name='Copyediting Started') elif action == 'indexing': book.stage.indexing = timezone.now() log.add_log_entry(book=book, user=request.user, kind='editing', message='Indexing has commenced.', short_name='Indexing Started') elif action == 'production': book.stage.production = timezone.now() book.stage.current_stage = 'production' log.add_log_entry(book=book, user=request.user, kind='production', message='Submission moved to Production', short_name='Submission in Production') book.stage.save() return redirect(reverse('editor_production', kwargs={'submission_id': submission_id})) book.stage.save() return redirect(reverse('editor_editing', kwargs={'submission_id': submission_id})) template = 'editor/submission.html' context = { 'submission': book, 'author_include': 'editor/editing.html', 'active_page': 'editing', } return render(request, template, context)
def view_copyedit(request, submission_id, copyedit_id): book = get_object_or_404(models.Book, pk=submission_id) copyedit = get_object_or_404(models.CopyeditAssignment, pk=copyedit_id) author_form = core_forms.CopyeditAuthorInvite(instance=copyedit) email_text = models.Setting.objects.get(group__name='email', name='author_copyedit_request').value if request.POST and 'invite_author' in request.POST: if not copyedit.completed: messages.add_message(request, messages.WARNING, 'This copyedit has not been completed, you cannot invite the author to review.') return redirect(reverse('view_copyedit', kwargs={'submission_id': submission_id, 'copyedit_id': copyedit_id})) else: copyedit.editor_review = timezone.now() log.add_log_entry(book=book, user=request.user, kind='editing', message='Copyedit Review Completed by %s %s' % (request.user.first_name, request.user.last_name), short_name='Editor Copyedit Review Complete') copyedit.save() elif request.POST and 'send_invite_author' in request.POST: attachment = handle_attachment(request, book) author_form = core_forms.CopyeditAuthorInvite(request.POST, instance=copyedit) author_form.save() copyedit.author_invited = timezone.now() copyedit.save() email_text = request.POST.get('email_text') logic.send_author_invite(book, copyedit, email_text, request.user, attachment) return redirect(reverse('view_copyedit', kwargs={'submission_id': submission_id, 'copyedit_id': copyedit_id})) template = 'editor/submission.html' context = { 'submission': book, 'copyedit': copyedit, 'author_form': author_form, 'author_include': 'editor/editing.html', 'submission_files': 'editor/view_copyedit.html', 'email_text': email_text, 'timeline': core_logic.build_time_line_editing_copyedit(copyedit), 'active_page': 'editing' , } return render(request, template, context)
def handle_typeset_assignment(request,book, typesetter, files, due_date, email_text, requestor, attachment): try: new_typesetter = models.TypesetAssignment( book=book, typesetter=typesetter, requestor=requestor, due=due_date, note=email_text, ) new_typesetter.save() for _file in files: new_typesetter.files.add(_file) new_typesetter.save() send_invite_typesetter(book, new_typesetter, email_text, requestor, attachment) log.add_log_entry(book=book, user=requestor, kind='typeset', message='Typesetter %s %s assigned. Due %s' % (typesetter.first_name, typesetter.last_name, due_date), short_name='Typeset Assignment') except: messages.add_message(request, messages.WARNING, 'Typeset Assignment for user <%s> already exists. User might already exist in one of the selected committees' % typesetter.username)
def revision(request, revision_id, submission_id): revision = get_object_or_404(revision_models.Revision, pk=revision_id, book__owner=request.user, completed__isnull=True) book = get_object_or_404(models.Book, pk=submission_id, owner=request.user) form = forms.AuthorRevisionForm(instance=revision) if request.POST: form = forms.AuthorRevisionForm(request.POST, instance=revision) if form.is_valid(): revision = form.save(commit=False) revision.completed = timezone.now() revision.save() task = models.Task(book=revision.book, creator=request.user, assignee=revision.requestor, text='Revisions submitted for %s' % revision.book.title, workflow=revision.revision_type, ) task.save() log.add_log_entry(book=book, user=request.user, kind='revisions', message='%s submitted revisions for %s' % (request.user.profile.full_name(),revision.book.title), short_name='Revisions submitted') messages.add_message(request, messages.SUCCESS, 'Revisions recorded, thanks.') return redirect(reverse('author_dashboard')) has_manuscript = False has_additional = False for file in book.files.all(): if file.kind == 'manuscript': has_manuscript = True elif file.kind == 'additional': has_additional = True template = 'author/submission.html' context = { 'submission': book, 'revision': revision, 'form': form, 'has_manuscript':has_manuscript, 'has_additional':has_additional, 'author_include': 'author/revision.html', } return render(request, template, context)
def request_revisions(request, submission_id, returner): book = get_object_or_404(models.Book, pk=submission_id) email_text = models.Setting.objects.get(group__name='email', name='request_revisions').value form = forms.RevisionForm() if revision_models.Revision.objects.filter(book=book, completed__isnull=True, revision_type=returner): messages.add_message(request, messages.WARNING, 'There is already an outstanding revision request for this book.') if request.POST: form = forms.RevisionForm(request.POST) if form.is_valid(): new_revision_request = form.save(commit=False) new_revision_request.book = book new_revision_request.revision_type = returner new_revision_request.requestor = request.user new_revision_request.save() print new_revision_request.revision_type email_text = request.POST.get('id_email_text') logic.send_requests_revisions(book, new_revision_request, email_text) log.add_log_entry(book, request.user, 'revisions', '%s %s requested revisions for %s' % (request.user.first_name, request.user.last_name, book.title), 'Revisions Requested') if returner == 'review': return redirect(reverse('editor_review', kwargs={'submission_id': submission_id})) else: messages.add_message(request, messages.INFO, 'Revision request submitted') return redirect(reverse('editor_submission', kwargs={'submission_id': submission_id})) template = 'editor/revisions/request_revisions.html' context = { 'submission': book, 'form': form, 'email_text': email_text, } return render(request, template, context)
def editorial_review(request, review_id): """Complete an editorial review.""" review = get_object_or_404(models.EditorialReview, pk=review_id, completed__isnull=True) form = review_forms.GeneratedForm(form=review.review_form) recommendation_form = forms.RecommendationForm(instance=review) submission = review.content_object book = isinstance(submission, core_models.Book) proposal = isinstance(submission, submission_models.Proposal) if book: peer_reviews = core_models.ReviewAssignment.objects.filter( book=submission, completed__isnull=False, ) else: peer_reviews = submission_models.ProposalReview.objects.filter( proposal=submission, completed__isnull=False, ) completed_editorial_reviews = models.EditorialReview.objects.filter( object_id=submission.id, content_type=review.content_type, completed__isnull=False, ) if request.POST: # Handle completed review. form = review_forms.GeneratedForm( request.POST, request.FILES, form=review.review_form, ) recommendation_form = forms.RecommendationForm( request.POST, instance=review, ) if form.is_valid() and recommendation_form.is_valid(): logic.handle_generated_form_post(review, request) review.completed = timezone.now() review.save() # Add to logs and notify editors. message = ("Editorial review assignment for " "'{}' has been completed by {}.".format( submission.title, review.user.profile.full_name(), )) short_message = 'Completed' if book: log.add_log_entry( book=submission, user=review.user, kind='Editorial Review', message=message, short_name=short_message, ) for editor in submission.book_editors.all(): notification = core_models.Task( assignee=editor, creator=review.user, text=message, book=submission, ) notification.save() else: log.add_proposal_log_entry( proposal=submission, user=review.user, kind='Editorial Review', message=message, short_name=short_message, ) # Handle email notification to editors. subject = get_setting( setting_name='editorialreview_completed_email_subject', setting_group_name='email_subject', default='Editorial review completed', ) email_text = get_setting( setting_name='editorialreview_completed_email', setting_group_name='email', default='message', ) email_text.replace('\n', '<br />') from_email = get_setting( setting_name='from_address', setting_group_name='email', default='*****@*****.**', ) press_name = get_setting( setting_name='press_name', setting_group_name='general', default='The publishers', ) try: series_editor_email = [submission.series.editor.email] except AttributeError: series_editor_email = None editors_to_notify = User.objects.filter( profile__roles__slug='press-editor') if submission.book_editors.all(): editors_to_notify = submission.book_editors.all() for editor in editors_to_notify: salutation = editor.profile.full_name() if editor.profile.salutation: salutation = editor.profile.salutation context = { 'salutation': salutation, 'submission': submission, 'review': review, 'base_url': core_models.Setting.objects.get(name='base_url').value, 'authors': [submission.author] if proposal else submission.author.all(), 'press_name': press_name } email.send_email(subject=subject, context=context, html_template=email_text, from_email=from_email, to=editor.email, cc=series_editor_email, book=submission if book else None, proposal=submission if proposal else None) return redirect( reverse('editorial_review_thanks', kwargs={'review_id': review_id})) template = 'editorialreview/editorial_review.html' context = { 'review': review, 'access_key': request.GET.get('access_key'), 'form': form, 'recommendation_form': recommendation_form, 'peer_reviews': peer_reviews, 'completed_editorial_reviews': completed_editorial_reviews } return render(request, template, context)
def start_submission(request, book_id=None): direct_submissions = core_models.Setting.objects.get( group__name='general', name='direct_submissions').value default_review_type = core_models.Setting.objects.get( group__name='general', name='default_review_type').value review_type_selection = core_models.Setting.objects.get( group__name='general', name='review_type_selection').value ci_required = core_models.Setting.objects.get( group__name='general', name='ci_required', ) checklist_items = submission_models.SubmissionChecklistItem.objects.all() if book_id: book = get_object_or_404( core_models.Book, pk=book_id, owner=request.user, ) if not book.proposal and not direct_submissions: return redirect(reverse('proposal_start')) book_form = forms.SubmitBookStageOne( instance=book, ci_required=ci_required.value, ) checklist_form = forms.SubmissionChecklist( checklist_items=checklist_items, book=book, ) else: if not direct_submissions: return redirect(reverse('proposal_start')) book = None book_form = forms.SubmitBookStageOne() checklist_form = forms.SubmissionChecklist( checklist_items=checklist_items, ) if request.method == 'POST': if book: book_form = forms.SubmitBookStageOne( request.POST, instance=book, ci_required=ci_required.value, review_type_required=review_type_selection, ) else: book_form = forms.SubmitBookStageOne( request.POST, ci_required=ci_required.value, review_type_required=review_type_selection, ) checklist_form = forms.SubmissionChecklist( request.POST, checklist_items=checklist_items, ) if book_form.is_valid() and checklist_form.is_valid(): book = book_form.save(commit=False) book.owner = request.user if not review_type_selection: book.review_type = default_review_type if not book.submission_stage > 2: book.submission_stage = 2 book.save() log.add_log_entry( book, request.user, 'submission', 'Submission Started', 'Submission Started', ) book.save() if not book_id and book: if book.book_type == 'monograph': logic.copy_author_to_submission(request.user, book) elif book.book_type == 'edited_volume': logic.copy_editor_to_submission(request.user, book) return redirect( reverse('submission_two', kwargs={'book_id': book.id})) template = "submission/start_submission.html" context = { 'book_form': book_form, 'checklist_form': checklist_form, 'book': book, 'active': 1, } return render(request, template, context)
def reviewer_decision(request, review_type, submission_id, review_assignment_id, decision=None, access_key=None): # Check the review assignment as not been completed and is being accessed by the assigned user review_assignment = None submission = get_object_or_404(core_models.Book, pk=submission_id) one_click_no_login = core_models.Setting.objects.filter(name = 'one_click_review_url') if one_click_no_login: if one_click_no_login[0].value == 'on': if access_key: review_assignment = get_object_or_404(core_models.ReviewAssignment, access_key=access_key,pk=review_assignment_id, declined__isnull=True, review_type=review_type, withdrawn = False) user = review_assignment.user else: if request.user.is_authenticated(): review_assignment = get_object_or_404(core_models.ReviewAssignment, Q(user=request.user), Q(book=submission),Q(pk=review_assignment_id), Q(declined__isnull=True), Q(review_type=review_type),Q(withdrawn = False),Q(access_key__isnull=True) | Q(access_key__exact='')) user = request.user else: raise Http404 else: if access_key: review_assignment = get_object_or_404(core_models.ReviewAssignment, access_key=access_key,pk=review_assignment_id, declined__isnull=True, review_type=review_type, withdrawn = False) user = review_assignment.user elif request.user.is_authenticated(): review_assignment = get_object_or_404(core_models.ReviewAssignment, Q(user=request.user), Q(book=submission),Q(pk=review_assignment_id), Q(declined__isnull=True), Q(review_type=review_type),Q(withdrawn = False),Q(access_key__isnull=True) | Q(access_key__exact='')) user = request.user else: raise Http404 else: user = request.user if access_key: review_assignment = get_object_or_404(core_models.ReviewAssignment, access_key=access_key,pk=review_assignment_id, declined__isnull=True, review_type=review_type, withdrawn = False) else: review_assignment = get_object_or_404(core_models.ReviewAssignment, Q(user=user), Q(book=submission),Q(pk=review_assignment_id), Q(declined__isnull=True), Q(review_type=review_type),Q(withdrawn = False),Q(access_key__isnull=True) | Q(access_key__exact='')) if review_assignment: editors = logic.get_editors(review_assignment) else: editors = None if review_assignment.accepted: if access_key: return redirect(reverse('review_with_access_key', kwargs={'review_type': review_type, 'submission_id': submission.pk,'access_key':access_key,'review_round':review_assignment.review_round.round_number})) else: return redirect(reverse('review_without_access_key', kwargs={'review_type': review_type, 'submission_id': submission.pk,'review_round':review_assignment.review_round.round_number})) elif review_assignment.declined: return redirect(reverse('reviewer_dashboard')) if decision and decision == 'accept': review_assignment.accepted = timezone.now() message = "Review Assignment request for '%s' has been accepted by %s %s." % (submission.title,review_assignment.user.first_name, review_assignment.user.last_name) log.add_log_entry(book=submission, user=user, kind='review', message=message, short_name='Assignment accepted') logic.notify_editors(submission,message,editors,user,'review') elif decision and decision == 'decline': review_assignment.declined = timezone.now() message = "Review Assignment request for '%s' has been declined by %s %s." % (submission.title,review_assignment.user.first_name, review_assignment.user.last_name) logic.notify_editors(submission,message,editors,user,'review') log.add_log_entry(book=submission, user=user, kind='review', message=message, short_name='Assignment declined') # If we didn't get a decision above, offer the user a choice. if request.POST: if 'accept' in request.POST: review_assignment.accepted = timezone.now() message = "Review Assignment request for '%s' has been accepted by %s %s." % (submission.title,review_assignment.user.first_name, review_assignment.user.last_name) log.add_log_entry(book=submission, user=user, kind='review', message=message, short_name='Assignment accepted') logic.notify_editors(submission,message,editors,user,'review') elif 'decline' in request.POST: review_assignment.declined = timezone.now() message = "Review Assignment request for '%s' has been declined by %s %s." % (submission.title,review_assignment.user.first_name, review_assignment.user.last_name) logic.notify_editors(submission,message,editors,user,'review') log.add_log_entry(book=submission, user=user, kind='review', message=message, short_name='Assignment declined') if request.POST or decision: review_assignment.save() if review_assignment.accepted: if access_key: return redirect(reverse('review_with_access_key', kwargs={'review_type': review_type, 'submission_id': submission.pk,'access_key':access_key,'review_round':review_assignment.review_round.round_number})) else: return redirect(reverse('review_without_access_key', kwargs={'review_type': review_type, 'submission_id': submission.pk,'review_round':review_assignment.review_round.round_number})) elif review_assignment.declined: return redirect(reverse('reviewer_dashboard')) template = 'review/reviewer_decision.html' context = { 'submission': submission, 'review_assignment': review_assignment, 'has_additional_files': logic.has_additional_files(submission), 'editors': editors, 'file_preview': core_models.Setting.objects.get(group__name='general', name='preview_review_files').value, 'instructions': core_models.Setting.objects.get(group__name='general', name='instructions_for_task_review').value } return render(request, template, context)
def review(request, review_type, submission_id, review_round, access_key=None): ci_required = core_models.Setting.objects.get(group__name='general', name='ci_required') one_click_no_login = core_models.Setting.objects.filter(name = 'one_click_review_url') if one_click_no_login: if one_click_no_login[0].value == 'on': if access_key: review_assignment = get_object_or_404(core_models.ReviewAssignment, access_key=access_key,review_round__round_number=review_round, declined__isnull=True, review_type=review_type, withdrawn = False) submission = get_object_or_404(core_models.Book, pk=submission_id) user = review_assignment.user if review_assignment.completed and not review_assignment.reopened: return redirect(reverse('review_complete_with_access_key', kwargs={'review_type': review_type, 'submission_id': submission.pk,'access_key':access_key,'review_round':review_round})) else: raise Http404 else: user = request.user if access_key: review_assignment = get_object_or_404(core_models.ReviewAssignment, access_key=access_key,review_round__round_number=review_round, declined__isnull=True, review_type=review_type, withdrawn = False) submission = get_object_or_404(core_models.Book, pk=submission_id) if review_assignment.completed and not review_assignment.reopened: return redirect(reverse('review_complete_with_access_key', kwargs={'review_type': review_type, 'submission_id': submission.pk,'access_key':access_key,'review_round':review_round})) elif review_type == 'proposal': submission = get_object_or_404(submission_models.Proposal, pk=submission_id) review_assignment = get_object_or_404(submission_models.ProposalReview, user=user, proposal=submission, completed__isnull=True, declined__isnull=True, withdrawn = False) else: submission = get_object_or_404(core_models.Book, pk=submission_id) review_assignment = get_object_or_404(core_models.ReviewAssignment, Q(user=user), Q(book=submission),Q(review_round__round_number=review_round), Q(declined__isnull=True), Q(review_type=review_type),Q(withdrawn = False),Q(access_key__isnull=True) | Q(access_key__exact='')) if review_assignment.completed and not review_assignment.reopened: return redirect(reverse('review_complete', kwargs={'review_type': review_type, 'submission_id': submission.pk,'review_round':review_round})) else: user = request.user if access_key: review_assignment = get_object_or_404(core_models.ReviewAssignment, access_key=access_key,review_round__round_number=review_round, declined__isnull=True, review_type=review_type, withdrawn = False) submission = get_object_or_404(core_models.Book, pk=submission_id) if review_assignment.completed and not review_assignment.reopened: return redirect(reverse('review_complete_with_access_key', kwargs={'review_type': review_type, 'submission_id': submission.pk,'access_key':access_key,'review_round':review_round})) elif review_type == 'proposal': submission = get_object_or_404(submission_models.Proposal, pk=submission_id) review_assignment = get_object_or_404(submission_models.ProposalReview, user=user, proposal=submission, completed__isnull=True, declined__isnull=True, withdrawn = False) else: submission = get_object_or_404(core_models.Book, pk=submission_id) review_assignment = get_object_or_404(core_models.ReviewAssignment, Q(user=user), Q(book=submission),Q(review_round__round_number=review_round), Q(declined__isnull=True), Q(review_type=review_type),Q(withdrawn = False),Q(access_key__isnull=True) | Q(access_key__exact='')) if review_assignment.completed and not review_assignment.reopened: return redirect(reverse('review_complete', kwargs={'review_type': review_type, 'submission_id': submission.pk,'review_round':review_round})) # Check that this review is being access by the user, is not completed and has not been declined. if review_assignment: if not review_assignment.accepted and not review_assignment.declined: if access_key: return redirect(reverse('reviewer_decision_without_access_key', kwargs={'review_type': review_type, 'submission_id': submission.pk,'access_key':access_key,'review_assignment_id':review_assignment.pk})) else: return redirect(reverse('reviewer_decision_without', kwargs={'review_type': review_type, 'submission_id': submission.pk,'review_assignment_id':review_assignment.pk})) editors = logic.get_editors(review_assignment) if review_assignment.review_form: form = forms.GeneratedForm(form=review_assignment.review_form) else: review_assignment.review_form = submission.review_form review_assignment.save() form = forms.GeneratedForm(form=submission.review_form) if review_assignment.reopened: result = review_assignment.results if result: initial_data = {} data = json.loads(result.data) for k,v in data.items(): initial_data[k] = v[0] form.initial = initial_data recommendation_form = core_forms.RecommendationForm(ci_required=ci_required.value) if review_assignment.reopened: initial_data = {} initial_data[u'recommendation']=review_assignment.recommendation initial_data[u'competing_interests']=review_assignment.competing_interests recommendation_form.initial=initial_data if not request.POST and request.GET.get('download') == 'docx': path = create_completed_review_form(submission, review_assignment.pk) return serve_file(request, path) elif request.POST: form = forms.GeneratedForm(request.POST, request.FILES, form=review_assignment.review_form) recommendation_form = core_forms.RecommendationForm(request.POST, ci_required=ci_required.value) if form.is_valid() and recommendation_form.is_valid(): save_dict = {} file_fields = models.FormElementsRelationship.objects.filter(form=review_assignment.review_form, element__field_type='upload') data_fields = models.FormElementsRelationship.objects.filter(~Q(element__field_type='upload'), form=review_assignment.review_form) for field in file_fields: if field.element.name in request.FILES: # TODO change value from string to list [value, value_type] save_dict[field.element.name] = [handle_review_file(request.FILES[field.element.name], submission, review_assignment, 'reviewer')] for field in data_fields: if field.element.name in request.POST: # TODO change value from string to list [value, value_type] save_dict[field.element.name] = [request.POST.get(field.element.name), 'text'] json_data = smart_text(json.dumps(save_dict)) if review_assignment.reopened: if review_assignment.results: review_assignment.results.data = json_data review_assignment.results.save() review_assignment.reopened=False review_assignment.save() else: form_results = models.FormResult(form=review_assignment.review_form, data=json_data) form_results.save() review_assignment.results = form_results review_assignment.reopened=False review_assignment.save() else: form_results = models.FormResult(form=review_assignment.review_form, data=json_data) form_results.save() review_assignment.results = form_results review_assignment.save() if request.FILES.get('review_file_upload'): handle_review_file(request.FILES.get('review_file_upload'), submission, review_assignment, 'reviewer') review_assignment.completed = timezone.now() if not review_assignment.accepted: review_assignment.accepted = timezone.now() review_assignment.recommendation = request.POST.get('recommendation') review_assignment.competing_interests = request.POST.get('competing_interests') review_assignment.save() message = "%s Review assignment with id %s has been completed by %s ." % (review_assignment.review_type.title(),review_assignment.id,review_assignment.user.profile.full_name()) press_editors = User.objects.filter(profile__roles__slug='press-editor') for editor in press_editors: notification = core_models.Task(assignee=editor,creator=user,text=message,workflow='review', book = submission) notification.save() print "notify" if not review_type == 'proposal': log.add_log_entry(book=submission, user=user, kind='review', message='Reviewer %s %s completed review for %s.' % (review_assignment.user.first_name, review_assignment.user.last_name, submission.title), short_name='Assignment Completed') message = "Reviewer %s %s has completed a review for '%s'." % (submission.title,review_assignment.user.first_name, review_assignment.user.last_name) logic.notify_editors(submission,message,editors,user,'review') if access_key: return redirect(reverse('review_complete_with_access_key', kwargs={'review_type': review_type, 'submission_id': submission.id,'access_key':access_key,'review_round':review_round})) else: return redirect(reverse('review_complete', kwargs={'review_type': review_type, 'submission_id': submission.id,'review_round':review_round})) template = 'review/review.html' context = { 'review_assignment': review_assignment, 'submission': submission, 'form': form, 'form_info': review_assignment.review_form, 'recommendation_form': recommendation_form, 'editors':editors, 'has_additional_files': logic.has_additional_files(submission), 'instructions': core_models.Setting.objects.get(group__name='general', name='instructions_for_task_review').value } return render(request, template, context)
def copyedit_review(request, submission_id, copyedit_id): book = get_object_or_404(models.Book, pk=submission_id, owner=request.user) copyedit = get_object_or_404( models.CopyeditAssignment, pk=copyedit_id, book__owner=request.user, book=book, author_invited__isnull=False, author_completed__isnull=True, ) form = core_forms.CopyeditAuthor(instance=copyedit) if request.POST: form = core_forms.CopyeditAuthor(request.POST, instance=copyedit) if form.is_valid(): form.save() submission_logic.handle_copyedit_author_labels( request.POST, copyedit, kind='misc', ) copyedit.author_completed = timezone.now() copyedit.save() log.add_log_entry( book=book, user=request.user, kind='editing', message='Copyedit Author review compeleted by %s %s.' % (request.user.first_name, request.user.last_name), short_name='Copyedit Author Review Complete', ) messages.add_message( request, messages.SUCCESS, 'Copyedit task complete. Thanks.', ) task.create_new_task( book, copyedit.book.owner, copyedit.requestor, "Author Copyediting completed for %s" % book.title, workflow='editing', ) return redirect( reverse('editing', kwargs={ "submission_id": submission_id, })) template = 'author/submission.html' context = { 'submission': book, 'copyedit': copyedit, 'author_files': True, 'author_include': 'author/copyedit.html', 'submission_files': 'author/copyedit_review.html', 'form': form, } return render(request, template, context)
def revision(request, revision_id, submission_id): _revision = get_object_or_404( revision_models.Revision, pk=revision_id, book__owner=request.user, completed__isnull=True, ) book = get_object_or_404(models.Book, pk=submission_id, owner=request.user) form = forms.AuthorRevisionForm(instance=_revision) if request.POST: form = forms.AuthorRevisionForm(request.POST, instance=_revision) if form.is_valid(): _revision = form.save(commit=False) _revision.completed = timezone.now() _revision.save() _task = models.Task( book=_revision.book, creator=request.user, assignee=_revision.requestor, text='Revisions submitted for %s' % _revision.book.title, workflow=_revision.revision_type, ) _task.save() log.add_log_entry( book=book, user=request.user, kind='revisions', message='%s submitted revisions for %s' % ( request.user.profile.full_name(), _revision.book.title, ), short_name='Revisions submitted', ) messages.add_message( request, messages.SUCCESS, 'Revisions recorded, thanks.', ) return redirect(reverse('author_dashboard')) has_manuscript = False has_additional = False for ff in book.files.all(): if ff.kind == 'manuscript': has_manuscript = True elif ff.kind == 'additional': has_additional = True template = 'author/submission.html' context = { 'submission': book, 'revision': _revision, 'form': form, 'has_manuscript': has_manuscript, 'has_additional': has_additional, 'author_include': 'author/revision.html', } return render(request, template, context)
def catalog(request, submission_id): book = get_object_or_404(models.Book, pk=submission_id) internal_review_assignments = models.ReviewAssignment.objects.filter(book=book, review_type='internal', completed__isnull=False).select_related('user', 'review_round') external_review_assignments = models.ReviewAssignment.objects.filter(book=book, review_type='external', completed__isnull=False).select_related('user', 'review_round') metadata_form = forms.EditMetadata(instance=book) cover_form = forms.CoverForm(instance=book) if request.POST: if request.GET.get('metadata', None): metadata_form = forms.EditMetadata(request.POST, instance=book) if metadata_form.is_valid(): metadata_form.save() for keyword in book.keywords.all(): book.keywords.remove(keyword) for keyword in request.POST.get('tags').split(','): new_keyword, c = models.Keyword.objects.get_or_create(name=keyword) book.keywords.add(new_keyword) for subject in book.subject.all(): book.subject.remove(subject) for subject in request.POST.get('stags').split(','): new_subject, c = models.Subject.objects.get_or_create(name=subject) book.subject.add(new_subject) book.save() return redirect(reverse('catalog', kwargs={'submission_id': submission_id})) else: print metadata_form.errors if request.GET.get('cover', None): cover_form = forms.CoverForm(request.POST, request.FILES, instance=book) if cover_form.is_valid(): cover_form.save() return redirect(reverse('catalog', kwargs={'submission_id': submission_id})) if request.GET.get('invite_author', None): note_to_author = request.POST.get('author_invite', None) new_cover_proof = editor_models.CoverImageProof(book=book, editor=request.user, note_to_author=note_to_author) new_cover_proof.save() log.add_log_entry(book=book, user=request.user, kind='production', message='%s %s requested Cover Image Proofs' % (request.user.first_name, request.user.last_name), short_name='Cover Image Proof Request') messages.add_message(request, messages.SUCCESS, 'Cover Image Proof request added.') return redirect(reverse('catalog', kwargs={'submission_id': submission_id})) template = 'editor/catalog/catalog.html' context = { 'active': 'production', 'submission': book, 'metadata_form': metadata_form, 'cover_form': cover_form, 'internal_review_assignments': internal_review_assignments, 'external_review_assignments': external_review_assignments, 'active_page': 'catalog_view', } return render(request, template, context)
def view_copyedit(request, submission_id, copyedit_id): book = get_object_or_404(models.Book, pk=submission_id) copyedit = get_object_or_404(models.CopyeditAssignment, pk=copyedit_id) author_form = core_forms.CopyeditAuthorInvite(instance=copyedit) email_text = models.Setting.objects.get( group__name='email', name='author_copyedit_request').value if request.POST and 'invite_author' in request.POST: if not copyedit.completed: messages.add_message( request, messages.WARNING, ('This copyedit has not been completed, ' 'you cannot invite the author to review.'), ) return redirect( reverse('view_copyedit', kwargs={ 'submission_id': submission_id, 'copyedit_id': copyedit_id })) else: copyedit.editor_review = timezone.now() log.add_log_entry( book=book, user=request.user, kind='editing', message='Copyedit Review Completed by %s %s' % (request.user.first_name, request.user.last_name), short_name='Editor Copyedit Review Complete') copyedit.save() elif request.POST and 'send_invite_author' in request.POST: attachment = handle_attachment(request, book) author_form = core_forms.CopyeditAuthorInvite( request.POST, instance=copyedit, ) author_form.save() copyedit.author_invited = timezone.now() copyedit.save() email_text = request.POST.get('email_text') logic.send_author_invite( book, copyedit, email_text, request.user, attachment, ) return redirect( reverse('view_copyedit', kwargs={ 'submission_id': submission_id, 'copyedit_id': copyedit_id })) template = 'author/submission.html' context = { 'submission': book, 'copyedit': copyedit, 'author_form': author_form, 'author_include': 'author/editing.html', 'submission_files': 'author/view_copyedit.html', 'email_text': email_text, 'timeline': core_logic.build_time_line_editing_copyedit(copyedit), } return render(request, template, context)
def review(request, review_type, submission_id,review_round, access_key=None): ci_required = core_models.Setting.objects.get(group__name='general', name='ci_required') # Check that this review is being access by the user, is not completed and has not been declined. if access_key: review_assignment = get_object_or_404(core_models.ReviewAssignment, access_key=access_key,review_round__round_number=review_round, declined__isnull=True, review_type=review_type) submission = get_object_or_404(core_models.Book, pk=submission_id) if review_assignment.completed: return redirect(reverse('review_complete_with_access_key', kwargs={'review_type': review_type, 'submission_id': submission.pk,'access_key':access_key,'review_round':review_round})) elif review_type == 'proposal': submission = get_object_or_404(submission_models.Proposal, pk=submission_id) review_assignment = get_object_or_404(submission_models.ProposalReview, user=request.user, proposal=submission, completed__isnull=True, declined__isnull=True) else: submission = get_object_or_404(core_models.Book, pk=submission_id) review_assignment = get_object_or_404(core_models.ReviewAssignment, Q(user=request.user), Q(book=submission),Q(review_round__round_number=review_round), Q(declined__isnull=True), Q(review_type=review_type),Q(access_key__isnull=True) | Q(access_key__exact='')) if review_assignment.completed: return redirect(reverse('review_complete', kwargs={'review_type': review_type, 'submission_id': submission.pk,'review_round':review_round})) if review_assignment: if not review_assignment.accepted and not review_assignment.declined: if access_key: return redirect(reverse('reviewer_decision_without_access_key', kwargs={'review_type': review_type, 'submission_id': submission.pk,'access_key':access_key,'review_assignment':review_assignment.pk})) else: return redirect(reverse('reviewer_decision_without', kwargs={'review_type': review_type, 'submission_id': submission.pk,'review_assignment':review_assignment.pk})) editors = logic.get_editors(review_assignment) form = forms.GeneratedForm(form=submission.review_form) recommendation_form = core_forms.RecommendationForm(ci_required=ci_required.value) if not request.POST and request.GET.get('download') == 'docx': path = create_review_form(submission) return serve_file(request, path) elif request.POST: form = forms.GeneratedForm(request.POST, request.FILES, form=submission.review_form) recommendation_form = core_forms.RecommendationForm(request.POST, ci_required=ci_required.value) if form.is_valid() and recommendation_form.is_valid(): save_dict = {} file_fields = models.FormElementsRelationship.objects.filter(form=submission.review_form, element__field_type='upload') data_fields = models.FormElementsRelationship.objects.filter(~Q(element__field_type='upload'), form=submission.review_form) for field in file_fields: if field.element.name in request.FILES: # TODO change value from string to list [value, value_type] save_dict[field.element.name] = [handle_review_file(request.FILES[field.element.name], submission, review_assignment, 'reviewer')] for field in data_fields: if field.element.name in request.POST: # TODO change value from string to list [value, value_type] save_dict[field.element.name] = [request.POST.get(field.element.name), 'text'] json_data = json.dumps(save_dict) form_results = models.FormResult(form=submission.review_form, data=json_data) form_results.save() if request.FILES.get('review_file_upload'): handle_review_file(request.FILES.get('review_file_upload'), submission, review_assignment, 'reviewer') review_assignment.completed = timezone.now() if not review_assignment.accepted: review_assignment.accepted = timezone.now() review_assignment.recommendation = request.POST.get('recommendation') review_assignment.competing_interests = request.POST.get('competing_interests') review_assignment.results = form_results review_assignment.save() if not review_type == 'proposal': log.add_log_entry(book=submission, user=request.user, kind='review', message='Reviewer %s %s completed review for %s.' % (review_assignment.user.first_name, review_assignment.user.last_name, submission.title), short_name='Assignment Completed') message = "Reviewer %s %s has completed a review for '%s'." % (submission.title,review_assignment.user.first_name, review_assignment.user.last_name) logic.notify_editors(submission,message,editors,request.user,'review') if access_key: return redirect(reverse('review_complete_with_access_key', kwargs={'review_type': review_type, 'submission_id': submission.id,'access_key':access_key,'review_round':review_round})) else: return redirect(reverse('review_complete', kwargs={'review_type': review_type, 'submission_id': submission.id,'review_round':review_round})) template = 'review/review.html' context = { 'review_assignment': review_assignment, 'submission': submission, 'form': form, 'form_info': submission.review_form, 'recommendation_form': recommendation_form, 'editors':editors, 'has_additional_files': logic.has_additional_files(submission), } return render(request, template, context)