[UPDT] SETTINGS: Updation in general settings by adding check box for enable block and unblock account

This commit is contained in:
Horilla
2024-02-19 15:30:14 +05:30
parent 0cf48401d8
commit bbe61678fa
6 changed files with 69 additions and 22 deletions

View File

@@ -0,0 +1,18 @@
{% load i18n %}
{% csrf_token %}
<div class="oh-inner-sidebar-content__header mt-4">
<h2 class="oh-inner-sidebar-content__title">{% trans 'Employee Account Block/Unblock' %}</h2>
</div>
<form action="{% url 'enable-account-block-unblock' %}" method="post">
{% csrf_token %}
<div class="oh-label__info" for="enable_block_unblock">
<label class="oh-label" for="enable_block_unblock">{% trans "Enable Block/Unblock" %}</label>
<span class="oh-info mr-2" title="{% trans "By enabling this feature, you can block or unblock an employee's account." %}">
</span>
</div>
<div class="oh-switch p-3">
<input type="checkbox"class="oh-switch__checkbox" name="enable_block_account" onchange="$(this).closest('form').find('input[type=submit]').click()" {% if enabled_block_unblock %} checked{% endif %} />
</div>
<input type="submit" hidden />
</form>
<div class="oh-inner-sidebar-content__footer"></div>

View File

@@ -22,4 +22,5 @@
{% include "settings/encashment_settings.html" %}
{% endif %}
{% include "base/audit_tag/history_tracking_fields.html" %}
{% include "base/audit_tag/employee_account_block_unblock.html" %}
{% endblock settings %}

View File

@@ -571,6 +571,7 @@ urlpatterns = [
path("settings/save-time/", views.save_time_format, name="save_time_format"),
path("settings/get-time-format/", views.get_time_format, name="get-time-format"),
path("history-field-settings",views.history_field_settings,name="history-field-settings"),
path("enable-account-block-unblock",views.enable_account_block_unblock,name="enable-account-block-unblock"),
path(
"settings/attendance-settings-view/",
views.validation_condition_view,

View File

@@ -28,7 +28,7 @@ from django.views.decorators.csrf import csrf_exempt
from employee.filters import EmployeeFilter
from employee.forms import ActiontypeForm
from horilla_audit.forms import HistoryTrackingFieldsForm
from horilla_audit.models import AuditTag, HistoryTrackingFields
from horilla_audit.models import AccountBlockUnblock, AuditTag, HistoryTrackingFields
from notifications.models import Notification
from notifications.base.models import AbstractNotification
from notifications.signals import notify
@@ -409,9 +409,9 @@ def home(request):
"completed_field_count": "0",
},
)
announcements = Announcement.objects.all().order_by('-created_on')
announcements = Announcement.objects.all().order_by("-created_on")
announcement_list = announcements.filter(employees=request.user.employee_get)
announcement_list =announcement_list | announcements.filter(employees__isnull=True)
announcement_list = announcement_list | announcements.filter(employees__isnull=True)
if request.user.has_perm("base.view_announcement"):
announcement_list = announcements
general_expire = AnnouncementExpire.objects.all().first()
@@ -3853,6 +3853,10 @@ def general_settings(request):
instance = AnnouncementExpire.objects.first()
form = AnnouncementExpireForm(instance=instance)
encashment_instance = EncashmentGeneralSettings.objects.first()
enabled_block_unblock = (
AccountBlockUnblock.objects.exists()
and AccountBlockUnblock.objects.first().is_enabled
)
encashment_form = EncashmentGeneralSettingsForm(instance=encashment_instance)
history_tracking_instance = HistoryTrackingFields.objects.first()
history_fields_form_initial = {}
@@ -3876,6 +3880,7 @@ def general_settings(request):
"form": form,
"encashment_form": encashment_form,
"history_fields_form": history_fields_form,
"enabled_block_unblock": enabled_block_unblock,
},
)
@@ -4028,6 +4033,22 @@ def history_field_settings(request):
return redirect(general_settings)
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()
instance.is_enabled = enabled
instance.save()
else:
AccountBlockUnblock.objects.create(is_enabled=enabled)
return redirect(general_settings)
@login_required
@permission_required("attendance.view_attendancevalidationcondition")
def validation_condition_view(request):

View File

@@ -112,6 +112,7 @@
/>
</a>
{% endif %}
{% if enabled_block_unblock %}
{% if perms.change_employee %}
{% if employee.employee_user_id.is_active %}
<form action = "{% url 'employee-account-block-unblock' employee.id %}"
@@ -133,6 +134,7 @@
</form>
{% endif %}
{% endif %}
{% endif %}
</div>
<div class="row">
<div class="col-12 col-sm-12 col-md-12 col-lg-4">

View File

@@ -132,3 +132,7 @@ class HistoryTrackingFields(models.Model):
# employee_id = models.ForeignKey("Employee", on_delete=models.PROTECT)
# history_id = models.ForeignKey(HorillaAuditLog, on_delete=models.PROTECT)
# message = models.TextField()
class AccountBlockUnblock(models.Model):
is_enabled = models.BooleanField(default=False, null=True, blank=True)