Exemple #1
0
def search_for_user(request, user_type='Any', extra='', returnList = False):
    """ Interface to search for a user. If you need a user, just use this.
        Returns (user or response, user returned?) """
    
    users = None
    error = False

    usc = UserSearchController()
    if isinstance(user_type, basestring):
        user_query = usc.query_from_criteria(user_type, request.GET)
        QSUsers = ESPUser.objects.filter(user_query).distinct()
    elif isinstance(user_type, QuerySet):
        QSUsers = usc.filter_from_criteria(user_type, request.GET)
    else:
        raise ESPError(True), 'Invalid user_type: %s' % type(user_type)
    
    #   We need to ask for more user input if no filtering options were selected
    if not usc.updated:
        users = None
    else:
        users = [ ESPUser(user) for user in QSUsers ]
    
    if users is not None and len(users) == 0:
        error = True
        users = None

    if users is None:
        return (render_to_response('users/usersearch.html', request, None, {'error': error, 'extra':extra,  'list': returnList}), False)
        
    if len(users) == 1:
        return (users[0], True)
        
    else:

        users.sort()

        if (request.GET.has_key('listokay') and request.GET['listokay'] == 'true') or \
           (request.GET.has_key('submitform') and request.GET['submitform'] == 'Use Filtered List'):
            Q_Filter = None
            if not hasattr(Q_include, 'old'):
                Q_Filter = Q_include
                if not hasattr(Q_exclude, 'old'):
                    Q_Filter &= ~Q_exclude
            else:
                if not hasattr(Q_exclude, 'old'):
                    Q_Filter = ~Q_exclude
            
            return (Q_Filter, True)
        
        context = {'users': users, 'extra':str(extra), 'list': returnList}

        return (render_to_response('users/userpick.html', request, None, context), False)

    print 'Ran into some kind of problem. %d users' % len(users)
Exemple #2
0
def search_for_user(request, user_type='Any', extra='', returnList=False):
    """ Interface to search for a user. If you need a user, just use this.
        Returns (user or response, user returned?) """

    users = None
    error = False

    usc = UserSearchController()
    if isinstance(user_type, basestring):
        user_query = usc.query_from_criteria(user_type, request.GET)
        QSUsers = ESPUser.objects.filter(user_query).distinct()
    elif isinstance(user_type, QuerySet):
        QSUsers = usc.filter_from_criteria(user_type, request.GET)
    else:
        raise ESPError('Invalid user_type: %s' % type(user_type), log=True)

    #   We need to ask for more user input if no filtering options were selected
    if not usc.updated:
        users = None
    else:
        users = [user for user in QSUsers]

    if users is not None and len(users) == 0:
        error = True
        users = None

    if users is None:
        return (render_to_response('users/usersearch.html', request, {
            'error': error,
            'extra': extra,
            'list': returnList
        }), False)

    if len(users) == 1:
        return (users[0], True)

    else:

        users.sort()

        if request.GET.get('listokay') == 'true' or \
           request.GET.get('submitform') == 'Use Filtered List':
            Q_Filter = Q(id__in=QSUsers.values_list('id', flat=True))
            return (Q_Filter, True)

        context = {'users': users, 'extra': str(extra), 'list': returnList}

        return (render_to_response('users/userpick.html', request,
                                   context), False)