blob: ff304f7b4188756bf67053359dd52621ca1abaa9 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
|
# -*- coding: utf-8 -*-
"""
tools for haystack search
"""
from haystack.query import SearchQuerySet
import itertools
def objects_of_sqs(sqs):
"""
return the corresponding model set of the SearchQuerySet
"""
if isinstance(sqs, SearchQuerySet):
return itertools.imap(lambda x: x.object, sqs)
else:
return sqs
def limit(seq, count=None):
"""
return the first 'count' items in 'seq'
if 'count=None', then all items returned
"""
return itertools.islice(seq, count)
|