Exemple #1
0
def upvote_question(request):
    question_pk = request.POST['question_pk']
    question = get_object_or_404(Question, pk=question_pk)
    points = question.points.filter(fromuser__id__exact=request.user.id)
    if (points.count() == 1):
        points.delete()
        return {'delta':-1}
    point = Point()
    point.fromuser = request.user
    point.save()
    question.points.add(point)
    return {'delta':1}
Exemple #2
0
def upvote_answer(request):
    answer_pk = request.POST['answer_pk']
    answer = get_object_or_404(Answer, pk=answer_pk)
    points = answer.points.filter(fromuser__id__exact=request.user.id)
    if (points.count() == 1):
        points.delete()
        return {'delta':-1}
    point = Point()
    point.fromuser = request.user
    point.save()
    answer.points.add(point)
    return {'delta':1}
Exemple #3
0
    def test_basic_addition(self):
        user = User.objects.all()[0]
        point = Point()
        point.fromuser = user
        point.save()

        question = Question();
        question.user = user
        question.title = "hi"
        question.slug = 'something'
        question.text = 'else'
        question.save()
        question.points.add(point)
        question.save()
        
        self.assertEquals(1, question.total_points())
Exemple #4
0
    def test_user_points(self):
        josh = User.objects.all()[0]

        question = Question();
        question.user = josh
        question.title = "hi"
        question.slug = 'something'
        question.text = 'else'
        question.save()

        point = Point()
        point.fromuser = josh
        point.save()
        question.points.add(point)

        user = User()
        user.save()
        point = Point()
        point.fromuser = user
        point.save()
        question.points.add(point)

        self.assertEquals(2, userPoint(josh))