add filter to show user profile

This commit is contained in:
alafin 2009-04-15 10:29:12 +03:00
parent e0de4973d7
commit 5b0d2cb071
3 changed files with 10 additions and 19 deletions

View file

@ -256,19 +256,19 @@ class UserSearchForm(forms.Form):
sort_dir = self.cleaned_data['sort_dir']
if sort_by=='username':
if sort_dir=='ASC':
return qs.filter(username__contains=username).order_by('username')
return qs.filter(username__contains=username, forum_profile__post_count__gte=forum_settings.POST_USER_SEARCH).order_by('username')
elif sort_dir=='DESC':
return qs.filter(username__contains=username).order_by('-username')
return qs.filter(username__contains=username, forum_profile__post_count__gte=forum_settings.POST_USER_SEARCH).order_by('-username')
elif sort_by=='registered':
if sort_dir=='ASC':
return qs.filter(username__contains=username).order_by('date_joined')
return qs.filter(username__contains=username, forum_profile__post_count__gte=forum_settings.POST_USER_SEARCH).order_by('date_joined')
elif sort_dir=='DESC':
return qs.filter(username__contains=username).order_by('-date_joined')
return qs.filter(username__contains=username, forum_profile__post_count__gte=forum_settings.POST_USER_SEARCH).order_by('-date_joined')
elif sort_by=='num_posts':
if sort_dir=='ASC':
return qs.filter(username__contains=username).order_by('forum_profile__post_count')
return qs.filter(username__contains=username, forum_profile__post_count__gte=forum_settings.POST_USER_SEARCH).order_by('forum_profile__post_count')
elif sort_dir=='DESC':
return qs.filter(username__contains=username).order_by('-forum_profile__post_count')
return qs.filter(username__contains=username, forum_profile__post_count__gte=forum_settings.POST_USER_SEARCH).order_by('-forum_profile__post_count')
else:
return qs

View file

@ -23,6 +23,7 @@ NOTICE = get('NOTICE', '')
HOST = get('HOST', 'localhost:8000')
USER_ONLINE_TIMEOUT = get('USER_ONLINE_TIMEOUT', 15)
EMAIL_DEBUG = get('FORUM_EMAIL_DEBUG', False)
POST_USER_SEARCH = get('POST_USER_SEARCH', 1)
# GRAVATAR Extension
GRAVATAR_SUPPORT = get('GRAVATAR_SUPPORT', True)

View file

@ -25,8 +25,6 @@ from forum.templatetags import forum_extras
from forum import settings as forum_settings
from forum.util import urlize, smiles
from forum.index import post_indexer
from forum.orm import load_related
@render_to('forum/index.html')
def index(request, full=True):
@ -394,16 +392,6 @@ def user(request, username):
user = get_object_or_404(User, username=username)
if request.user.is_authenticated() and user == request.user or request.user.is_superuser:
if 'section' in request.GET:
#if 'admin' in request.GET['section'] and request.user.is_superuser:
# form = build_form(AdminProfileForm, request, instance=user.forum_profile)
# if request.POST and form.is_valid():
# form.save()
# return render_to_response('forum/profile/profile_admin.html',
# {'active_menu':'admin',
# 'profile': user,
# #'form': form,
# 'reports': reports,
# }, RequestContext(request))
section = request.GET['section']
if section == 'privacy':
form = build_form(PrivacyProfileForm, request, instance=user.forum_profile)
@ -485,6 +473,8 @@ def user(request, username):
else:
topic_count = Topic.objects.filter(user=user).count()
if user.forum_profile.post_count < forum_settings.POST_USER_SEARCH and not request.user.is_authenticated():
return HttpResponseRedirect(reverse('auth_login') + '?next=%s' % request.path)
return {'profile': user,
'topic_count': topic_count,
}
@ -708,7 +698,7 @@ def open_topic(request, topic_id):
@render_to('forum/users.html')
@paged('users', forum_settings.USERS_PAGE_SIZE)
def users(request):
users = User.objects.order_by('username')
users = User.objects.filter(forum_profile__post_count__gte=forum_settings.POST_USER_SEARCH).order_by('username')
form = UserSearchForm(request.GET)
users = form.filter(users)
return {'paged_qs': users,