From c8d35414f814f09f6ae4b8acc707672e4fb35781 Mon Sep 17 00:00:00 2001 From: Horilla Date: Tue, 22 Jul 2025 11:46:02 +0530 Subject: [PATCH] [UPDT] HORILLA_THEME: Updated accessibility restriction to V2 --- horilla_theme/apps.py | 5 + horilla_theme/forms.py | 40 +++++ .../accessibility/accessibility.html | 168 ++++++++++++++++++ 3 files changed, 213 insertions(+) create mode 100644 horilla_theme/forms.py create mode 100644 horilla_theme/templates/accessibility/accessibility.html diff --git a/horilla_theme/apps.py b/horilla_theme/apps.py index b2c53ab46..a86067e25 100644 --- a/horilla_theme/apps.py +++ b/horilla_theme/apps.py @@ -4,3 +4,8 @@ from django.apps import AppConfig class HorillaThemeConfig(AppConfig): default_auto_field = "django.db.models.BigAutoField" name = "horilla_theme" + + def ready(self): + from . import forms + + return super().ready() diff --git a/horilla_theme/forms.py b/horilla_theme/forms.py new file mode 100644 index 000000000..b3602d41e --- /dev/null +++ b/horilla_theme/forms.py @@ -0,0 +1,40 @@ + +from django import forms +from accessibility.filters import _filter_form_structured, AccessibilityFilter,HorillaFilterSet + + +def __new_init__(self, *args, **kwargs): + AccessibilityFilter.__bases__[0].__init__(self, *args, **kwargs) + for field_name, field in self.form.fields.items(): + filter_widget = self.filters[field_name] + widget = filter_widget.field.widget + if isinstance( + widget, (forms.NumberInput, forms.EmailInput, forms.TextInput) + ): + field.widget.attrs.update({"class": "oh-input w-100"}) + elif isinstance(widget, (forms.Select,)): + field.widget.attrs.update( + { + "class": "", + "id": "", + } + ) + elif isinstance(widget, (forms.Textarea)): + field.widget.attrs.update({"class": "oh-input w-100"}) + elif isinstance( + widget, + ( + forms.CheckboxInput, + forms.CheckboxSelectMultiple, + ), + ): + field.widget.attrs.update({"class": "oh-switch__checkbox"}) + elif isinstance(widget, (forms.ModelChoiceField)): + field.widget.attrs.update( + { + "class": "oh-select oh-select-2 select2-hidden-accessible", + } + ) + self.form.structured = _filter_form_structured(self.form) + +AccessibilityFilter.__init__ = __new_init__ \ No newline at end of file diff --git a/horilla_theme/templates/accessibility/accessibility.html b/horilla_theme/templates/accessibility/accessibility.html new file mode 100644 index 000000000..affc6973c --- /dev/null +++ b/horilla_theme/templates/accessibility/accessibility.html @@ -0,0 +1,168 @@ +{% extends "settings.html" %} +{% load static i18n %} +{% block settings %} + + + +
+
{% trans "Default Accessibility" %}
+ +
+ +
+ {% for accessibility, display in accessibility %} +
+
+ {{display}} + +
+ +
+
+
+
+ +
+
+
+ +
+
+
+
+
+ {% trans "Only the employees selected in any of the fields will have access to the " %} `{{display}}` {% trans "feature" %} +
+ {% trans "If none are selected, the feature will be available to all normal users and employees." %} +
+ + {{accessibility_filter.form.structured}} + +
+
+
+
+ {% endfor %} +
+ + +{% endblock settings %} \ No newline at end of file