DRY in forms
This commit is contained in:
parent
e6520c6e0a
commit
e0fcb4d369
1 changed files with 7 additions and 6 deletions
|
@ -287,21 +287,22 @@ class UserSearchForm(forms.Form):
|
||||||
#show_group = self.cleaned_data['show_group']
|
#show_group = self.cleaned_data['show_group']
|
||||||
sort_by = self.cleaned_data['sort_by']
|
sort_by = self.cleaned_data['sort_by']
|
||||||
sort_dir = self.cleaned_data['sort_dir']
|
sort_dir = self.cleaned_data['sort_dir']
|
||||||
|
qs = qs.filter(username__contains=username, forum_profile__post_count__gte=forum_settings.POST_USER_SEARCH)
|
||||||
if sort_by=='username':
|
if sort_by=='username':
|
||||||
if sort_dir=='ASC':
|
if sort_dir=='ASC':
|
||||||
return qs.filter(username__contains=username, forum_profile__post_count__gte=forum_settings.POST_USER_SEARCH).order_by('username')
|
return qs.order_by('username')
|
||||||
elif sort_dir=='DESC':
|
elif sort_dir=='DESC':
|
||||||
return qs.filter(username__contains=username, forum_profile__post_count__gte=forum_settings.POST_USER_SEARCH).order_by('-username')
|
return qs.order_by('-username')
|
||||||
elif sort_by=='registered':
|
elif sort_by=='registered':
|
||||||
if sort_dir=='ASC':
|
if sort_dir=='ASC':
|
||||||
return qs.filter(username__contains=username, forum_profile__post_count__gte=forum_settings.POST_USER_SEARCH).order_by('date_joined')
|
return qs.order_by('date_joined')
|
||||||
elif sort_dir=='DESC':
|
elif sort_dir=='DESC':
|
||||||
return qs.filter(username__contains=username, forum_profile__post_count__gte=forum_settings.POST_USER_SEARCH).order_by('-date_joined')
|
return qs.order_by('-date_joined')
|
||||||
elif sort_by=='num_posts':
|
elif sort_by=='num_posts':
|
||||||
if sort_dir=='ASC':
|
if sort_dir=='ASC':
|
||||||
return qs.filter(username__contains=username, forum_profile__post_count__gte=forum_settings.POST_USER_SEARCH).order_by('forum_profile__post_count')
|
return qs.order_by('forum_profile__post_count')
|
||||||
elif sort_dir=='DESC':
|
elif sort_dir=='DESC':
|
||||||
return qs.filter(username__contains=username, forum_profile__post_count__gte=forum_settings.POST_USER_SEARCH).order_by('-forum_profile__post_count')
|
return qs.order_by('-forum_profile__post_count')
|
||||||
else:
|
else:
|
||||||
return qs
|
return qs
|
||||||
|
|
||||||
|
|
Reference in a new issue