Ejemplo n.º 1
0
    def test_user_num_solutions(self):
        u = user(save=True)
        q1 = question(save=True)
        q2 = question(save=True)
        a1 = answer(creator=u, question=q1, save=True)
        a2 = answer(creator=u, question=q2, save=True)

        eq_(user_num_solutions(u), 0)
        q1.solution = a1
        q1.save()
        eq_(user_num_solutions(u), 1)
        q2.solution = a2
        q2.save()
        eq_(user_num_solutions(u), 2)
        q1.solution = None
        q1.save()
        eq_(user_num_solutions(u), 1)
        a2.delete()
        eq_(user_num_solutions(u), 0)
Ejemplo n.º 2
0
    def test_user_num_solutions(self):
        u = user(save=True)
        q1 = question(save=True)
        q2 = question(save=True)
        a1 = answer(creator=u, question=q1, save=True)
        a2 = answer(creator=u, question=q2, save=True)

        eq_(user_num_solutions(u), 0)
        q1.solution = a1
        q1.save()
        eq_(user_num_solutions(u), 1)
        q2.solution = a2
        q2.save()
        eq_(user_num_solutions(u), 2)
        q1.solution = None
        q1.save()
        eq_(user_num_solutions(u), 1)
        a2.delete()
        eq_(user_num_solutions(u), 0)
Ejemplo n.º 3
0
def profile(request, user_id):
    user_profile = get_object_or_404(Profile, user__id=user_id,
                                     user__is_active=True)

    groups = user_profile.user.groups.all()
    return jingo.render(request, 'users/profile.html', {
        'profile': user_profile,
        'groups': groups,
        'num_questions': user_num_questions(user_profile.user),
        'num_answers': user_num_answers(user_profile.user),
        'num_solutions': user_num_solutions(user_profile.user)
    })
Ejemplo n.º 4
0
def profile(request, user_id):
    user_profile = get_object_or_404(Profile,
                                     user__id=user_id,
                                     user__is_active=True)

    groups = user_profile.user.groups.all()
    return jingo.render(
        request, 'users/profile.html', {
            'profile': user_profile,
            'groups': groups,
            'num_questions': user_num_questions(user_profile.user),
            'num_answers': user_num_answers(user_profile.user),
            'num_solutions': user_num_solutions(user_profile.user)
        })
Ejemplo n.º 5
0
def profile(request, template, user_id):
    user_profile = get_object_or_404(
        Profile, user__id=user_id)

    if not (request.user.has_perm('users.deactivate_users')
            or user_profile.user.is_active):
        raise Http404('No Profile matches the given query.')

    groups = user_profile.user.groups.all()
    return render(request, template, {
        'profile': user_profile,
        'groups': groups,
        'num_questions': user_num_questions(user_profile.user),
        'num_answers': user_num_answers(user_profile.user),
        'num_solutions': user_num_solutions(user_profile.user),
        'num_documents': user_num_documents(user_profile.user)})
Ejemplo n.º 6
0
def profile(request, template, user_id):
    user_profile = get_object_or_404(Profile, user__id=user_id)

    if not (request.user.has_perm('users.deactivate_users')
            or user_profile.user.is_active):
        raise Http404('No Profile matches the given query.')

    groups = user_profile.user.groups.all()
    return render(
        request, template, {
            'profile': user_profile,
            'groups': groups,
            'num_questions': user_num_questions(user_profile.user),
            'num_answers': user_num_answers(user_profile.user),
            'num_solutions': user_num_solutions(user_profile.user),
            'num_documents': user_num_documents(user_profile.user)
        })