Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add checks that person_type and news_type queries are numerical and i… #1148

Merged
merged 2 commits into from
Apr 4, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion opentech/public/news/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ def get_context(self, request, *args, **kwargs):
'authors__author',
)

if request.GET.get('news_type'):
if request.GET.get('news_type') and request.GET.get('news_type').isdigit():
news = news.filter(news_types__news_type=request.GET.get('news_type'))

# Pagination
Expand Down
2 changes: 1 addition & 1 deletion opentech/public/people/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ def get_context(self, request, *args, **kwargs):
'person_types__person_type',
)

if request.GET.get('person_type'):
if request.GET.get('person_type') and request.GET.get('person_type').isdigit():
people = people.filter(person_types__person_type=request.GET.get('person_type'))

if not request.GET.get('include_inactive') == 'true':
Expand Down
6 changes: 6 additions & 0 deletions opentech/public/search/views.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import re

from django.conf import settings
from django.core.paginator import EmptyPage, PageNotAnInteger, Paginator
from django.http import Http404
Expand All @@ -17,6 +19,10 @@ def search(request):

# Search
if search_query:
# Allow only word characters and spaces in search query.
words = re.findall('\w+', search_query.strip())
search_query = ' '.join(words)

public_site = request.site.root_page

search_results = Page.objects.live().descendant_of(
Expand Down