Skip to content
This repository has been archived by the owner on Mar 15, 2018. It is now read-only.

Commit

Permalink
make the search form lazier and cachier
Browse files Browse the repository at this point in the history
  • Loading branch information
jbalogh committed Mar 1, 2010
1 parent 6d5c3f2 commit af66a65
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 8 deletions.
5 changes: 0 additions & 5 deletions apps/search/context_processors.py

This file was deleted.

3 changes: 2 additions & 1 deletion apps/search/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,9 @@ class _SearchForm(forms.Form):
advanced = forms.BooleanField(widget=forms.HiddenInput)

# Attach these to the form for usage in the template.
app_versions = get_app_versions()
get_app_versions = staticmethod(get_app_versions)
top_level_cat = dict(top_level)
queryset = AppVersion.objects.filter(id__in=amo.APP_IDS)

# TODO(jbalogh): when we start using this form for zamboni search, it
# should check that the appid and lver match up using app_versions.
Expand Down
8 changes: 8 additions & 0 deletions apps/search/helpers.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import jingo

from . import forms


@jingo.register.function
def SearchForm(request):
return forms.SearchForm(request)
1 change: 0 additions & 1 deletion settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,6 @@
'amo.context_processors.app',
'amo.context_processors.i18n',
'amo.context_processors.global_settings',
'search.context_processors.search_form',
)

ROOT_URLCONF = '%s.urls' % ROOT_PACKAGE
Expand Down
5 changes: 4 additions & 1 deletion templates/search.html
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
{% set search_form = SearchForm(request) %}
{% cache search_form.queryset %}
{% set show_advanced = search_form.advanced.data == 'on' %}
<div class="search-form expanded-search-form {% if show_advanced %}expanded{% endif %}">
<form method="get" id="search-form" action="{{ url('search.search') }}">
Expand Down Expand Up @@ -60,8 +62,9 @@
</div>
</fieldset>
<span id="search-data"
data-appversions="{{ search_form.app_versions|json }}"></span>
data-appversions="{{ search_form.get_app_versions()|json }}"></span>
{{ search_form.advanced|safe }}
</div> {# advanced-search #}
</form>
</div>
{% endcache %}

0 comments on commit af66a65

Please sign in to comment.