Skip to content

Commit

Permalink
Fix circular import
Browse files Browse the repository at this point in the history
  • Loading branch information
CamLamb committed Dec 16, 2024
1 parent 99df4c7 commit c493b61
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 14 deletions.
4 changes: 2 additions & 2 deletions src/content/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
from extended_search.index import DWIndexedField as IndexedField
from extended_search.index import Indexed, RelatedFields
from peoplefinder.widgets import PersonChooser
from search.utils import split_query
from user.models import User as UserModel


Expand Down Expand Up @@ -527,8 +526,9 @@ class SearchKeywordOrPhrase(models.Model):

class SearchKeywordOrPhraseQuerySet(models.QuerySet):
def filter_by_query(self, query):
query_parts = split_query(query)
from search.utils import split_query

query_parts = split_query(query)
return self.filter(search_keyword_or_phrase__keyword_or_phrase__in=query_parts)


Expand Down
15 changes: 9 additions & 6 deletions src/search/utils.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,21 @@
import re
import unicodedata
from typing import Optional
from typing import TYPE_CHECKING, Optional

from django.conf import settings
from django.urls import reverse
from wagtail.search.query import Fuzzy, Or, Phrase, PlainText

from content.models import BasePage
from extended_search import settings as search_settings
from extended_search.index import Indexed
from extended_search.query import Nested, OnlyFields
from extended_search.query_builder import CustomQueryBuilder
from news.models import NewsPage
from peoplefinder.models import Person, Team


if TYPE_CHECKING:
from content.models import BasePage
from peoplefinder.models import Person, Team


def sanitize_search_query(query: Optional[str] = None) -> str:
Expand Down Expand Up @@ -280,7 +283,7 @@ def get_content_author(page) -> dict:
return content_author


def get_page_export_row(page_result: BasePage, base_url: str) -> list[str]:
def get_page_export_row(page_result: "BasePage", base_url: str) -> list[str]:
content_owner = get_content_owner(page_result)
content_author = get_content_author(page_result)
return [
Expand All @@ -297,7 +300,7 @@ def get_page_export_row(page_result: BasePage, base_url: str) -> list[str]:
]


def get_person_export_row(person_result: Person, base_url: str) -> list[str]:
def get_person_export_row(person_result: "Person", base_url: str) -> list[str]:
return [
f"{person_result.first_name} {person_result.last_name}",
person_result.email,
Expand All @@ -307,7 +310,7 @@ def get_person_export_row(person_result: Person, base_url: str) -> list[str]:
]


def get_team_export_row(team_result: Team, base_url: str) -> list[str]:
def get_team_export_row(team_result: "Team", base_url: str) -> list[str]:
return [
team_result.name,
f"{base_url}{team_result.get_absolute_url()}",
Expand Down
14 changes: 8 additions & 6 deletions src/search/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,6 @@
from extended_search.settings import settings_singleton
from peoplefinder.models import Person, Team
from search.templatetags import search as search_template_tag
from search.utils import (
get_page_export_row,
get_person_export_row,
get_query_info_for_model,
get_team_export_row,
)


logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -108,6 +102,8 @@ def explore(request: HttpRequest) -> HttpResponse:
"""
Administrative view for exploring search options, boosts, etc
"""
from search.utils import get_query_info_for_model

if request.method == "POST":
if not request.user.has_perm("extended_search.change_setting"):
messages.error(request, "You are not authorised to edit settings")
Expand Down Expand Up @@ -150,6 +146,12 @@ def export_search(request: HttpRequest, category: str) -> HttpResponse:
"""
Administrative view for exporting search results as csv
"""
from search.utils import (
get_page_export_row,
get_person_export_row,
get_team_export_row,
)

query = request.GET.get("query", "")
if category == "all":
category = "all_pages"
Expand Down

0 comments on commit c493b61

Please sign in to comment.