From 2c5863ef159c4ce5f30d9aaaf185e3f540eebef0 Mon Sep 17 00:00:00 2001 From: Horilla Date: Mon, 29 Jan 2024 15:08:36 +0530 Subject: [PATCH] [UPDT] BASE: Changed comment view from modal to activity sidebar --- base/context_processors.py | 12 ++ base/forms.py | 45 +++++++ base/templates/base/general_settings.html | 1 + .../shift_request/htmx/requests.html | 4 +- .../shift_request/htmx/shift_comment.html | 113 ++++++++++++++++++ .../shift_request/shift_request_view.html | 56 +++++++++ base/urls.py | 11 ++ 7 files changed, 240 insertions(+), 2 deletions(-) create mode 100644 base/templates/shift_request/htmx/shift_comment.html diff --git a/base/context_processors.py b/base/context_processors.py index 2d4816fbf..f043eb0f4 100644 --- a/base/context_processors.py +++ b/base/context_processors.py @@ -5,6 +5,7 @@ This module is used to register context processor` """ from django.urls import path from django.http import HttpResponse +from attendance.models import AttendanceGeneralSetting from base.models import Company from base.urls import urlpatterns from offboarding.models import OffboardingGeneralSetting @@ -102,3 +103,14 @@ def resignation_request_enabled(request): if first: enabled_resignation_request = first.resignation_request return {"enabled_resignation_request": enabled_resignation_request} + + +def timerunner_enabled(request): + """ + Check weather resignation_request enabled of not in offboarding + """ + first = AttendanceGeneralSetting.objects.first() + enabled_timerunner = True + if first: + enabled_timerunner = first.time_runner + return {"enabled_timerunner": enabled_timerunner} diff --git a/base/forms.py b/base/forms.py index 58a432eb3..7c127af64 100644 --- a/base/forms.py +++ b/base/forms.py @@ -24,6 +24,7 @@ from base.models import ( AnnouncementComment, AnnouncementExpire, Attachment, + BaserequestFile, Company, Department, DynamicEmailConfiguration, @@ -50,6 +51,8 @@ from base.methods import reload_queryset from horilla_audit.models import AuditTag from horilla_widgets.widgets.horilla_multi_select_field import HorillaMultiSelectField from horilla_widgets.widgets.select_widgets import HorillaMultiSelectWidget +from employee.forms import MultipleFileField + # your form here @@ -1550,6 +1553,48 @@ class ShiftrequestcommentForm(ModelForm): model = ShiftrequestComment fields = ('comment',) + + +class shiftCommentForm(ModelForm): + """ + Shift request comment model form + """ + + verbose_name = "Add Comment" + + class Meta: + model = ShiftrequestComment + fields = "__all__" + + def __init__(self, *args, **kwargs): + super().__init__(*args, **kwargs) + self.fields["files"] = MultipleFileField(label="files") + self.fields["files"].required = False + + def as_p(self): + """ + Render the form fields as HTML table rows with Bootstrap styling. + """ + context = {"form": self} + table_html = render_to_string("common_form.html", context) + return table_html + + def save(self, commit: bool = ...) -> Any: + multiple_files_ids = [] + files = None + if self.files.getlist("files"): + files = self.files.getlist("files") + self.instance.attachemnt = files[0] + multiple_files_ids = [] + for attachemnt in files: + file_instance = BaserequestFile() + file_instance.file = attachemnt + file_instance.save() + multiple_files_ids.append(file_instance.pk) + instance = super().save(commit) + if commit: + instance.files.add(*multiple_files_ids) + return instance, files class WorktyperequestcommentForm(ModelForm): diff --git a/base/templates/base/general_settings.html b/base/templates/base/general_settings.html index 4022c2afc..b5340f031 100644 --- a/base/templates/base/general_settings.html +++ b/base/templates/base/general_settings.html @@ -3,5 +3,6 @@ {% include "announcement/expiry_day.html" %} {% include "offboarding/settings/settings.html" %} +{% include "attendance/settings/settings.html" %} {% endblock settings %} \ No newline at end of file diff --git a/base/templates/shift_request/htmx/requests.html b/base/templates/shift_request/htmx/requests.html index ca23891fd..82ad7e8b4 100755 --- a/base/templates/shift_request/htmx/requests.html +++ b/base/templates/shift_request/htmx/requests.html @@ -97,8 +97,8 @@ style="cursor: pointer;" - diff --git a/base/templates/shift_request/htmx/shift_comment.html b/base/templates/shift_request/htmx/shift_comment.html new file mode 100644 index 000000000..28dbf226e --- /dev/null +++ b/base/templates/shift_request/htmx/shift_comment.html @@ -0,0 +1,113 @@ +{% load i18n static %} + + + + {% trans 'Add comment' %} + +{% if comments %} +
    + {% for comment in comments %} +
  1. + {{ comment.comment }} + +
    + {% for file in comment.files.all %} + + {% endfor %} + +
    + {% csrf_token %} + + + +
    +
    + + {% trans 'by' %} + + {{ comment.employee_id.get_full_name }} @ {{comment.request_id.employee_id.get_full_name }} + {% trans "'s shift request" %} + +
    +
    +
    +
  2. + {% endfor %} +
+{% else %} +
+
+
+ {% trans "There are no comments to show." %} + +
+
+
+{% endif %} diff --git a/base/templates/shift_request/shift_request_view.html b/base/templates/shift_request/shift_request_view.html index b3253af23..d1283ee77 100644 --- a/base/templates/shift_request/shift_request_view.html +++ b/base/templates/shift_request/shift_request_view.html @@ -64,5 +64,61 @@ +
+
+ + + + {% trans "Comments" %} +
+
+
+
+ + + + + {% endblock content %} \ No newline at end of file diff --git a/base/urls.py b/base/urls.py index 3fff200ce..157186b6f 100644 --- a/base/urls.py +++ b/base/urls.py @@ -647,6 +647,17 @@ urlpatterns = [ views.view_shiftrequest_comment, name="shift-request-view-comment", ), + + path( + "view-shift-comment//", + views.view_shift_comment, + name="view-shift-comment", + ), + path( + "delete-comment-file/", + views.delete_comment_file, + name="delete-comment-file", + ), path( "shift-request-delete-comment//", views.delete_shiftrequest_comment,