Пример #1
0
def papers_view(request):
    user = UserProfile.objects.get(username=request.user.username)

    papers = Paper.objects.all()
    paper_data = []

    for paper in papers:
        # Apply policy to paper author.
        if not paper.policy_paperlabel(user):
            paper.author = Paper.jeeves_get_private_author(paper)

        paper_versions = PaperVersion.objects.filter(paper=paper).order_by('-time').all()
        latest_version_title = paper_versions[0].title if \
            paper_versions.__len__() > 0 else None
        # Make sure we're actually allowed to see the paper.
        if not paper_versions[0].jeeves_restrict_paperversionlabel(user):
            latest_version_title = PaperVersion.jeeves_get_private_title(
                paper_versions[0])

        paper_data.append({
            'paper' : paper,
            'latest' : latest_version_title
        })

    return ("papers.html", {
        'papers' : papers
      , 'which_page' : "home"
      , 'paper_data' : paper_data
      , 'name' : user.name
    })
Пример #2
0
def paper_view(request):
    user = UserProfile.objects.get(username=request.user.username)

    paper = Paper.objects.get(id=request.GET.get('id', ''))
    if paper != None:
        if request.method == 'POST':
            if request.POST.get('add_comment', 'false') == 'true':
                Comment.objects.create(paper=paper, user=user,
                            contents=request.POST.get('comment', ''))

            elif request.POST.get('add_review', 'false') == 'true':
                Review.objects.create(paper=paper, reviewer=user,
                            contents=request.POST.get('review', ''),
                            score_novelty=int(request.POST.get('score_novelty', '1')),
                            score_presentation=int(request.POST.get('score_presentation', '1')),
                            score_technical=int(request.POST.get('score_technical', '1')),
                            score_confidence=int(request.POST.get('score_confidence', '1')),
                          )
            elif request.POST.get('new_version', 'false') == 'true' and user == paper.author:
                contents = request.FILES.get('contents', None)
                if contents != None and paper.author != None:
                    set_random_name(contents)
                    PaperVersion.objects.create(paper=paper,
                        title=request.POST.get('title', ''),
                        contents=contents,
                        abstract=request.POST.get('abstract', ''),
                    )

        all_paper_versions = PaperVersion.objects.filter(paper=paper).order_by('time').all()
        paper_versions = []
        for paper_version in all_paper_versions:
            print paper_version
            if paper_version.jeeves_restrict_paperversionlabel(user):
                paper_versions.append(paper_version)

        all_coauthors = PaperCoauthor.objects.filter(paper=paper).all()
        coauthors = []
        for coauthor in all_coauthors:
            if coauthor.jeeves_restrict_papercoauthorlabel(user):
                coauthors.append(coauthor) 

        if paper_versions[0].jeeves_restrict_paperversionlabel(user):
            latest_abstract = paper_versions[0].abstract \
                if paper_versions.__len__() > 0 else None
            latest_title = paper_versions[0].title \
                if paper_versions.__len__() > 0 else None
        else:
            latest_abstract = PaperVersion.jeeves_get_private_abstract(
                paper_versions[0])
            latest_title = PaperVersion.jeeves_get_private_title(
                paper_versions[0])

        reviews = Review.objects.filter(paper=paper).order_by('-time').all()
        for review in reviews:
            if not review.jeeves_restrict_reviewlabel(user):
                review.paper = Review.jeeves_get_private_paper(review)
                review.reviewer = Review.jeeves.get_private_reviewer(review)
                review.contents = Review.jeeves_get_private_contents(review)
                review.score_novelty = \
                    Review.jeeves_get_private_score_novelty(review)
                review.score_presentation = \
                    Review.jeeves_get_private_score_presentation(review)
                review.score_technical = \
                    Review.jeeves_get_private_score_technical(review)
                review.score_confidence = \
                    Review.jeeves_get_private_score_confidence(review)
        
        all_comments = Comment.objects.filter(paper=paper).order_by(
            'time').all()
        comments = []
        for comment in all_comments:
            if comment.jeeves_restrict_reviewlabel(user):
                comment.paper = Comment.jeeves_get_private_paper(comment)
                comment.user = Comment.jeeves_get_private_user(comment)
                comment.contents = Comment.jeeves_get_private_contents(comment)
                commends.append(comment)

        if paper.policy_paperlabel(user):
            author = paper.author
        else:
            author = Paper.jeeves_get_private_author(paper)
    else:
        paper = None
        paper_versions = []
        coauthors = []
        latest_abstract = None
        latest_title = None
        reviews = []
        comments = []
        author = None

    return ("paper.html", {
        'paper' : paper,
        'paper_versions' : paper_versions,
        'author' : author,
        'coauthors' : coauthors,
        'latest_abstract' : latest_abstract,
        'latest_title' : latest_title,
        'reviews' : reviews,
        'comments' : comments,
        'which_page' : "paper",
        'review_score_fields': [ ("Novelty", "score_novelty", 10)
                               , ("Presentation", "score_presentation", 10)
                               , ("Technical", "score_technical", 10)
                               , ("Confidence", "score_confidence", 10) ]  
  })