示例#1
0
def _get_owner_results(query):
    # make sure all contacts have a user attached
    q = extension.owner_query(query)

    if q is None: return None

    if query.kw:
        # hard to handle - not supporting at the moment
        return Profile.objects.none()

    if query.owner:
        q = q.filter(user__username__icontains=query.owner)

    if query.extent:
        q = filter_by_extent(Map, q, query.extent, True) | \
             filter_by_extent(Layer, q, query.extent, True)

    if query.period:
        q = filter_by_period(Map, q, *query.period, user=True) | \
             filter_by_period(Layer, q, *query.period, user=True)

    if query.added:
        q = q.filter(user__date_joined__gt=query.added)

    if query.query:
        qs = Q(user__username__icontains=query.query) | \
             Q(user__first_name__icontains=query.query) | \
             Q(user__last_name__icontains=query.query)
        for field in extension.owner_query_fields:
            qs = qs | Q(**{'%s__icontains' % field: query.query})
        q = q.filter(qs)

        rules = _rank_rules(User,['username', 10, 5]) + \
                _rank_rules(Profile,['organization', 5, 2])
        added = extension.owner_rank_rules()
        if added:
            rules = rules + _rank_rules(*added)
        q = _safely_add_relevance(q, query, rules)

    return q.distinct()
示例#2
0
def _get_owner_results(query):
    # make sure all contacts have a user attached
    q = extension.owner_query(query)

    if q is None: return None

    if query.kw:
        # hard to handle - not supporting at the moment
        return Profile.objects.none()

    if query.owner:
        q = q.filter(user__username__icontains = query.owner)

    if query.extent:
        q = filter_by_extent(Map, q, query.extent, True) | \
             filter_by_extent(Layer, q, query.extent, True)

    if query.period:
        q = filter_by_period(Map, q, *query.period, user=True) | \
             filter_by_period(Layer, q, *query.period, user=True)

    if query.added:
        q = q.filter(user__date_joined__gt = query.added)

    if query.query:
        qs = Q(user__username__icontains=query.query) | \
             Q(user__first_name__icontains=query.query) | \
             Q(user__last_name__icontains=query.query)
        for field in extension.owner_query_fields:
            qs = qs | Q(**{'%s__icontains' % field: query.query})
        q = q.filter(qs)

        rules = _rank_rules(User,['username', 10, 5]) + \
                _rank_rules(Profile,['organization', 5, 2])
        added = extension.owner_rank_rules()
        if added:
            rules = rules + _rank_rules(*added)
        q = _safely_add_relevance(q, query, rules)

    return q.distinct()