diff --git a/scipost/forms.py b/scipost/forms.py index 7c5cf4bf63277f3c13f4fcb26e3980a892e69b4d..59420f21f92f804da88831fc1bf61b84e82d3627 100644 --- a/scipost/forms.py +++ b/scipost/forms.py @@ -695,6 +695,12 @@ class SearchForm(HayStackSearchForm): start = forms.DateField(widget=MonthYearWidget(), required=False) # Month end = forms.DateField(widget=MonthYearWidget(end=True), required=False) # Month + def clean_q(self): + q = self.cleaned_data.get('q', '') + # Block queries matching flagged regex to avoid gunicorn worker timeout + if re.search(r'\w+.cn', q): + raise Http404 + return q def search(self): if not self.is_valid(): @@ -703,10 +709,6 @@ class SearchForm(HayStackSearchForm): if not self.cleaned_data.get("q"): return self.no_query_found() - # Block queries matching flagged regex to avoid gunicorn worker timeout - if re.search(r'\w+.cn', self.cleaned_data["q"]): - raise Http404 - sqs = self.searchqueryset.auto_query(self.cleaned_data["q"]) if self.load_all: diff --git a/scipost/urls.py b/scipost/urls.py index a425c6d1950f3efb64868724b82f734d1b8b31d0..bc17384655643726893958ff1211c9bf751b9572 100644 --- a/scipost/urls.py +++ b/scipost/urls.py @@ -53,7 +53,7 @@ urlpatterns = [ ), # Search - url(r'^search', views.SearchView.as_view(), name='search'), + url(r'^search$', views.SearchView.as_view(), name='search'), url(r'^$', views.index, name='index'), url(r'^files/secure/(?P<path>.*)$', views.protected_serve, name='secure_file'), diff --git a/scipost/views.py b/scipost/views.py index 15cd8c6212e912a41bb5e7eca47d5d426993d7f9..50e0dcffc379935e39b4c0448df0f5660fa80c0a 100644 --- a/scipost/views.py +++ b/scipost/views.py @@ -152,7 +152,6 @@ class SearchView(SearchView): def get_context_data(self, *args, **kwargs): """Update context with some additional information.""" ctx = super().get_context_data(*args, **kwargs) - ctx['search_query'] = self.request.GET.get('q') ctx['results_count'] = kwargs['object_list'].count() return ctx