def get_faqs(request): """ Display the FAQ page if there is no user query and allows users to search for terms The view will fetch the result from the search engine and display the results Uses :class:`~voyages.apps.help.models.Faq` and and :class:`~voyages.apps.help.models.FaqCategory` """ current_query = "" if request.method == "POST": # Convert the posted data into Haystack search form form = HighlightedSearchForm(request.POST) if form.is_valid(): # Perform the query by specifying the search term and sort orders (category and then questions) current_query = form.cleaned_data["q"] query_result = ( SearchQuerySet() .filter(content=current_query) .models(Faq) .order_by("faq_category_order", "faq_question_order") ) else: form = HighlightedSearchForm() query_result = SearchQuerySet().models(Faq).order_by("faq_category_order", "faq_question_order") else: # return the form if there is no form and display the entire faq (from the database) form = HighlightedSearchForm() query_result = SearchQuerySet().models(Faq).order_by("faq_category_order", "faq_question_order") faq_list = _sort_faq(query_result, request.LANGUAGE_CODE) return render(request, "help/page_faqs.html", {"form": form, "faq_list": faq_list, "current_query": current_query})
def __init__(self, arg, **kwargs): HighlightedSearchForm.__init__(self, arg, kwargs) #self.auto_id = False for f in self.fields: if isinstance(self.fields[f], forms.CharField) is True: self.fields[f].widget.attrs["class"] = "form-control" self.fields[f].widget.attrs['placeholder'] = \ "Search for author, book or part of the quote" self.fields[f].label = '' self.fields[f].help_text = ''
def glossary_page(request): """ Display the entire Glossary page if there is no user query and allows users to search for terms The view will fetch the result from the search engine and display the results. Uses :class:`~voyages.apps.help.models.Glossary` """ query = "" lang = request.LANGUAGE_CODE field = "glossary_term_lang_" + lang results = SearchQuerySet().models(Glossary) if request.method == "POST": form = HighlightedSearchForm(request.POST) if form.is_valid(): # Perform the query query = form.cleaned_data["q"] results = results.filter(content=query) else: form = HighlightedSearchForm() else: form = HighlightedSearchForm() results = results.order_by(field) letters, letters_found, glossary_content = _sort_glossary(results, lang) try: glossary_content = sorted(glossary_content, key=lambda k: k["letter"]) except: pass return render( request, "help/page_glossary.html", { "glossary": glossary_content, "letters": letters, "form": form, "letters_found": letters_found, "results": results, "query": query, }, )
def glossary_page(request): """ Display the entire Glossary page if there is no user query and allows users to search for terms The view will fetch the result from the search engine and display the results. Uses :class:`~voyages.apps.help.models.Glossary` """ query = "" lang = request.LANGUAGE_CODE field = 'glossary_term_lang_' + lang results = SearchQuerySet().models(Glossary) if request.method == 'POST': form = HighlightedSearchForm(request.POST) if form.is_valid(): # Perform the query query = form.cleaned_data['q'] results = results.filter(content=query) else: form = HighlightedSearchForm() else: form = HighlightedSearchForm() results = results.order_by(field) letters, letters_found, glossary_content = _sort_glossary(results, lang) try: glossary_content = sorted(glossary_content, key=lambda k: k['letter']) except: pass return render(request, 'help/page_glossary.html', {'glossary': glossary_content, 'letters': letters, 'form': form, 'letters_found': letters_found, 'results': results, 'query': query})
def glossary_page(request): """ Display the entire Glossary page if there is no user query and allows users to search for terms The view will fetch the result from the search engine and display the results. Uses :class:`~voyages.apps.help.models.Glossary` """ query = "" lang = request.LANGUAGE_CODE field = 'glossary_term_lang_' + lang results = SearchQuerySet().models(Glossary) if request.method == 'POST': form = HighlightedSearchForm(request.POST) if form.is_valid(): # Perform the query query = form.cleaned_data['q'] results = results.filter(content=query) else: form = HighlightedSearchForm() else: form = HighlightedSearchForm() results = results.order_by(field) letters, letters_found, glossary_content = _sort_glossary(results, lang) try: glossary_content = sorted(glossary_content, key=lambda k: k['letter']) except: pass return render( request, 'help/page_glossary.html', { 'glossary': glossary_content, 'letters': letters, 'form': form, 'letters_found': letters_found, 'results': results, 'query': query })
def get_faqs(request): """ Display the FAQ page if there is no user query and allows users to search for terms The view will fetch the result from the search engine and display the results Uses :class:`~voyages.apps.help.models.Faq` and and :class:`~voyages.apps.help.models.FaqCategory` """ current_query = '' if request.method == 'POST': # Convert the posted data into Haystack search form form = HighlightedSearchForm(request.POST) if form.is_valid(): # Perform the query by specifying the search term and sort orders (category and then questions) current_query = form.cleaned_data['q'] query_result = SearchQuerySet().filter( content=current_query).models(Faq).order_by( 'faq_category_order', 'faq_question_order') else: form = HighlightedSearchForm() query_result = SearchQuerySet().models(Faq).order_by( 'faq_category_order', 'faq_question_order') else: # return the form if there is no form and display the entire faq (from the database) form = HighlightedSearchForm() query_result = SearchQuerySet().models(Faq).order_by( 'faq_category_order', 'faq_question_order') faq_list = _sort_faq(query_result, request.LANGUAGE_CODE) return render(request, 'help/page_faqs.html', { 'form': form, "faq_list": faq_list, 'current_query': current_query })