Fixed sidebar search support
This commit is contained in:
@@ -6,7 +6,12 @@ from dynamic_search.api import registered_search_dict
|
||||
|
||||
class SearchForm(forms.Form):
|
||||
q = forms.CharField(max_length=128, label=_(u'Search terms'))
|
||||
|
||||
source = forms.CharField(
|
||||
max_length=32,
|
||||
required=False,
|
||||
widget=forms.widgets.HiddenInput()
|
||||
)
|
||||
|
||||
|
||||
class AdvancedSearchForm(forms.Form):
|
||||
def __init__(self, *args, **kwargs):
|
||||
|
||||
@@ -41,7 +41,6 @@ class RecentSearch(models.Model):
|
||||
advanced_string.append(u'%s: %s' % (model_field.get('title', model_field['name']), u' '.join(value)))
|
||||
|
||||
display_string = u', '.join(advanced_string)
|
||||
|
||||
return u'%s (%s)' % (display_string, self.hits)
|
||||
|
||||
def save(self, *args, **kwargs):
|
||||
|
||||
@@ -12,10 +12,10 @@ register = Library()
|
||||
@register.inclusion_tag('search_results_subtemplate.html', takes_context=True)
|
||||
def search_form(context):
|
||||
context.update({
|
||||
'form': SearchForm(initial={'q': context.get('query_string', '')}),
|
||||
'form': SearchForm(initial={'q': context.get('query_string', {}).get('q'), 'source': 'sidebar'}),
|
||||
'request': context['request'],
|
||||
'MEDIA_URL': context['MEDIA_URL'],
|
||||
'form_action': reverse('results'),
|
||||
'form_action': reverse('search'),
|
||||
'form_title': _(u'Search'),
|
||||
'submit_label': _(u'Search'),
|
||||
'submit_icon_famfam': 'zoom',
|
||||
@@ -26,7 +26,6 @@ def search_form(context):
|
||||
@register.inclusion_tag('generic_subtemplate.html', takes_context=True)
|
||||
def recent_searches_template(context):
|
||||
recent_searches = RecentSearch.objects.filter(user=context['user'])
|
||||
|
||||
context.update({
|
||||
'request': context['request'],
|
||||
'MEDIA_URL': context['MEDIA_URL'],
|
||||
@@ -40,5 +39,4 @@ def recent_searches_template(context):
|
||||
} for rs in recent_searches
|
||||
]
|
||||
})
|
||||
|
||||
return context
|
||||
|
||||
@@ -79,22 +79,27 @@ def search(request, advanced=False):
|
||||
context_instance=RequestContext(request)
|
||||
)
|
||||
else:
|
||||
extra_context = {
|
||||
'submit_label': _(u'Search'),
|
||||
'submit_icon_famfam': 'zoom',
|
||||
'form_title': _(u'Search'),
|
||||
'form_hide_required_text': True,
|
||||
}
|
||||
|
||||
if ('q' in request.GET) and request.GET['q'].strip():
|
||||
query_string = request.GET['q']
|
||||
form = SearchForm(initial={'q': query_string})
|
||||
extra_context.update({'form': form})
|
||||
return results(request, extra_context=extra_context)
|
||||
if request.GET.get('source') != 'sidebar':
|
||||
# Don't include a form a top of the results if the search
|
||||
# was originated from the sidebar search form
|
||||
extra_context = {
|
||||
'submit_label': _(u'Search'),
|
||||
'submit_icon_famfam': 'zoom',
|
||||
'form_title': _(u'Search'),
|
||||
'form_hide_required_text': True,
|
||||
}
|
||||
if ('q' in request.GET) and request.GET['q'].strip():
|
||||
query_string = request.GET['q']
|
||||
form = SearchForm(initial={'q': query_string})
|
||||
extra_context.update({'form': form})
|
||||
return results(request, extra_context=extra_context)
|
||||
else:
|
||||
form = SearchForm()
|
||||
extra_context.update({'form': form})
|
||||
return results(request, extra_context=extra_context)
|
||||
else:
|
||||
form = SearchForm()
|
||||
extra_context.update({'form': form})
|
||||
return results(request, extra_context=extra_context)
|
||||
# Already has a form with data, go to results
|
||||
return results(request)
|
||||
|
||||
|
||||
def search_again(request):
|
||||
|
||||
Reference in New Issue
Block a user