<commit_before>"""Template tags used by the site search application."""


from django import template

from cms.apps.pages.templatetags import PatternNode
from cms.apps.pages.models import Page


register = template.Library()


@register.tag
def search_form(parser, token):
    """Renders the Google Custom Search Engine search form."""
    def handler(context, search_page, form_id="cse-search-box"):
        request = context["request"]
        search_term = request.GET.get("q", "")
        search_page = Page.objects.get_page(search_page)
        context.push()
        try:
            context.update({"search_page": search_page,
                            "form_id": form_id,
                            "search_term": search_term})
            return template.loader.render_to_string("search/form.html", context)
        finally:
            context.pop()
    return PatternNode(parser, token, handler, ("{search_page} {form_id}", "{search_page}",))

<commit_msg>Made search_form fail silently if cannot find page by permalink.<commit_after>"""Template tags used by the site search application."""


from django import template

from cms.apps.pages.templatetags import PatternNode
from cms.apps.pages.models import Page


register = template.Library()


@register.tag
def search_form(parser, token):
    """Renders the Google Custom Search Engine search form."""
    def handler(context, search_page, form_id="cse-search-box"):
        request = context["request"]
        try:
            search_page = Page.objects.get_page(search_page)
        except Page.DoesNotExist:
            return ""
        search_term = request.GET.get("q", "")
        context.push()
        try:
            context.update({"search_page": search_page,
                            "form_id": form_id,
                            "search_term": search_term})
            return template.loader.render_to_string("search/form.html", context)
        finally:
            context.pop()
    return PatternNode(parser, token, handler, ("{search_page} {form_id}", "{search_page}",))


{'fraction_non_alphanumeric': 0.11423039690222653, 'fraction_numerical': 0.0, 'mean_word_length': 2.7377938517179023, 'pattern_counts': {'":': 6, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7578109', 'n_tokens_mistral': 565, 'n_tokens_neox': 564, 'n_words': 142}