Esempio n. 1
0
def profile(request, template, user_id):
    # The browser replaces '+' in URL's with ' ' but since we never have ' ' in
    # URL's we can assume everytime we see ' ' it was a '+' that was replaced.
    # We do this to deal with legacy usernames that have a '+' in them.
    user_id = user_id.replace(' ', '+')

    user = User.objects.filter(username=user_id).first()

    if not user:
        try:
            user = get_object_or_404(User, id=user_id)
        except ValueError:
            raise Http404('No Profile matches the given query.')
        return redirect(reverse('users.profile', args=(user.username,)))

    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)})
Esempio n. 2
0
def profile(request, template, user_id):
    # The browser replaces '+' in URL's with ' ' but since we never have ' ' in
    # URL's we can assume everytime we see ' ' it was a '+' that was replaced.
    # We do this to deal with legacy usernames that have a '+' in them.
    user_id = user_id.replace(' ', '+')

    user = User.objects.filter(username=user_id).first()

    if not user:
        try:
            user = get_object_or_404(User, id=user_id)
        except ValueError:
            raise Http404('No Profile matches the given query.')
        return redirect(reverse('users.profile', args=(user.username, )))

    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)
        })
Esempio n. 3
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)
Esempio n. 4
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)
Esempio 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)})
Esempio 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)})
Esempio n. 7
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),
        },
    )