[FIX] HORILLA VIEWS: Generic delete issue

This commit is contained in:
Horilla
2025-01-20 17:12:26 +05:30
parent 50ad1dca23
commit 732175365c
5 changed files with 46 additions and 32 deletions

View File

@@ -15,7 +15,7 @@ from django.http import HttpRequest, HttpResponse, QueryDict
from django.shortcuts import render
from django.urls import resolve, reverse
from django.utils.decorators import method_decorator
from django.utils.translation import gettext_lazy as _trans
from django.utils.translation import gettext_lazy as _
from django.views.generic import DetailView, FormView, ListView, TemplateView
from base.methods import closest_numbers, eval_validate, get_key_instances
@@ -142,7 +142,7 @@ class HorillaListView(ListView):
form = self.get_bulk_form()
form.verbose_name = (
form.verbose_name
+ f" ({len((eval_validate(request.GET.get('instance_ids','[]'))))} {_trans('Records')})"
+ f" ({len((eval_validate(request.GET.get('instance_ids','[]'))))} {_('Records')})"
)
return render(
request,
@@ -168,7 +168,7 @@ class HorillaListView(ListView):
)
if instance_ids and form.is_valid():
form.save()
messages.success(request, _trans("Selected Records updated"))
messages.success(request, _("Selected Records updated"))
script_id = get_short_uuid(length=3, prefix="bulk")
return HttpResponse(
@@ -181,7 +181,7 @@ class HorillaListView(ListView):
"""
)
if not instance_ids:
messages.info(request, _trans("No records selected"))
messages.info(request, _("No records selected"))
return render(
request,
self.bulk_template,
@@ -297,7 +297,9 @@ class HorillaListView(ListView):
if key in ["filter_applied", "nav_url"] + self.filter_keys_to_remove
]
for key in keys_to_remove + ["referrer"]:
for key in (
keys_to_remove + ["referrer", "nav_url"] + self.filter_keys_to_remove
):
if key in data_dict.keys():
data_dict.pop(key)
context["filter_dict"] = data_dict
@@ -500,7 +502,11 @@ class HorillaDetailedView(DetailView):
title = "Detailed View"
template_name = "generic/horilla_detailed_view.html"
header: dict = {"title": "Horilla", "subtitle": "Horilla Detailed View"}
header: dict = {
"title": "Horilla",
"subtitle": "Horilla Detailed View",
"avatar": "",
}
body: list = []
action_method: list = []
@@ -697,9 +703,12 @@ class HorillaCardView(ListView):
if value[0] in ["unknown", "on"] + self.filter_keys_to_remove
]
for key in keys_to_remove + ["referrer"]:
for key in (
keys_to_remove + ["referrer", "nav_url"] + self.filter_keys_to_remove
):
if key in data_dict.keys():
data_dict.pop(key)
context["filter_dict"] = data_dict
ordered_ids = list(queryset.values_list("id", flat=True))
@@ -1089,6 +1098,8 @@ class HorillaProfileView(DetailView):
template_name = "generic/horilla_profile_view.html"
view_id: str = None
filter_class: FilterSet = None
push_url: str = None
key_name: str = "pk"
# add these method under the model
# get_avatar --> image/profile
@@ -1209,10 +1220,14 @@ class HorillaProfileView(DetailView):
url_name = url.url_name
next_url = reverse(url_name, kwargs={key: next_id})
previous_url = reverse(url_name, kwargs={key: previous_id})
push_url_next = reverse(self.push_url, kwargs={self.key_name: next_id})
push_url_prev = reverse(self.push_url, kwargs={self.key_name: previous_id})
context["instance_ids"] = str(instance_ids)
if instance_ids:
context["next_url"] = next_url
context["previous_url"] = previous_url
context["push_url_next"] = push_url_next
context["push_url_prev"] = push_url_prev
context["display_count"] = display_count
context["actions"] = self.actions

View File

@@ -363,4 +363,10 @@
</div>
</div>
{% endif %}
<script>
setInterval(() => {
$("#{{view_id}} [type=checkbox].list-table-row:checked").first().change();
$("#{{view_id}} [type=checkbox].list-table-row:checked").not().first().change();
}, 200);
</script>
</div>

View File

@@ -17,6 +17,7 @@
<li {% if instance.pk == object.pk %} class="active" {% endif %}>
<a
hx-get="{{object.get_profile_url}}?{{request.GET.urlencode}}"
hx-push-url = "{{object.get_push_url}}"
hx-target="#{{view_id|safe}}"
hx-swap="outerHTML"
class="d-block">
@@ -80,6 +81,7 @@
<a
hx-get="{{previous_url}}?instance_ids={{instance_ids}}"
hx-push-url = "{{object.get_push_url}}"
hx-target="#{{view_id|safe}}"
hx-swap="outerHTML"
title=""
@@ -96,6 +98,7 @@
</a>
<a
hx-get="{{next_url}}?instance_ids={{instance_ids}}"
hx-push-url = "{{object.get_push_url}}"
hx-target="#{{view_id|safe}}"
hx-swap="outerHTML"
title=""
@@ -165,10 +168,13 @@
<div class="oh-profile__avatar">
<img src="{{instance.get_avatar}}" class="oh-profile__image" />
</div>
{% if instance|getattribute:"is_active" %}
<span
class="oh-profile__active-badge oh-profile__active-badge--secondary"
title="Active"
style="background-color: limegreen;"
></span>
{% endif %}
</div>
<div class="oh-profile__info-container">
<h1 class="oh-profile__info-name">{{instance}}</h1>

View File

@@ -133,14 +133,3 @@
</div>
{% endif %}
</div>
<script>
{% comment %} $(document).ready(function () {
$(".quick-bulk-action").hover(function () {
// over
$(this).find('.label').show('slow');
}, function () {
// out
}
);
}); {% endcomment %}
</script>

View File

@@ -520,11 +520,7 @@ class HorillaDeleteConfirmationView(View):
model = type(obj)
protected_model_count[model._meta.verbose_name_plural] += 1
protected_model_count = dict(protected_model_count)
return render(
self.request,
"generic/delete_confirmation.html",
{
context = {
"model_map": merge_dicts(MODEL_MAP, PROTECTED_MODEL_MAP),
"dynamic_list_path": DYNAMIC_PATH_MAP,
"delete_object": delete_object,
@@ -533,8 +529,10 @@ class HorillaDeleteConfirmationView(View):
"related_objects_count": model_count,
"protected_objects_count": protected_model_count,
}
| self.get_context_data(),
)
for key, value in self.get_context_data().items():
context[key] = value
return render(self.request, "generic/delete_confirmation.html", context)
def post(self, *args, **kwargs):
"""