Skip to content
Snippets Groups Projects
Commit 0295d1c8 authored by Tomáš Valenta's avatar Tomáš Valenta
Browse files

add date to search results

parent 13e5bc07
No related branches found
No related tags found
2 merge requests!861Release: New homepage design,!857Nicer search
Pipeline #15965 passed
...@@ -1027,22 +1027,25 @@ class MainSearchPage( ...@@ -1027,22 +1027,25 @@ class MainSearchPage(
if request.GET.get("q", "") == "": if request.GET.get("q", "") == "":
return context return context
query = request.GET["q"] search_query = request.GET["q"]
context["global_search_query"] = query context["global_search_query"] = search_query
for model in ( for model in (
MainPersonPage, MainPersonPage,
MainArticlePage, MainArticlePage,
MainSimplePage, MainSimplePage,
): ):
filter = models.Q(title__icontains=query) filter = models.Q(title__icontains=search_query)
if hasattr(model, "perex"): if hasattr(model, "perex"):
filter = filter | models.Q(perex__icontains=query) filter = filter | models.Q(perex__icontains=search_query)
context["results"] += list(model.objects.filter(filter).all()[:15]) results = model.objects.filter(filter)
print(context["results"]) if hasattr(model, "date"):
results = results.order_by("-date")
context["results"] += list(results.all()[:15])
context["results"].sort(key=lambda result: result.title) context["results"].sort(key=lambda result: result.title)
......
...@@ -127,4 +127,4 @@ ...@@ -127,4 +127,4 @@
<glyph unicode="&#xe976;" glyph-name="price-tags" horiz-adv-x="1280" d="M1232 960h-384c-26.4 0-63.274-15.274-81.942-33.942l-476.116-476.116c-18.668-18.668-18.668-49.214 0-67.882l412.118-412.118c18.668-18.668 49.214-18.668 67.882 0l476.118 476.118c18.666 18.666 33.94 55.54 33.94 81.94v384c0 26.4-21.6 48-48 48zM992 576c-53.020 0-96 42.98-96 96s42.98 96 96 96 96-42.98 96-96-42.98-96-96-96zM128 416l544 544h-80c-26.4 0-63.274-15.274-81.942-33.942l-476.116-476.116c-18.668-18.668-18.668-49.214 0-67.882l412.118-412.118c18.668-18.668 49.214-18.668 67.882 0l30.058 30.058-416 416z" /> <glyph unicode="&#xe976;" glyph-name="price-tags" horiz-adv-x="1280" d="M1232 960h-384c-26.4 0-63.274-15.274-81.942-33.942l-476.116-476.116c-18.668-18.668-18.668-49.214 0-67.882l412.118-412.118c18.668-18.668 49.214-18.668 67.882 0l476.118 476.118c18.666 18.666 33.94 55.54 33.94 81.94v384c0 26.4-21.6 48-48 48zM992 576c-53.020 0-96 42.98-96 96s42.98 96 96 96 96-42.98 96-96-42.98-96-96-96zM128 416l544 544h-80c-26.4 0-63.274-15.274-81.942-33.942l-476.116-476.116c-18.668-18.668-18.668-49.214 0-67.882l412.118-412.118c18.668-18.668 49.214-18.668 67.882 0l30.058 30.058-416 416z" />
<glyph unicode="&#xe977;" glyph-name="twitter" horiz-adv-x="1001" d="M596.009 526.629l372.819 433.371h-88.346l-323.718-376.29-258.553 376.29h-298.21l390.983-569.018-390.983-454.457h88.351l341.855 397.375 273.051-397.375h298.21l-405.458 590.103zM475 385.969l-354.815 507.521h135.702l624.636-893.48h-135.702l-269.821 385.959z" /> <glyph unicode="&#xe977;" glyph-name="twitter" horiz-adv-x="1001" d="M596.009 526.629l372.819 433.371h-88.346l-323.718-376.29-258.553 376.29h-298.21l390.983-569.018-390.983-454.457h88.351l341.855 397.375 273.051-397.375h298.21l-405.458 590.103zM475 385.969l-354.815 507.521h135.702l624.636-893.48h-135.702l-269.821 385.959z" />
<glyph unicode="&#xe99b;" glyph-name="stats-dots" d="M128 64h896v-128h-1024v1024h128zM288 128c-53.020 0-96 42.98-96 96s42.98 96 96 96c2.828 0 5.622-0.148 8.388-0.386l103.192 171.986c-9.84 15.070-15.58 33.062-15.58 52.402 0 53.020 42.98 96 96 96s96-42.98 96-96c0-19.342-5.74-37.332-15.58-52.402l103.192-171.986c2.766 0.238 5.56 0.386 8.388 0.386 2.136 0 4.248-0.094 6.35-0.23l170.356 298.122c-10.536 15.408-16.706 34.036-16.706 54.11 0 53.020 42.98 96 96 96s96-42.98 96-96c0-53.020-42.98-96-96-96-2.14 0-4.248 0.094-6.35 0.232l-170.356-298.124c10.536-15.406 16.706-34.036 16.706-54.11 0-53.020-42.98-96-96-96s-96 42.98-96 96c0 19.34 5.74 37.332 15.578 52.402l-103.19 171.984c-2.766-0.238-5.56-0.386-8.388-0.386s-5.622 0.146-8.388 0.386l-103.192-171.986c9.84-15.068 15.58-33.060 15.58-52.4 0-53.020-42.98-96-96-96z" /> <glyph unicode="&#xe99b;" glyph-name="stats-dots" d="M128 64h896v-128h-1024v1024h128zM288 128c-53.020 0-96 42.98-96 96s42.98 96 96 96c2.828 0 5.622-0.148 8.388-0.386l103.192 171.986c-9.84 15.070-15.58 33.062-15.58 52.402 0 53.020 42.98 96 96 96s96-42.98 96-96c0-19.342-5.74-37.332-15.58-52.402l103.192-171.986c2.766 0.238 5.56 0.386 8.388 0.386 2.136 0 4.248-0.094 6.35-0.23l170.356 298.122c-10.536 15.408-16.706 34.036-16.706 54.11 0 53.020 42.98 96 96 96s96-42.98 96-96c0-53.020-42.98-96-96-96-2.14 0-4.248 0.094-6.35 0.232l-170.356-298.124c10.536-15.406 16.706-34.036 16.706-54.11 0-53.020-42.98-96-96-96s-96 42.98-96 96c0 19.34 5.74 37.332 15.578 52.402l-103.19 171.984c-2.766-0.238-5.56-0.386-8.388-0.386s-5.622 0.146-8.388 0.386l-103.192-171.986c9.84-15.068 15.58-33.060 15.58-52.4 0-53.020-42.98-96-96-96z" />
</font></defs></svg> </font></defs></svg>
\ No newline at end of file
...@@ -6,6 +6,10 @@ ...@@ -6,6 +6,10 @@
> >
<h2 class="head-4xl group-hover:underline">{{ title }}</h2> <h2 class="head-4xl group-hover:underline">{{ title }}</h2>
{% if date %}
<span class="text-grey-250">{{ date }}</span>
{% endif %}
{% if perex %} {% if perex %}
<p class="!hover:no-underline"> <p class="!hover:no-underline">
{{ perex }} {{ perex }}
......
...@@ -4,6 +4,6 @@ ...@@ -4,6 +4,6 @@
</div> </div>
{% for result in results %} {% for result in results %}
{% include "main/includes/molecules/search/universal_search_result.html" with url=result.url title=result.title perex=result.perex %} {% include "main/includes/molecules/search/universal_search_result.html" with url=result.url title=result.title date=result.date perex=result.perex %}
{% endfor %} {% endfor %}
</div> </div>
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment