def test_user_num_questions(self): """Answers are counted correctly on a user.""" u = user(save=True) eq_(user_num_questions(u), 0) q1 = question(creator=u, save=True) eq_(user_num_questions(u), 1) q2 = question(creator=u, save=True) eq_(user_num_questions(u), 2) q1.delete() eq_(user_num_questions(u), 1) q2.delete() eq_(user_num_questions(u), 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)})
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) })
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)})
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), }, )