diff --git a/horilla_views/cbv_methods.py b/horilla_views/cbv_methods.py index a1a9017e4..ca0466731 100644 --- a/horilla_views/cbv_methods.py +++ b/horilla_views/cbv_methods.py @@ -28,6 +28,7 @@ from django.urls import reverse from django.utils.functional import lazy from django.utils.html import format_html from django.utils.safestring import SafeString +from django.utils.translation import gettext_lazy as _trans from horilla import settings from horilla.horilla_middlewares import _thread_locals @@ -198,6 +199,28 @@ def permission_required(function, perm): return _function +@decorator_with_arguments +def check_feature_enabled(function, feature_name, model_class: models.Model): + """ + Decorator for check feature enabled in singlton model + """ + + def _function(self, request, *args, **kwargs): + general_setting = model_class.objects.first() + enabled = getattr(general_setting, feature_name, False) + if enabled: + return function(self, request, *args, **kwargs) + messages.info(request, _trans("Feature is not enabled on the settings")) + previous_url = request.META.get("HTTP_REFERER", "/") + key = "HTTP_HX_REQUEST" + if key in request.META.keys(): + return render(request, "decorator_404.html") + script = f'' + return HttpResponse(script) + + return _function + + def hx_request_required(function): """ Decorator method that only allow HTMX metod to enter diff --git a/horilla_views/templates/generic/bulk_form.html b/horilla_views/templates/generic/bulk_form.html index 981b3d482..32ccab216 100644 --- a/horilla_views/templates/generic/bulk_form.html +++ b/horilla_views/templates/generic/bulk_form.html @@ -1,4 +1,4 @@
{% csrf_token %} {% include "generic/form.html" %} -
\ No newline at end of file +