[UPDT] HORILLA_VIEWS: Updated search url and view type url to include referrer and urlencode

This commit is contained in:
Horilla
2025-08-08 14:44:56 +05:30
parent c58b6165fb
commit 71c6c7f87d
4 changed files with 32 additions and 22 deletions

View File

@@ -7,7 +7,7 @@ import json
import logging
import traceback
from typing import Any
from urllib.parse import parse_qs, urlencode
from urllib.parse import parse_qs, parse_qsl, urlencode, urlparse, urlunparse
import pandas as pd
from bs4 import BeautifulSoup
@@ -2159,7 +2159,6 @@ class HorillaNavView(TemplateView):
context["group_by_fields"] = self.group_by_fields
context["actions"] = self.actions
context["filter_body_template"] = self.filter_body_template
context["view_types"] = self.view_types
context["create_attrs"] = self.create_attrs
context["search_in"] = self.search_in
context["apply_first_filter"] = self.apply_first_filter
@@ -2177,6 +2176,32 @@ class HorillaNavView(TemplateView):
context["active_view"] = models.ActiveView.objects.filter(
path=self.request.path
).first()
extra_params = {
"referrer": self.request.META.get("HTTP_REFERER", ""),
}
# Update each view's URL with query parameters
for view in self.view_types:
parsed = urlparse(view.get("url", ""))
combined_query = dict(parse_qsl(parsed.query))
combined_query.update(self.request.GET)
combined_query.update(extra_params)
view["url"] = urlunparse(parsed._replace(query=urlencode(combined_query)))
context["view_types"] = self.view_types
# Update search URL with query parameters
parsed_search = urlparse(str(self.search_url))
parsed_search_url = dict(parse_qsl(parsed_search.query))
parsed_search_url.update(self.request.GET)
parsed_search_url.update(extra_params)
context["search_url"] = urlunparse(
parsed_search._replace(query=urlencode(parsed_search_url))
)
# CACHE.get(self.request.session.session_key + "cbv")[HorillaNavView] = context
return context

View File

@@ -18,7 +18,7 @@
<form autocomplete="off"
id="filterForm"
onsubmit="event.preventDefault()"
hx-get="{{search_url}}?&referrer={{request.META.HTTP_REFERER}}&{{request.GET.urlencode}}"
hx-get="{{search_url}}"
hx-replace-url="false"
hx-target="{{search_swap_target}}"
hx-on:submit="htmxLoadIndicator(this);"
@@ -90,7 +90,7 @@
></a>
{% if active_view.type == type.type %}
<script>
$("form#filterForm.oh-main__titlebar oh-main__titlebar--right").attr('hx-get','{{type.url}}?&referrer={{request.META.HTTP_REFERER}}&{{request.GET.urlencode}}');
$("form#filterForm.oh-main__titlebar oh-main__titlebar--right").attr('hx-get','{{type.url}}');
$(".oh-view-types .oh-view-type[data-type={{type.type}}] a").addClass("oh-btn--view-active")
</script>

View File

@@ -12,6 +12,7 @@
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<script>
window.CURRENT_LANGUAGE = "{{ LANGUAGE_CODE }}";
var at_work_seconds = {{ request.user.employee_get.get_forecasted_at_work.forecasted_at_work_seconds }}
var run = 0
</script>
@@ -221,6 +222,7 @@
</div>
</div>
<script src="{% url 'javascript-catalog' %}"></script>
<!--htmx script -->
<script src="{% static 'build/js/web.frontend.min.js' %}"></script>
<script src="{% static 'htmx/htmx.min.js' %}"></script>

View File

@@ -384,23 +384,6 @@ function initializeSummernote(candId,searchWords,) {
}
var message;
var languageCode = "en";
var emptyMessages = {
ar: "...لم يتم العثور على بيانات",
de: "Keine Daten gefunden...",
es: "No se encontraron datos...",
en: "No records available at the moment.",
fr: "Aucune donnée trouvée...",
};
$.ajax({
type: "GET",
url: "/employee/get-language-code/",
success: function (response) {
languageCode = response.language_code;
message = emptyMessages[languageCode];
},
});
function emptyChart(chart, args, options) {
flag = false;
@@ -425,7 +408,7 @@ function initializeSummernote(candId,searchWords,) {
message = chart.data.message
? chart.data.message
: emptyMessages[languageCode];
: i18nMessages.emptyMessages;
noDataImage.onload = () => {
// Draw image first at center