From caae8ff3a9935ffa0075d596bd6ec14af24e4c29 Mon Sep 17 00:00:00 2001 From: Horilla Date: Wed, 25 Dec 2024 12:04:48 +0530 Subject: [PATCH] [UPDT] BASE: Employee account block and unblock option form submission updated to htmx attributes --- .../employee_account_block_unblock.html | 22 ++++++----- .../pagination_settings.html | 37 +++++++++---------- base/views.py | 24 ++++++++---- 3 files changed, 46 insertions(+), 37 deletions(-) diff --git a/base/templates/base/audit_tag/employee_account_block_unblock.html b/base/templates/base/audit_tag/employee_account_block_unblock.html index 7b67f7a54..387cca63f 100644 --- a/base/templates/base/audit_tag/employee_account_block_unblock.html +++ b/base/templates/base/audit_tag/employee_account_block_unblock.html @@ -3,16 +3,18 @@

{% trans 'Employee Account Block/Unblock' %}

-
+ {% csrf_token %} -
- - - -
-
- -
- +
+ + + +
+
+ +
+
diff --git a/base/templates/base/dynamic_pagination/pagination_settings.html b/base/templates/base/dynamic_pagination/pagination_settings.html index f9e891615..e6637be4f 100644 --- a/base/templates/base/dynamic_pagination/pagination_settings.html +++ b/base/templates/base/dynamic_pagination/pagination_settings.html @@ -1,22 +1,21 @@ {% load i18n %} -
- {% csrf_token %} -
-

{% trans "Default Records Per Page" %}

-
-
- - - -
- - - + + {% csrf_token %} +
+

{% trans "Default Records Per Page" %}

+
+
+ + + +
+ + +
diff --git a/base/views.py b/base/views.py index 870c55876..90cd0ea68 100644 --- a/base/views.py +++ b/base/views.py @@ -5142,21 +5142,27 @@ def history_field_settings(request): return redirect(general_settings) +@login_required +@permission_required("horilla_audit.change_accountblockunblock") def enable_account_block_unblock(request): if request.method == "POST": - enabled = request.POST.get("enable_block_account") - if enabled == "on": - enabled = True - else: - enabled = False - if AccountBlockUnblock.objects.exists(): - instance = AccountBlockUnblock.objects.first() + enabled = request.POST.get("enable_block_account") == "on" + instance = AccountBlockUnblock.objects.first() + if instance: instance.is_enabled = enabled - messages.success(request, _("Settings updated.")) instance.save() else: AccountBlockUnblock.objects.create(is_enabled=enabled) + messages.success( + request, + _( + f"Account block/unblock setting has been {'enabled' if enabled else 'disabled'}." + ), + ) + if request.META.get("HTTP_HX_REQUEST"): + return HttpResponse() return redirect(general_settings) + return HttpResponse(status=405) @login_required @@ -6111,6 +6117,8 @@ def pagination_settings_view(request): if pagination_form.is_valid(): pagination_form.save() messages.success(request, _("Default pagination updated.")) + if request.META.get("HTTP_HX_REQUEST"): + return HttpResponse() return HttpResponseRedirect(request.META.get("HTTP_REFERER", "/"))