Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge pull request #25 from ramiro/ticket-17385

Init release dropdown in search form with currently shown version value.
  • Loading branch information...
commit 483ce6b00571fc3e2ded7e5d98d0bf5b3dce066e 2 parents 69ca152 + 396f5ba
@jezdez jezdez authored
View
10 django_website/docs/forms.py
@@ -7,12 +7,16 @@
class DocSearchForm(haystack.forms.SearchForm):
- def __init__(self, *args, **kwargs):
+ def __init__(self, version, *args, **kwargs):
super(DocSearchForm, self).__init__(*args, **kwargs)
self.fields['q'].widget = SearchInput()
+ try:
+ rel = DocumentRelease.objects.get(version=version)
+ except DocumentRelease.DoesNotExist:
+ rel = DocumentRelease.objects.default()
self.fields['release'] = DocumentReleaseChoiceField(
queryset = DocumentRelease.objects.all().order_by('version'),
- initial = DocumentRelease.objects.default(),
+ initial = rel,
empty_label = None,
required = False,
)
@@ -29,4 +33,4 @@ def label_from_instance(self, obj):
return obj.human_version
class SearchInput(forms.TextInput):
- input_type = 'search'
+ input_type = 'search'
View
3  django_website/docs/templatetags/docs.py
@@ -10,9 +10,10 @@
@register.inclusion_tag('docs/search_form.html', takes_context=True)
def search_form(context, search_form_id='sidebar_search'):
request = context['request']
+ version = context['version']
auto_id = 'id_%s_%%s' % search_form_id
return {
- 'form': DocSearchForm(initial=request.GET, auto_id=auto_id),
+ 'form': DocSearchForm(version, initial=request.GET, auto_id=auto_id),
'search_form_id': search_form_id,
}
Please sign in to comment.
Something went wrong with that request. Please try again.