From 3e5c4f80e2d7af941296a3f7bb53abefa6bf65c9 Mon Sep 17 00:00:00 2001 From: Horilla Date: Thu, 7 Mar 2024 12:19:04 +0530 Subject: [PATCH] [UPDT] BASE: Updated employee rotating shift assign delete method and rotating shift assign modal close button hx-target and hx-get --- base/models.py | 59 ++- .../base/rotating_shift/htmx/group_by.html | 18 +- .../base/rotating_shift/individual_view.html | 355 +++++++++++------- .../rotating_shift_assign_view.html | 17 +- .../htmx/work_type_request_single_view.html | 2 +- base/urls.py | 2 +- employee/templates/tabs/shift-tab.html | 8 +- 7 files changed, 271 insertions(+), 190 deletions(-) diff --git a/base/models.py b/base/models.py index c154b1f7d..226a6859e 100644 --- a/base/models.py +++ b/base/models.py @@ -3,7 +3,6 @@ models.py This module is used to register django models """ - from collections.abc import Iterable from typing import Any import django @@ -34,13 +33,11 @@ def validate_time_format(value): except ValueError as e: raise ValidationError(_("Invalid format, excepted HH:MM")) from e - def clear_messages(request): storage = messages.get_messages(request) for message in storage: pass - class Company(models.Model): """ Company model @@ -720,16 +717,14 @@ class WorkTypeRequest(models.Model): ordering = [ "-id", ] - - def delete(self, *args, **kwargs): - request = getattr(_thread_locals, "request", None) + def delete(self,*args, **kwargs): + request = getattr(_thread_locals,"request",None) if not self.approved: super().delete(*args, **kwargs) else: if request: clear_messages(request) - messages.warning(request, "The request entry cannot be deleted.") - + messages.warning(request,"The request entry cannot be deleted.") def is_any_work_type_request_exists(self): approved_work_type_requests_range = WorkTypeRequest.objects.filter( employee_id=self.employee_id, @@ -782,7 +777,9 @@ class WorkTypeRequest(models.Model): ) if not self.is_permanent_work_type: if not self.requested_till: - raise ValidationError(_("Requested till field is required.")) + raise ValidationError( + _("Requested till field is required.") + ) def __str__(self) -> str: return f"{self.employee_id.employee_first_name} \ @@ -799,7 +796,7 @@ class WorktyperequestComment(models.Model): request_id = models.ForeignKey(WorkTypeRequest, on_delete=models.CASCADE) employee_id = models.ForeignKey(Employee, on_delete=models.CASCADE) comment = models.TextField(null=True, verbose_name=_("Comment")) - files = models.ManyToManyField(BaserequestFile, blank=True) + files = models.ManyToManyField(BaserequestFile,blank=True) created_at = models.DateTimeField( auto_now_add=True, verbose_name=_("Created At"), @@ -897,7 +894,9 @@ class ShiftRequest(models.Model): ) if not self.is_permanent_shift: if not self.requested_till: - raise ValidationError(_("Requested till field is required.")) + raise ValidationError( + _("Requested till field is required.") + ) def is_any_request_exists(self): approved_shift_requests_range = ShiftRequest.objects.filter( @@ -941,20 +940,21 @@ class ShiftRequest(models.Model): def save(self, *args, **kwargs): super().save(*args, **kwargs) - def delete(self, *args, **kwargs): - request = getattr(_thread_locals, "request", None) + def delete(self,*args, **kwargs): + request = getattr(_thread_locals,"request",None) if not self.approved: super().delete(*args, **kwargs) else: if request: clear_messages(request) - messages.warning(request, "The request entry cannot be deleted.") - + messages.warning(request,"The request entry cannot be deleted.") + def __str__(self) -> str: return f"{self.employee_id.employee_first_name} \ {self.employee_id.employee_last_name} - {self.requested_date}" + class ShiftrequestComment(models.Model): """ ShiftrequestComment Model @@ -964,7 +964,7 @@ class ShiftrequestComment(models.Model): request_id = models.ForeignKey(ShiftRequest, on_delete=models.CASCADE) employee_id = models.ForeignKey(Employee, on_delete=models.CASCADE) - files = models.ManyToManyField(BaserequestFile, blank=True) + files = models.ManyToManyField(BaserequestFile,blank=True) comment = models.TextField(null=True, verbose_name=_("Comment")) created_at = models.DateTimeField( auto_now_add=True, @@ -994,9 +994,6 @@ class DynamicEmailConfiguration(models.Model): SingletoneModel to keep the mail server configurations """ - is_primary = models.BooleanField( - default=False, verbose_name=_("Primary Mail Server") - ) host = models.CharField( blank=True, null=True, max_length=256, verbose_name=_("Email Host") ) @@ -1043,16 +1040,16 @@ class DynamicEmailConfiguration(models.Model): ) ) if not self.company_id: - raise ValidationError({"company_id": _("This field is required")}) + servers_same_company = DynamicEmailConfiguration.objects.filter( + company_id__isnull=True + ).exclude(id=self.id) + if servers_same_company.exists(): + raise ValidationError({"company_id": _("This field is required")}) def __str__(self): return self.username def save(self, *args, **kwargs) -> None: - if self.is_primary: - DynamicEmailConfiguration.objects.filter(is_primary=True).update( - is_primary=False - ) super().save(*args, **kwargs) servers_same_company = DynamicEmailConfiguration.objects.filter( company_id=self.company_id @@ -1270,22 +1267,20 @@ class AnnouncementExpire(models.Model): class Announcement(models.Model): + """ Anonuncement Model for stroing all announcements. """ - from employee.models import Employee title = models.CharField(max_length=30) - description = models.TextField(null=True, max_length=255) + description = models.TextField(null=True,max_length=255) attachments = models.ManyToManyField( Attachment, related_name="announcement_attachments", blank=True ) created_on = models.DateTimeField(auto_now_add=True) expire_date = models.DateField(null=True, blank=True) - employees = models.ManyToManyField( - Employee, related_name="announcement_employees", blank=True - ) + employees = models.ManyToManyField(Employee, related_name="announcement_employees", blank=True) department = models.ManyToManyField(Department, blank=True) job_position = models.ManyToManyField(JobPosition, blank=True) disable_comments = models.BooleanField(default=False) @@ -1295,7 +1290,6 @@ class Announcement(models.Model): This method is used to get the view count of the announcement """ return self.announcementview_set.filter(viewed=True) - def __str__(self): return self.title @@ -1309,7 +1303,7 @@ class AnnouncementComment(models.Model): announcement_id = models.ForeignKey(Announcement, on_delete=models.CASCADE) employee_id = models.ForeignKey(Employee, on_delete=models.CASCADE) - comment = models.TextField(null=True, verbose_name=_("Comment"), max_length=255) + comment = models.TextField(null=True, verbose_name=_("Comment"),max_length=255) created_at = models.DateTimeField( auto_now_add=True, verbose_name=_("Created At"), @@ -1321,11 +1315,10 @@ class AnnouncementView(models.Model): """ Announcemnt View Model """ - user = models.ForeignKey(User, on_delete=models.CASCADE) announcement = models.ForeignKey(Announcement, on_delete=models.CASCADE) viewed = models.BooleanField(default=False) - created_at = models.DateTimeField(auto_now_add=True, null=True) + created_at = models.DateTimeField(auto_now_add=True,null=True) class EmailLog(models.Model): diff --git a/base/templates/base/rotating_shift/htmx/group_by.html b/base/templates/base/rotating_shift/htmx/group_by.html index 3eb176e1e..65429a451 100644 --- a/base/templates/base/rotating_shift/htmx/group_by.html +++ b/base/templates/base/rotating_shift/htmx/group_by.html @@ -1,6 +1,16 @@ {% load attendancefilters %} {% load basefilters %} {% load static %} {% load i18n %} {% include 'filter_tags.html' %} - +{% if messages %} +
+ {% for message in messages %} +
+
+ {{ message }} +
+
+ {% endfor %} +
+{% endif %}
{% if perms.base.view_shiftrequest %}
{% csrf_token %} diff --git a/base/templates/base/rotating_shift/individual_view.html b/base/templates/base/rotating_shift/individual_view.html index e173a7c06..03467d29f 100644 --- a/base/templates/base/rotating_shift/individual_view.html +++ b/base/templates/base/rotating_shift/individual_view.html @@ -1,160 +1,227 @@ -{% load i18n %} -
-

- {% trans "Details" %} -

- -
-
-{% if request.GET.instances_ids %} -
- - - -
-{% endif %} - - -
-
- Mary Magdalene -
-
- {{instance.employee_id}} - - {{instance.employee_id.employee_work_info.department_id}} / - {{instance.employee_id.employee_work_info.job_position_id}} +{% load i18n %} {% load static %} +{% if messages %} +
+ {% for message in messages %} +
+
+ {{ message }}
-
-
+ {% endfor %} +
+{% endif %} +
+ {% if instance %} +

{% trans "Details" %}

+ {% endif %} + +
+{% if instance %} +
+ {% if request.GET.instances_ids %} +
+ + + +
+ {% endif %} + + +
+
+ Mary Magdalene +
+
+ {{instance.employee_id}} + + {{instance.employee_id.employee_work_info.department_id}} / + {{instance.employee_id.employee_work_info.job_position_id}} +
+
+
+
-
- {% trans "Title" %} - {{instance.rotating_shift_id}} -
-
- {% trans "Based On" %} - - {{instance.get_based_on_display}} - -
+
+ {% trans "Title" %} + {{instance.rotating_shift_id}} +
+
+ {% trans "Based On" %} + + {{instance.get_based_on_display}} + +
-
- {% trans "Rotate" %} - - {% if instance.based_on == 'after' %} - {% trans "Rotate after" %} {{instance.rotate_after_day}} {% trans "days" %} - {% elif instance.based_on == "weekly" %} - {% trans "Weekly every" %} {{instance.rotate_every_weekend}} - {% elif instance.based_on == "monthly" %} - {% if instance.rotate_every == "1" %} +
+ {% trans "Rotate" %} + + {% if instance.based_on == 'after' %} + {% trans "Rotate after" %} + {{instance.rotate_after_day}} {% trans "days" %} + {% elif instance.based_on == "weekly" %} + {% trans "Weekly every" %} {{instance.rotate_every_weekend}} + {% elif instance.based_on == "monthly" %} + {% if instance.rotate_every == "1" %} {% trans "Rotate every" %} {{instance.rotate_every}}{% trans "st day of month" %} - {% elif instance.rotate_every == "2" %} - {% trans "Rotate every" %} {{instance.rotate_every}}{% trans "nd day of month" %} - {% elif instance.rotate_every == "3" %} - {% trans "Rotate every" %} {{instance.rotate_every}}{% trans "rd day of month" %} - {% elif instance.rotate_every == "last" %} + {% elif instance.rotate_every == "2" %} {% trans "Rotate every" %} + {{instance.rotate_every}}{% trans "nd day of month" %} + {% elif instance.rotate_every == "3" %} {% trans "Rotate every" %} + {{instance.rotate_every}}{% trans "rd day of month" %} + {% elif instance.rotate_every == "last" %} {% trans "Rotate every last day of month" %} - {% else %} + {% else %} {% trans "Rotate every" %} {{instance.rotate_every}}{% trans "th day of month" %} - {% endif %} - {% endif %} - -
-
- {% trans "Start Date" %} - {{instance.start_date}} -
+ {% endif %} + {% endif %} +
+
+
+ {% trans "Start Date" %} + {{instance.start_date}} +
-
- {% trans "Current Shift" %} - {{instance.current_shift}} -
-
- {% trans "Next Shift" %} - - {{instance.next_shift}} - -
+
+ {% trans "Current Shift" %} + {{instance.current_shift}} +
+
+ {% trans "Next Shift" %} + + {{instance.next_shift}} + +
- -
-
- {% trans "Next Change Date" %} - - {{instance.next_change_date}} - -
-
- - - -
+ +
+
+ {% trans "Next Change Date" %} + + {{instance.next_change_date}} + +
+
+ + +
-
- - - - {% trans "Edit" %} - -
- - -
-
- {% csrf_token %} - -
-
+
+ + {% trans "Edit" %} + +
+ + +
+
+ {% csrf_token %} + +
+
+
+{% else %} +
+ Page not found. 404. +
+ {% trans "There are no rotating shift assigned to this employee." %} +
+{% endif %} diff --git a/base/templates/base/rotating_shift/rotating_shift_assign_view.html b/base/templates/base/rotating_shift/rotating_shift_assign_view.html index ab1b9e5e6..1e819f191 100644 --- a/base/templates/base/rotating_shift/rotating_shift_assign_view.html +++ b/base/templates/base/rotating_shift/rotating_shift_assign_view.html @@ -1,6 +1,17 @@ {% load static %} {% load i18n %} {% load basefilters %} +{% if messages %} +
+ {% for message in messages %} +
+
+ {{ message }} +
+
+ {% endfor %} +
+{% endif %}
{% csrf_token %}
diff --git a/base/urls.py b/base/urls.py index aec2de48d..d0f04cb90 100644 --- a/base/urls.py +++ b/base/urls.py @@ -425,7 +425,7 @@ urlpatterns = [ name="rotating-shift-assign-bulk-delete", ), path( - "rotating-shift-assign-delete//", + "rotating-shift-assign-delete//", views.rotating_shift_assign_delete, name="rotating-shift-assign-delete", ), diff --git a/employee/templates/tabs/shift-tab.html b/employee/templates/tabs/shift-tab.html index d9a8a6326..271e6ae28 100644 --- a/employee/templates/tabs/shift-tab.html +++ b/employee/templates/tabs/shift-tab.html @@ -400,7 +400,7 @@
{{rshift.next_shift}}
{% if not request.GET.profile and perms.base.change_rotatingworktypeassign or perms.base.delete_rotatingshiftassign or request.user|check_manager:rshift or request.user|is_reportingmanager %} -
+
{% if perms.base.change_rotatingshiftassign or perms.base.change_rotatingworktypeassign or request.user|check_manager:rshift or request.user|is_reportingmanager %} {% endif %} {% if perms.base.delete_rotatingshiftassign or request.user|is_reportingmanager %} -
{% csrf_token %}