From dcd04e2bd8a31eb5d85a7af2906ac2bc1a900dc8 Mon Sep 17 00:00:00 2001 From: Horilla Date: Tue, 18 Jun 2024 14:24:11 +0530 Subject: [PATCH] [UPDT] BASE: Updated rotating shift and work type by adding additional shift and work type to rotate --- attendance/templates/attendance_form.html | 4 +- base/forms.py | 170 ++++++++++++++++++ base/models.py | 84 ++++++++- .../htmx/add_more_shift_fields.html | 27 +++ .../htmx/rotating_shift_as_p.html | 43 +++++ .../htmx/rotating_shift_form.html | 4 +- .../rotating_shift/rotating_shift_view.html | 114 ++++++------ .../htmx/add_more_work_type_fields.html | 27 +++ .../htmx/rotating_work_type_as_p.html | 42 +++++ base/templates/base/shift/schedule_view.html | 2 +- base/urls.py | 26 +++ base/views.py | 42 ++++- .../templates/candidate/candidate_nav.html | 2 +- 13 files changed, 526 insertions(+), 61 deletions(-) create mode 100644 base/templates/base/rotating_shift/htmx/add_more_shift_fields.html create mode 100644 base/templates/base/rotating_shift/htmx/rotating_shift_as_p.html create mode 100644 base/templates/base/rotating_work_type/htmx/add_more_work_type_fields.html create mode 100644 base/templates/base/rotating_work_type/htmx/rotating_work_type_as_p.html diff --git a/attendance/templates/attendance_form.html b/attendance/templates/attendance_form.html index 6a9b12d78..795aa3df5 100644 --- a/attendance/templates/attendance_form.html +++ b/attendance/templates/attendance_form.html @@ -44,10 +44,10 @@ -
+ - {% endif %} -
- {% endfor %} - - +
+
+
+
{% trans "Title" %}
+
{% trans "Shift 1" %}
+
{% trans "Shift 2" %}
+
{% trans "Additional Shifts" %}
+
{% trans "Actions" %}
+
+
+
+ {% for rshift in rshifts %} +
+
{{rshift.name}}
+
{{rshift.shift1}}
+
{{rshift.shift2}}
+
+ {% if rshift.additional_shifts %} + {% for shift in rshift.additional_shifts %} + {{shift}}
+ {% endfor %} + {% else %} + {{rshift.additional_shifts}} + {% endif %} +
+ {% if perms.base.change_rotatingshift or perms.base.delete_rotatingshift %} +
+
+ {% if perms.base.change_rotatingshift %} + + + {% endif %} {% if perms.base.delete_rotatingshift %} +
+ {% csrf_token %} + +
+ {% endif %} +
+
+ {% endif %} +
+ {% endfor %} +
+
diff --git a/base/templates/base/rotating_work_type/htmx/add_more_work_type_fields.html b/base/templates/base/rotating_work_type/htmx/add_more_work_type_fields.html new file mode 100644 index 000000000..2ea28ea75 --- /dev/null +++ b/base/templates/base/rotating_work_type/htmx/add_more_work_type_fields.html @@ -0,0 +1,27 @@ +{% load i18n %} +
+ {{field_html}} + + + +
+
+ {% trans "Add more work types.." %} +
diff --git a/base/templates/base/rotating_work_type/htmx/rotating_work_type_as_p.html b/base/templates/base/rotating_work_type/htmx/rotating_work_type_as_p.html new file mode 100644 index 000000000..2dd8bb62f --- /dev/null +++ b/base/templates/base/rotating_work_type/htmx/rotating_work_type_as_p.html @@ -0,0 +1,42 @@ +{% load i18n %} {% load basefilters %} {{ form.non_field_errors }} +{% for field in form.visible_fields %} +{% if field.name|startswith:"work_type" and not field.field.required %} +
+ {{ field }} + + + +
+{% else %} +
+ + {{field}} +
+{% endif %} {% endfor %} +
+ + {% trans "Add more work types.." %} + +
diff --git a/base/templates/base/shift/schedule_view.html b/base/templates/base/shift/schedule_view.html index 00bfe501c..2cba6367c 100644 --- a/base/templates/base/shift/schedule_view.html +++ b/base/templates/base/shift/schedule_view.html @@ -8,7 +8,7 @@
{% trans "Shift" %}
-
{% trans "Days" %}
+
{% trans "Days" %}
diff --git a/base/urls.py b/base/urls.py index 75e65b764..f5e8032ad 100644 --- a/base/urls.py +++ b/base/urls.py @@ -1,10 +1,12 @@ from django.contrib.auth.models import Group from django.contrib.auth.views import PasswordResetConfirmView from django.urls import path +from django.utils.translation import gettext_lazy as _ from base import announcement, request_and_approve, views from base.forms import ( RotatingShiftAssignForm, + RotatingShiftForm, RotatingWorkTypeAssignForm, RotatingWorkTypeForm, ShiftRequestForm, @@ -192,6 +194,18 @@ urlpatterns = [ name="work-type-delete", kwargs={"model": WorkType, "redirect": "/settings/work-type-view"}, ), + path( + "add-remove-work-type-fields", + views.add_remove_dynamic_fields, + name="add-remove-work-type-fields", + kwargs={ + "model": WorkType, + "form_class": RotatingWorkTypeForm, + "template": "base/rotating_work_type/htmx/add_more_work_type_fields.html", + "empty_label": _("---Choose Work Type---"), + "field_name_pre": "work_type", + }, + ), path( "settings/rotating-work-type-create/", views.rotating_work_type_create, @@ -352,6 +366,18 @@ urlpatterns = [ views.rotating_shift_create, name="rotating-shift-create", ), + path( + "add-remove-shift-fields", + views.add_remove_dynamic_fields, + name="add-remove-shift-fields", + kwargs={ + "model": EmployeeShift, + "form_class": RotatingShiftForm, + "template": "base/rotating_shift/htmx/add_more_shift_fields.html", + "empty_label": _("---Choose Shift---"), + "field_name_pre": "shift", + }, + ), path( "settings/rotating-shift-view/", views.rotating_shift_view, diff --git a/base/views.py b/base/views.py index e5e0b6cd6..38a3719c1 100644 --- a/base/views.py +++ b/base/views.py @@ -919,6 +919,45 @@ def object_duplicate(request, obj_id, **kwargs): return render(request, template, context) +@login_required +@hx_request_required +@duplicate_permission() +def add_remove_dynamic_fields(request, **kwargs): + if request.method == "POST": + model = kwargs["model"] + form_class = kwargs["form_class"] + template = kwargs["template"] + empty_label = kwargs["empty_label"] + field_name_pre = kwargs["field_name_pre"] + hx_target = request.META.get("HTTP_HX_TARGET") + if hx_target: + field_counts = int(hx_target.split("_")[-1]) + 1 + next_hx_target = f"{hx_target.rsplit('_', 1)[0]}_{field_counts}" + form = form_class() + field_name = f"{field_name_pre}{field_counts}" + form.fields[field_name] = forms.ModelChoiceField( + queryset=model.objects.all(), + widget=forms.Select( + attrs={ + "class": "oh-select oh-select-2 mb-3", + "name": field_name, + "id": f"id_{field_name}", + } + ), + required=False, + empty_label=empty_label, + ) + context = { + "field_counts": field_counts, + "field_html": form[field_name].as_widget(), + "current_hx_target": hx_target, + "next_hx_target": next_hx_target, + } + field_html = render_to_string(template, context) + return HttpResponse(field_html) + return HttpResponse() + + @login_required @permission_required("base.view_dynamicemailconfiguration") def mail_server_conf(request): @@ -2023,7 +2062,8 @@ def rotating_shift_create(request): form = RotatingShiftForm() messages.success(request, _("Rotating shift created.")) return HttpResponse("") - + else: + form = RotatingShiftForm() return render( request, "base/rotating_shift/htmx/rotating_shift_form.html", diff --git a/recruitment/templates/candidate/candidate_nav.html b/recruitment/templates/candidate/candidate_nav.html index 8b7a2cafc..73997817c 100644 --- a/recruitment/templates/candidate/candidate_nav.html +++ b/recruitment/templates/candidate/candidate_nav.html @@ -60,7 +60,7 @@ x-data="{searchShow: false}" id="filterForm" hx-target="#section" class="d-flex" - onsubmit="event.preventDefault(); + onsubmit="event.preventDefault();" >