Skip to content

Commit

Permalink
backup for code
Browse files Browse the repository at this point in the history
  • Loading branch information
daniel-gray-tangent committed Jul 24, 2024
1 parent 41fdf46 commit 16e86f0
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 3 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,5 @@ app/media/
/logging/
/pdf_uploads/
/pdf_upload_completed/
/tmp/
/tmp/app_punt_env
13 changes: 12 additions & 1 deletion app/general/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,16 @@ def filter_queryset(self, queryset):

# A fixed list of identical fields are required to join queries of
# different classes with `.union()`:
fields = ("id", "heading", "description", "rank", "search_headline", "view")
fields = (
"id",
"heading",
"description",
"rank",
"search_headline",
"view",
"logo_url",
"logo_url",
)

# In the queries below, any differences between models must be fixed
# through e.g. `Value` or `F` annotations.
Expand All @@ -59,6 +68,7 @@ def filter_queryset(self, queryset):
Project.objects.annotate(
heading=F("name"),
view=Value("project_detail"),
logo_url=F("logo"),
search_headline=SearchHeadline("description", query),
rank=SearchRank(project_search_vector, query, normalization=16),
search=project_search_vector,
Expand All @@ -74,6 +84,7 @@ def filter_queryset(self, queryset):
queryset = queryset.annotate(
heading=F("title"),
view=Value("document_detail"),
logo_url=Value("no_logo"),
rank=search_rank,
search_headline=search_headline,
).values(*fields)
Expand Down
10 changes: 8 additions & 2 deletions app/templates/app/search.html
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,20 @@ <h5 class="card-title">{% trans "Search a term" %}</h5>
<div class="container">
{% for result in search_results %}
<div>
<h3><a href="{% url result.view result.id %}">{{ result.heading }}</a></h2>
<h2><a href="{% url result.view result.id %}">{{ result.heading }}</a></h2>
<p>{{ result.description | truncatewords:10 }}</p>
<p>
<span class="mr-5"><b>{% trans "Excerpt:" %}</b></span>
<span>{{ result.search_headline|safe }}</span>
</p>
<p>
{% if result.logo_url != "no_logo" %}
<img src="/media/{{ result.logo_url }}" alt="{{ result.name }} logo"
class="project-logo">
{% endif %}
</p>
<p>
<span><i>{{ result.rank }}</i></span>
<span><i>{{ result.rank }}</i></span>
</p>
</div>
{% endfor %}
Expand Down

0 comments on commit 16e86f0

Please sign in to comment.