Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Init release dropdown in search form with currently shown version value.

  • Loading branch information...
commit 396f5ba3601ee9f5f0139f522e2e0ea2deaa0f6b 1 parent 69ca152
Ramiro Morales authored December 12, 2011
10  django_website/docs/forms.py
@@ -7,12 +7,16 @@
7 7
 
8 8
 class DocSearchForm(haystack.forms.SearchForm):
9 9
 
10  
-    def __init__(self, *args, **kwargs):
  10
+    def __init__(self, version, *args, **kwargs):
11 11
         super(DocSearchForm, self).__init__(*args, **kwargs)
12 12
         self.fields['q'].widget = SearchInput()
  13
+        try:
  14
+            rel = DocumentRelease.objects.get(version=version)
  15
+        except DocumentRelease.DoesNotExist:
  16
+            rel = DocumentRelease.objects.default()
13 17
         self.fields['release'] = DocumentReleaseChoiceField(
14 18
             queryset = DocumentRelease.objects.all().order_by('version'),
15  
-            initial = DocumentRelease.objects.default(),
  19
+            initial = rel,
16 20
             empty_label = None,
17 21
             required = False,
18 22
         )
@@ -29,4 +33,4 @@ def label_from_instance(self, obj):
29 33
         return obj.human_version
30 34
 
31 35
 class SearchInput(forms.TextInput):
32  
-    input_type = 'search'
  36
+    input_type = 'search'
3  django_website/docs/templatetags/docs.py
@@ -10,9 +10,10 @@
10 10
 @register.inclusion_tag('docs/search_form.html', takes_context=True)
11 11
 def search_form(context, search_form_id='sidebar_search'):
12 12
     request = context['request']
  13
+    version = context['version']
13 14
     auto_id = 'id_%s_%%s' % search_form_id
14 15
     return {
15  
-        'form': DocSearchForm(initial=request.GET, auto_id=auto_id),
  16
+        'form': DocSearchForm(version, initial=request.GET, auto_id=auto_id),
16 17
         'search_form_id': search_form_id,
17 18
     }
18 19
 

0 notes on commit 396f5ba

Please sign in to comment.
Something went wrong with that request. Please try again.