コード例 #1
0
ファイル: assign_pcm.py プロジェクト: ibrr1/SAM2017
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('../')
コード例 #2
0
ファイル: pcc_rating.py プロジェクト: ibrr1/SAM2017
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)
コード例 #3
0
ファイル: paper_submission.py プロジェクト: ibrr1/SAM2017
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)