def vote(request, paper_id): p = get_object_or_404(Paper, pk=paper_id) try: v = Vote(account = request.user.account, paper = p, votetype = request.POST['votetype']) except (KeyError, Vote.DoesNotExist): # Redisplay the poll voting form. return render(request, 'pubview/detail.html', { 'paper': p, 'error_message': "Vote type doesn't exist", }) else: #has this user already voted on this paper? if not request.user.account.alreadyvoted(paper_id): # save if not v.save() else: # is the vote the same? testv = Vote.objects.get(account = request.user.account, paper = p) if testv.votetype != v.votetype: testv.votetype = v.votetype testv.save() # Always return an HttpResponseRedirect after successfully dealing # with POST data. This prevents data from being posted twice if a # user hits the Back button. return HttpResponseRedirect(reverse('pubview:index'))
a1 = Author(firstname ="Joseph", lastname = "Pickrell") a2 = Author(firstname="Jonathan", lastname="Pritchard") a1.save() a2.save() j = Journal(name = "Fake Journal") j.save() j2 = Journal(name = "arXiv q-bio") j2.save() p1 = Paper(title = "Awesome Paper 1", journal =j, year = 2011, abstract = "This is a paper about stuff. We show stuff.") p1.save() p2 = Paper(title = "Awesome Paper 2", journal =j, year = 2011, abstract = "Genomics!") p2.save() pv2 = PaperVersion(title = "Awesome Paper 2", journal =j, year = 2011, paper = p2) pv2 = PaperVersion(title = "Awesome Paper 2", journal =j2, year = 2010, paper = p2) p3 = Paper(title = "Awesome Paper 3", journal =j, year = 2011, abstract = "Previous paper on this topic was bullshit.") p3.save() a1.papers.add(p1, p2) a2.papers.add(p1, p3) a1.coauthors.add(a2) a2.coauthors.add(a1) a1.save() a2.save() like = Vote(account = a, paper = p1, votetype = "U") like.save()