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

View File

@@ -363,4 +363,10 @@
</div> </div>
</div> </div>
{% endif %} {% 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> </div>

View File

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

View File

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

View File

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