Пример #1
0
def search(request):
    limit = None
    nonvouched_only = False
    people = []
    size_exceeded = False
    show_pagination = False
    form = forms.SearchForm(request.GET)

    if form.is_valid():
        query = form.cleaned_data.get('q', '')
        limit = form.cleaned_data['limit']
        nonvouched_only = form.cleaned_data['nonvouched_only']

        if request.user.is_authenticated():
            ldap = UserSession.connect(request)
            try:
                # Stale data okay
                sortk = attrgetter('full_name')
                people = sorted(ldap.search(query,
                                            nonvouched_only=nonvouched_only),
                                key=sortk)

                # Search based on group name as well
                groups = Group.objects.filter(name__icontains=query)[:limit]
                for group in groups:
                    for user in users_from_groups(
                            request,
                            group,
                            limit=forms.PAGINATION_LIMIT,
                            nonvouched_only=nonvouched_only):
                        if not user.unique_id in [p.unique_id for p in people]:
                            people.append(user)

                paginator = Paginator(people, limit)
                page = request.GET.get('page', 1)
                try:
                    people = paginator.page(page)
                except PageNotAnInteger:
                    people = paginator.page(1)
                except EmptyPage:
                    people = paginator.page(paginator.num_pages)

                if paginator.count > forms.PAGINATION_LIMIT:
                    show_pagination = True

            except SIZELIMIT_EXCEEDED:
                size_exceeded = True

            if len(people) == 1 and not show_pagination:
                return redirect(reverse('profile', args=[people[0].unique_id]))

    d = dict(people=people,
             form=form,
             limit=limit,
             nonvouched_only=nonvouched_only,
             show_pagination=show_pagination,
             size_exceeded_error=size_exceeded)
    return render(request, 'phonebook/search.html', d)
Пример #2
0
def search(request):
    num_pages = 0
    limit = None
    nonvouched_only = False
    picture_only = False
    people = []
    show_pagination = False
    form = forms.SearchForm(request.GET)
    groups = None
    curated_groups = None

    if form.is_valid():
        query = form.cleaned_data.get('q', u'')
        limit = form.cleaned_data['limit']
        vouched = False if form.cleaned_data['nonvouched_only'] else None
        profilepic = True if form.cleaned_data['picture_only'] else None
        page = request.GET.get('page', 1)
        curated_groups = Group.get_curated()

        # If nothing has been entered don't load any searches.
        if not (not query and vouched is None and profilepic is None):
            profiles = UserProfile.search(query,
                                          vouched=vouched,
                                          photo=profilepic)
            groups = Group.search(query)

            paginator = Paginator(profiles, limit)

            try:
                people = paginator.page(page)
            except PageNotAnInteger:
                people = paginator.page(1)
            except EmptyPage:
                people = paginator.page(paginator.num_pages)

            if len(profiles) == 1 and not groups:
                return redirect(
                    reverse('profile', args=[people[0].user.username]))

            if paginator.count > forms.PAGINATION_LIMIT:
                show_pagination = True
                num_pages = len(people.paginator.page_range)

    d = dict(people=people,
             form=form,
             limit=limit,
             nonvouched_only=nonvouched_only,
             picture_only=picture_only,
             show_pagination=show_pagination,
             num_pages=num_pages,
             groups=groups,
             curated_groups=curated_groups)

    if request.is_ajax():
        return render(request, 'search_ajax.html', d)

    return render(request, 'phonebook/search.html', d)
Пример #3
0
def show(request, id, url=None):
    """ List all users with this group."""
    group = get_object_or_404(Group, id=id)
    if not url:
        redirect(reverse('group', args=[group.id, group.url]))
    form = forms.SearchForm(request.GET)
    limit = forms.PAGINATION_LIMIT
    if form.is_valid():
        limit = form.cleaned_data['limit']

    in_group = (request.user.get_profile().groups.filter(id=group.id).count())
    profiles = group.userprofile_set.all()
    page = request.GET.get('page', 1)
    paginator = Paginator(profiles, limit)
    people = []
    try:
        people = paginator.page(page)
    except PageNotAnInteger:
        people = paginator.page(1)
    except EmptyPage:
        people = paginator.page(paginator.num_pages)

    show_pagination = False
    num_pages = 0
    if paginator.count > forms.PAGINATION_LIMIT:
        show_pagination = True
        num_pages = len(people.paginator.page_range)

    d = dict(people=people,
             group=group,
             in_group=in_group,
             form=form,
             limit=limit,
             show_pagination=show_pagination,
             num_pages=num_pages)

    if group.steward:
        # Get the 15 most globally popular skills that appear in the group
        skills = [
            s.name for s in Skill.objects.filter(
                userprofile__group__id=group.id).annotate(
                    users=Count('userprofile')).order_by('users')
        ][:15]
        d.update(skills=skills)
        d.update(irc_channels=group.irc_channel.split(' '))
        d.update(members=UserProfile.objects.filter(groups=group).count())

    if request.is_ajax():
        return render(request, 'search_ajax.html', d)

    return render(request, 'groups/group.html', d)
Пример #4
0
def search(request):
    num_pages = 0
    limit = None
    nonvouched_only = False
    people = []
    show_pagination = False
    form = forms.SearchForm(request.GET)

    if form.is_valid():
        query = form.cleaned_data.get('q', '')
        limit = form.cleaned_data['limit']
        vouched = False if form.cleaned_data['nonvouched_only'] else None
        page = request.GET.get('page', 1)

        profiles = UserProfile.search(query, vouched=vouched)

        paginator = Paginator(profiles, limit)

        try:
            people = paginator.page(page)
        except PageNotAnInteger:
            people = paginator.page(1)
        except EmptyPage:
            people = paginator.page(paginator.num_pages)

        if paginator.count > forms.PAGINATION_LIMIT:
            show_pagination = True
            num_pages = len(people.paginator.page_range)

    d = dict(people=people,
             form=form,
             limit=limit,
             nonvouched_only=nonvouched_only,
             show_pagination=show_pagination,
             num_pages=num_pages)

    if request.is_ajax():
        return render(request, 'phonebook/search_ajax.html', d)

    return render(request, 'phonebook/search.html', d)