13
13
from wlhelp.models import Building, Ware
14
14
from wlmaps.models import Map
16
17
class DummyEmptyQueryset(object):
18
A simple dummy class when a search
19
should not be run. The template expects
20
a queryset and checks for the count member.
18
"""A simple dummy class when a search should not be run.
20
The template expects a queryset and checks for the count member.
25
28
def search(request):
26
29
if request.method == 'POST':
27
30
form = SearchForm(request.POST)
29
32
if form.is_valid():
30
query = form.cleaned_data["search"]
31
do_wiki = form.cleaned_data["incl_wiki"]
32
do_forum = form.cleaned_data["incl_forum"]
33
do_news = form.cleaned_data["incl_news"]
34
do_help = form.cleaned_data["incl_help"]
35
do_maps = form.cleaned_data["incl_maps"]
33
query = form.cleaned_data['search']
34
do_wiki = form.cleaned_data['incl_wiki']
35
do_forum = form.cleaned_data['incl_forum']
36
do_news = form.cleaned_data['incl_news']
37
do_help = form.cleaned_data['incl_help']
38
do_maps = form.cleaned_data['incl_maps']
38
wlhelp_wares = Ware.search.query(query) if do_help else DummyEmptyQueryset()
39
wlhelp_buildings = Building.search.query(query) if do_help else DummyEmptyQueryset()
41
wlhelp_wares = Ware.search.query(
42
query) if do_help else DummyEmptyQueryset()
43
wlhelp_buildings = Building.search.query(
44
query) if do_help else DummyEmptyQueryset()
42
map_results = Map.search.query(query) if do_maps else DummyEmptyQueryset()
47
map_results = Map.search.query(
48
query) if do_maps else DummyEmptyQueryset()
45
wiki_results = Article.search.query(query) if do_wiki else DummyEmptyQueryset()
51
wiki_results = Article.search.query(
52
query) if do_wiki else DummyEmptyQueryset()
48
forum_results_topic = Topic.search.query(query) if do_forum else DummyEmptyQueryset()
49
forum_results_post = Post.search.query(query) if do_forum else DummyEmptyQueryset()
55
forum_results_topic = Topic.search.query(
56
query) if do_forum else DummyEmptyQueryset()
57
forum_results_post = Post.search.query(
58
query) if do_forum else DummyEmptyQueryset()
52
news_results = NewsPost.search.query(query) if do_news else DummyEmptyQueryset()
61
news_results = NewsPost.search.query(
62
query) if do_news else DummyEmptyQueryset()
54
64
template_params = {
55
"wiki_results": wiki_results,
57
"wlhelp_hits": wlhelp_wares.count() + wlhelp_buildings.count(),
58
"wlhelp_results_wares": wlhelp_wares,
59
"wlhelp_results_buildings": wlhelp_buildings,
61
"forum_hits": forum_results_post.count() + forum_results_topic.count(),
62
"forum_results_topic": forum_results_topic,
63
"forum_results_post": forum_results_post,
65
"map_results": map_results,
67
"news_results": news_results,
65
'wiki_results': wiki_results,
67
'wlhelp_hits': wlhelp_wares.count() + wlhelp_buildings.count(),
68
'wlhelp_results_wares': wlhelp_wares,
69
'wlhelp_results_buildings': wlhelp_buildings,
71
'forum_hits': forum_results_post.count() + forum_results_topic.count(),
72
'forum_results_topic': forum_results_topic,
73
'forum_results_post': forum_results_post,
75
'map_results': map_results,
77
'news_results': news_results,
73
return render_to_response("wlsearch/search.html",
75
context_instance=RequestContext(request))
83
return render_to_response('wlsearch/search.html',
85
context_instance=RequestContext(request))
77
87
form = SearchForm()
79
89
template_params = {
83
return render_to_response("wlsearch/search.html",
93
return render_to_response('wlsearch/search.html',
85
95
context_instance=RequestContext(request))