* Bugfix for double results in "show own posts" * Don't put user_id in GET -> use request.user * remove {% if results %} with {% for %}...{% empty %} * Refactor search()
Fixed topic search results which returned nothing. Return a list instead of a generator in TopicFromPostResult.__getitem__() so that the pagination can work correctly. from: https://bitbucket.org/hsoft/djangobb/changeset/1b2f31c54c516c699a7b11a1d43b170742157df5 use the slow, but correct solution for display the result as topics used fast solution with a work-a-round for double topics respect sort order count only one time better solution, but slow with woosh and many hits change info make it DRY remove debug imports remove not needed tuple() * add "show your topics/posts" search * add link to switch between topics/posts search * merge {% block controls %} * make search_posts.html useable with queryset and SearchQuerySet Add topic <-> post switch links to other type of search, too. not really in GET needed. * Use PostSearchForm() in normal search * add switch links to normal search, too. better docstring better text?
This commit is contained in:
parent
c566df87ed
commit
48ed192424
8 changed files with 222 additions and 188 deletions
|
@ -134,7 +134,7 @@ class ExcludeTagsHTMLParser(HTMLParser):
|
|||
self.html.append(data)
|
||||
|
||||
def handle_startendtag(self, tag, attrs):
|
||||
self.html.append('<%s%s/>' % (tag, self.__html_attrs(attrs)))
|
||||
self.html.append('<%s%s/>' % (tag, self.__html_attrs(attrs)))
|
||||
|
||||
def handle_endtag(self, tag):
|
||||
self.is_ignored = False
|
||||
|
@ -153,7 +153,7 @@ class ExcludeTagsHTMLParser(HTMLParser):
|
|||
def __html_attrs(self, attrs):
|
||||
_attrs = ''
|
||||
if attrs:
|
||||
_attrs = ' %s' % (' '.join([('%s="%s"' % (k,v)) for k,v in attrs]))
|
||||
_attrs = ' %s' % (' '.join([('%s="%s"' % (k, v)) for k, v in attrs]))
|
||||
return _attrs
|
||||
|
||||
def feed(self, data):
|
||||
|
@ -202,7 +202,7 @@ def paginate(items, request, per_page, total_count=None):
|
|||
paged_list_name = paginator.page(page_number).object_list
|
||||
except (InvalidPage, EmptyPage):
|
||||
raise Http404
|
||||
return pages, paginator, paged_list_name
|
||||
return pages, paginator, paged_list_name
|
||||
|
||||
def set_language(request, language):
|
||||
"""
|
||||
|
@ -222,27 +222,3 @@ def convert_text_to_html(text, markup):
|
|||
raise Exception('Invalid markup property: %s' % markup)
|
||||
return urlize(text)
|
||||
|
||||
|
||||
class TopicFromPostResult(object):
|
||||
"""
|
||||
Custom Result object to return topics from a post search.
|
||||
|
||||
This function uses a generator to return topic objects from
|
||||
results given by haystack on a post query. This eliminates
|
||||
loading a large array of topic objects into memory.
|
||||
"""
|
||||
|
||||
def __init__(self, posts):
|
||||
self.posts = posts
|
||||
|
||||
def __len__(self):
|
||||
return len(self.posts)
|
||||
|
||||
def __getitem__(self, key):
|
||||
if isinstance(key, slice):
|
||||
return (self.posts[i].object.topic
|
||||
for i in xrange(*key.indices(len(self))))
|
||||
elif isinstance(key, int):
|
||||
return self.posts[key].object.topic
|
||||
|
||||
raise TypeError('unknown type in key for __getitem__')
|
||||
|
|
Reference in a new issue