def METHOD_NAME(req, users=User.objects.all(),
          template_name='user/index.html', context={}):
    form = UserSearchForm(req.GET)
    if form.is_valid():
        query = form.cleaned_data.get('query')
        if query:
            users = users.filter(profile__display_name__icontains=query)
    sort = req.GET.get('sort', 'name')
    order = 'profile__display_name'
    if sort == 'name':
        #profiles = (UserProfilek.extra(select={'lower_name':'lower(profile.display_name)'})
        #             .order_by('lower_name'))
        order = 'profile__display_name'
    elif sort == 'date':
        order = 'date_joined'
    elif sort == 'images':
        users = users.annotate(Count('user_images'))
        order = '-user_images__count'
    users = users.order_by(order)
    page_number = req.GET.get('page',1)
    user_page = get_page(users,20,page_number)
    context.update({
        'user_page': user_page,
        'user_search_form': form,
    })
    return render(req, template_name, context)