def assign_paper(request, submission_id, pcm_id): if not __is_session_open(request): return HttpResponseRedirect('/') user = User.objects.get(email=request.session['user_email']) context = {} context.update(__add_general_content_to_context(user)) rev = Review() pcm = User.objects.get(id=pcm_id) current_submission = submission.Submission.objects.get(id=submission_id) paper = current_submission.paper rev.reviewer = pcm rev.paper = paper rev.save() current_submission.reviews.add(rev) current_submission.save() try: nm = NotificationManager.create() nm.send_notification(recipients=[pcm], message="You have been assigned the paper \"{0}\" for review".format(paper.title)) except: print("Something went wrong with adding a notification about paper assignment") return HttpResponseRedirect('../')
def view_rating(request, paper_id): if not __is_session_open(request): return HttpResponseRedirect("/") user = User.objects.get(email=request.session["user_email"]) curent_reviews = Review.objects.all().filter(paper=paper_id) pcc_form = PCC_Rate(request.POST or None) context = {"pcc_rate_form": pcc_form, "rate_paper_page": True, "review": curent_reviews} if pcc_form.is_valid(): current_submission = Submission.objects.all().get(paper=paper_id) current_submission.rating = pcc_form.cleaned_data["rating"] current_submission.save() try: nm = NotificationManager.create() nm.send_notification( recipients=[current_submission.submitter], message='Your submission for the paper "{0}", has been given the rating: {1}'.format( current_submission.paper.title, current_submission.rating ), ) except: print("There was a problem sending the notification for a rated paper") return HttpResponseRedirect("/user_profile") context.update(__add_general_content_to_context(user)) return render(request, "pcc_view_reviews.html", context)
def view_report(request, paper_id): if not __is_session_open(request): return HttpResponseRedirect('/') user = User.objects.get(email=request.session['user_email']) curent_reviews = Review.objects.all().filter(paper = paper_id) pcc_form = PCC_Rate(request.POST or None) print(paper_id) context = { 'pcc_rate_form': pcc_form, 'review':curent_reviews, 'generate_report_page': True, } if pcc_form.is_valid(): # current_review = review.Review() current_submission = Submission.objects.all().get(paper = paper_id) current_submission.rating = pcc_form.cleaned_data['rating'] current_submission.save() return HttpResponseRedirect('/user_profile') context.update(__add_general_content_to_context(user)) return render(request, 'pcc_view_generate_report.html', context)
def review_paper(request, review_id): if not __is_session_open(request): return HttpResponseRedirect('/') user = models.User.objects.get(email=request.session['user_email']) review_paper_form = ReviewPaper(request.POST or None) context = { 'review_paper_form': review_paper_form, 'review_paper_page': True } context.update(__add_general_content_to_context(user)) if review_paper_form.is_valid(): # current_review = review.Review() current_review = review.Review.objects.get(id=review_id) current_review.description = review_paper_form.cleaned_data['description'] current_review.rating = review_paper_form.cleaned_data['rating'] current_review.date = datetime.datetime.now() current_review.is_complete = True current_review.save() return HttpResponseRedirect('/user_profile') return render(request, 'review_paper.html', context)
def download(request, file_name): if not __is_session_open(request): return HttpResponseRedirect('/') file = open('submitted_papers/{}'.format(file_name), 'rb') response = HttpResponse(file, content_type='application/pdf') response['Content-Disposition'] = "attachment; filename={}".format(file_name) return response
def download(request, file_name): if not __is_session_open(request): return HttpResponseRedirect("/") file = open("submitted_papers/{}".format(file_name), "rb") response = HttpResponse(file, content_type="application/pdf") response["Content-Disposition"] = "attachment; filename={}".format(file_name) return response
def user_profile(request): if not __is_session_open(request): return HttpResponseRedirect("/") user = models.User.objects.get(email=request.session["user_email"]) context = {"user_type": user.type} context.update(__add_general_content_to_context(user)) return render(request, "user_profile.html", context)
def pcc_rating(request): if not __is_session_open(request): return HttpResponseRedirect("/") user = User.objects.get(email=request.session["user_email"]) all_submission = Submission.objects.all() context = {"all_submission": all_submission, "rate_paper_page": True} context.update(__add_general_content_to_context(user)) return render(request, "pcc_rate_paper.html", context)
def chooseSubmission(request,submission_id): if not __is_session_open(request): return HttpResponseRedirect('/') user = User.objects.get(email=request.session['user_email']) if user.type != "PCM": return HttpResponseRedirect('/') else: choice = SubmissionChoice() choice.chooser = user submission = Submission.objects.get(id= submission_id) choice.choice = submission choice.save() return HttpResponseRedirect('/user_profile/paper_list/')
def pcms_chosen_paper(request): if not __is_session_open(request): return HttpResponseRedirect('/') user = User.objects.get(email=request.session['user_email']) pcms_chosen_paper = SubmissionChoice.objects.all() print(pcms_chosen_paper) context = { 'ChosenPaper': pcms_chosen_paper, 'pcm_chosen_paper_page': True, } context.update(__add_general_content_to_context(user)) return render(request, 'pcms_chosen_paper_list.html', context)
def review_paper_list(request): if not __is_session_open(request): return HttpResponseRedirect("/") user = User.objects.get(email=request.session["user_email"]) reviews = review.Review.objects.filter(reviewer=user.id) # papers = submission.Submission.objects.all() print(user.id) print(reviews) context = {"papers_queryset": reviews, "user_type": user.type, "review_paper_list_page": True} context.update(__add_general_content_to_context(user)) return render(request, "review_paper_list.html", context)
def pcc_generate_report(request): if not __is_session_open(request): return HttpResponseRedirect('/') user = User.objects.get(email=request.session['user_email']) all_Submission = Submission.objects.all() context = { 'all_submission': all_Submission, 'generate_report_page': True, } context.update(__add_general_content_to_context(user)) return render(request, 'pcc_genrate_report.html', context)
def manage_account(request): if not __is_session_open(request): return HttpResponseRedirect('/') user = user_model.User.objects.get(email=request.session['user_email']) # put all the initial for fields in this dict initial_form_data = {'first_name': user.first_name, 'last_name': user.last_name, 'password': user.password, 'password_verification': user.password, 'manage_account_page' : True } if request.method == 'GET': form_personal_info = update_user_info_form.ManageAccount(initial_form_data) context = { 'form_user_personal_information': form_personal_info, } context.update(__add_general_content_to_context(user)) if request.method == 'POST': form_personal_info = update_user_info_form.ManageAccount(request.POST or None) context = { 'form_user_personal_information': form_personal_info, } context.update(__add_general_content_to_context(user)) if form_personal_info.is_valid(): user.first_name = form_personal_info.cleaned_data['first_name'] user.last_name = form_personal_info.cleaned_data['last_name'] user.password = form_personal_info.cleaned_data['password'] # store the user in the db user.save() messages.success(request, 'You have successfully updated your information') return HttpResponseRedirect('/user_profile') return render(request, 'manage_account.html', context)
def paper_list(request): if not __is_session_open(request): return HttpResponseRedirect('/') user = User.objects.get(email=request.session['user_email']) submissionPairs = [] if user.type == 'Author': submissions = Submission.objects.all().filter(submitter_id__exact=user.id) else: submissions = Submission.objects.all() for sub in submissions: submissionPairs.append((sub,SubmissionChoice.objects.all().filter(chooser=user,choice=sub).exists())) context = { 'papers_queryset': submissions, 'user_type': user.type, 'paper_list_page': True, 'pairs': submissionPairs, } context.update(__add_general_content_to_context(user)) return render(request, 'paper_list.html', context)
def on_assign_pcm(request, submission_id): if not __is_session_open(request): return HttpResponseRedirect('/') user = User.objects.get(email=request.session['user_email']) all_pcms = User.objects.all().filter(type='PCM') paper = submission.Submission.objects.get(id=int(submission_id)).paper pcm_sets = [] for pcm in all_pcms: assigned = Review.objects.filter(paper=paper, reviewer=pcm).exists() if not assigned: chosen = SubmissionChoice.objects.filter(chooser=pcm, choice=submission.Submission.objects.filter(id=int(submission_id))).exists() pcm_sets.append((pcm, chosen)) context = { 'pcms_list': pcm_sets, 'paper_id': submission_id, } context.update(__add_general_content_to_context(user)) return render(request, 'assign_pcm_table.html', context)
def paper_updating_event(request,paper_id): ## check if the submition date is passed so he cannot publish one last_month = datetime.datetime.now() - datetime.timedelta(days=1) PaperDeadLine =paper.PaperDeadLine.objects.filter(date_deadline__gte=last_month) if not PaperDeadLine : return render(request, 'paper_dead_line.html') #**************** if not __is_session_open(request): return HttpResponseRedirect('/') user = User.objects.get(email=request.session['user_email']) #get paper info that we want to update and put this info into the form op paper my_paper= paper.Paper.objects.get(id=paper_id) paper_submission_form = PaperSubmission(request.POST or None) paper_submission_form.fields["title"].initial=my_paper.title; paper_submission_form.fields["authors_list"].initial=my_paper.authors_list; paper_submission_form.fields["author_contact"].initial=my_paper.author_contact; paper_submission_form.fields["paper_format"].initial=my_paper.paper_format; my_Old_paper_path=my_paper.paper; paper_submission_form.fields["is_this_a_revision_of_a_previously_submitted_paper"].initial= "Yes" if my_paper.revision_paper==1 else "No" # paper_submission_form.title=my_paper.title context = { 'paper_submission_form': paper_submission_form, } context.update(__add_general_content_to_context(user)) if request.method == "POST": paper_submission_form = PaperSubmission(request.POST, request.FILES) if paper_submission_form.is_valid(): try: filename = request.FILES['paper'].name if not (filename.endswith('.pdf') or (filename.endswith('.doc')) or (filename.endswith('.docx'))): error = 'sorry!! you can only submit a PDF or Word document' context['error'] = error else: df = datetime.datetime.now() #file name is user last name + date + current time filename = user.last_name + '_' + str(df.month)+"_"+ str(df.day)+"_"+ str(df.year)+ "_" +str(df.hour)+ "_"+ str(df.minute) +"_" +str(df.second) +"_"+ filename #save the file in a folder name submitted_papers in the project main folder file_name='submitted_papers/'+ filename handle_uploaded_file(request.FILES['paper'],file_name) #---- except: # if he didnot submit new file keep old version filename=my_Old_paper_path #Update the paper info submitted_paper = paper.Paper() my_paper.paper = filename my_paper.title = paper_submission_form.cleaned_data['title'] my_paper.authors_list = paper_submission_form.cleaned_data['authors_list'] my_paper.author_contact = paper_submission_form.cleaned_data['author_contact'] my_paper.paper_format = paper_submission_form.cleaned_data['paper_format'] my_paper.revision_paper= 1 if paper_submission_form.cleaned_data["is_this_a_revision_of_a_previously_submitted_paper"]=="Yes" else 0 my_paper.save() messages.success(request, 'Thanks, You have successfully updated a paper') return HttpResponseRedirect('/user_profile') return render(request, 'paper_updating.html', context)
def paper_submission(request): # check if the submition date is passed so he cannot publish one last_month = datetime.datetime.now() - datetime.timedelta(days=1) paper_dead_line = paper.PaperDeadLine.objects.filter(date_deadline__gte=last_month) if not __is_session_open(request): return HttpResponseRedirect('/') user = User.objects.get(email=request.session['user_email']) paper_submission_form = PaperSubmission(request.POST or None) context = { 'paper_submission_form': paper_submission_form, 'paper_submission_page': True } context.update(__add_general_content_to_context(user)) if not paper_dead_line: return render(request, 'paper_dead_line.html', context) if request.method == "POST": paper_submission_form = PaperSubmission(request.POST, request.FILES) if paper_submission_form.is_valid(): filename = request.FILES['paper'].name if not (filename.endswith('.pdf') or (filename.endswith('.doc')) or (filename.endswith('.docx'))): error = 'sorry!! you can only submit a PDF or Word document' context['error'] = error else: df = datetime.datetime.now() # file name is user last name + date + current time filename = user.last_name + '_' + str(df.month) + "_" + str(df.day) + "_" + str(df.year) + "_" + str(df.hour) + "_" + str(df.minute) + "_" + str(df.second) + "_" + filename # save the file in a folder name submitted_papers in the project main folder file_name = 'submitted_papers/' + filename handle_uploaded_file(request.FILES['paper'], file_name) submitted_paper = paper.Paper() submitted_paper.paper = filename submitted_paper.title = paper_submission_form.cleaned_data['title'] submitted_paper.authors_list = paper_submission_form.cleaned_data['authors_list'] submitted_paper.author_contact = paper_submission_form.cleaned_data['author_contact'] submitted_paper.paper_format = paper_submission_form.cleaned_data['paper_format'] submitted_paper.date_created = datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S") submitted_paper.revision_paper = 1 if paper_submission_form.cleaned_data["is_this_a_revision_of_a_previously_submitted_paper"] == "Yes" else 0 submitted_paper.save() new_submission = submission.Submission() new_submission.paper = submitted_paper new_submission.submitter = user new_submission.save() try: print("Sending Notification to PCC") pcc = User.objects.get(type=User.PCC) nm = NotificationManager.create() nm.send_notification(recipients=[pcc], message="{0} has submitted a paper with the title \"{1}\"".format(user.full_name, submitted_paper.title)) except: print("Something went wrong when adding the task") messages.success(request, 'Thanks, You have successfully submitted a paper') return HttpResponseRedirect('/user_profile') return render(request, 'paper_submission.html', context)