From 5a3e6488d0cc81792cc3b55477485cb95601d2cb Mon Sep 17 00:00:00 2001 From: Horilla Date: Thu, 14 Nov 2024 15:35:44 +0530 Subject: [PATCH] [UPDT] BASE: Base app request comments delete and file delete HTMX attributes --- base/templates/announcement/comment_view.html | 20 +- .../templates/base/auth/permission_lines.html | 3 - .../templates/base/auth/permission_table.html | 1 - .../shift_request/htmx/requests.html | 240 +++++----- .../shift_request/htmx/shift_comment.html | 195 +++----- .../htmx/work_type_comment.html | 207 +++------ base/views.py | 124 +++-- employee/templates/tabs/note_tab.html | 433 ++++++------------ employee/views.py | 18 +- 9 files changed, 485 insertions(+), 756 deletions(-) diff --git a/base/templates/announcement/comment_view.html b/base/templates/announcement/comment_view.html index adbcd6555..b30f20708 100644 --- a/base/templates/announcement/comment_view.html +++ b/base/templates/announcement/comment_view.html @@ -35,7 +35,7 @@ {% csrf_token %}
- + @@ -69,7 +69,7 @@ {% if perms.base.delete_announcementcomment or request.user == comment.created_by %} {{ comment.comment }} + hx-swap="delete" hx-target="#announCommentCard{{comment.id}}" hx-on:click="setTimeout(() => {reloadMessage(this);},100);"> {% endif %} @@ -101,19 +101,3 @@ {% endif %} - - diff --git a/base/templates/base/auth/permission_lines.html b/base/templates/base/auth/permission_lines.html index 95ca441b8..82e6d8ab1 100644 --- a/base/templates/base/auth/permission_lines.html +++ b/base/templates/base/auth/permission_lines.html @@ -62,9 +62,6 @@ {% endif %} {% endif %} -
- - - - {% trans "Comments" %} -
- {% if request.user.employee_get == shift_request.employee_id or perms.base.add_shiftrequestcomment or request.user|is_reportingmanager %} -
- {% csrf_token %} -
- - -
- -
- {% endif %} +
+ + + + {% trans "Comments" %} +
+{% if request.user.employee_get == shift_request.employee_id or perms.base.add_shiftrequestcomment or request.user|is_reportingmanager %} +
+ {% csrf_token %} +
+ + +
+ +
+{% endif %} {% if comments %}
    {% for comment in comments %}
  1. {{ comment.comment }} - {% if request.user.employee_get == shift_request.employee_id or perms.base.delete_shiftrequestcomment or request.user|is_reportingmanager %} - - + {% if request.user.employee_get == comment.employee_id or perms.base.delete_shiftrequestcomment or request.user|is_reportingmanager %} + + {% endif %}
    {% for file in comment.files.all %} - + + + + {% if request.user.employee_get == comment.employee_id or perms.base.delete_baserequestfile or request.user|is_reportingmanager %} + + {% endif %} + + {% endfor %} - -
    - {% csrf_token %} - - - -
    + {% if request.user.employee_get == comment.employee_id or perms.base.add_baserequestfile or request.user|is_reportingmanager %} +
    + {% csrf_token %} + + + +
    + {% endif %}
    {% trans 'by' %} - + {{ comment.employee_id.get_full_name }} @ {{comment.request_id.employee_id.get_full_name }} {% trans "'s shift request" %} @@ -124,52 +90,15 @@
- {% endfor %} {% else %}
- {% trans "There are no comments to show." %} - + {% trans "There are no comments to show." %} +
{% endif %} - - - - - - - diff --git a/base/templates/work_type_request/htmx/work_type_comment.html b/base/templates/work_type_request/htmx/work_type_comment.html index 6cb9a3e9e..710174b2f 100644 --- a/base/templates/work_type_request/htmx/work_type_comment.html +++ b/base/templates/work_type_request/htmx/work_type_comment.html @@ -1,56 +1,45 @@ {% load i18n static %} {% load basefilters %} {% if messages %} -
- {% for message in messages %} -
{{ message }}
- {% endfor %} -
- + {% endif %} -
- - - - {% trans "Comments" %} -
- {% if request.user.employee_get == work_type_request.employee_id or perms.base.add_worktyperequestcomment or request.user|is_reportingmanager %} -
- {% csrf_token %} +
+ + + + {% trans "Comments" %} +
+{% if request.user.employee_get == work_type_request.employee_id or perms.base.add_worktyperequestcomment or request.user|is_reportingmanager %} + + {% csrf_token %} -
- - -
+
+ + +
- -
- {% endif %} + + +{% endif %} {% if comments %} @@ -58,72 +47,48 @@ {% for comment in comments %}
  • {{ comment.comment }} - {% if request.user.employee_get == work_type_request.employee_id or perms.base.delete_worktyperequestcomment or request.user|is_reportingmanager %} - - - + {% if request.user.employee_get == comment.employee_id or perms.base.delete_worktyperequestcomment or request.user|is_reportingmanager %} + + + {% endif %}
    {% for file in comment.files.all %} - + + + {% if request.user.employee_get == comment.employee_id or perms.base.delete_baserequestfile or request.user|is_reportingmanager %} + + {% endif %} + + {% endfor %} - -
    - {% csrf_token %} - - - -
    + {% if request.user.employee_get == comment.employee_id or perms.base.add_baserequestfile or request.user|is_reportingmanager %} +
    + {% csrf_token %} + + + +
    + {% endif %}
    {% trans 'by' %} - + {{ comment.employee_id.get_full_name }} @ {{comment.request_id.employee_id.get_full_name }} {% trans "'s worktype request" %} @@ -131,52 +96,16 @@
  • - {% endfor %} {% else %}
    - {% trans "There are no comments to show." %} - + {% trans "There are no comments to show." %} +
    {% endif %} - - - - - - - diff --git a/base/views.py b/base/views.py index ff3ba68c8..cb3031465 100644 --- a/base/views.py +++ b/base/views.py @@ -109,6 +109,7 @@ from base.methods import ( format_date, get_key_instances, get_pagination, + is_reportingmanager, sortby, ) from base.models import ( @@ -4011,7 +4012,7 @@ def shift_request_view(request): allocated_shift_requests = filtersubordinates( request, ShiftRequest.objects.filter(reallocate_to__isnull=False), - "base.add_shiftrequest", + "base.view_shiftrequest", ) allocated_requests = ShiftRequest.objects.filter(reallocate_to__isnull=False) if not request.user.has_perm("base.view_shiftrequest"): @@ -4816,22 +4817,25 @@ def delete_notification(request, id): """ This method is used to delete notification """ + script = "" try: request.user.notifications.get(id=id).delete() messages.success(request, _("Notification deleted.")) except Exception as e: messages.error(request, e) - notifications = request.user.notifications.all() - return render( - request, "notification/all_notifications.html", {"notifications": notifications} - ) + if not request.user.notifications.all(): + script = """""" + return HttpResponse(script) @login_required def mark_as_read_notification(request, notification_id): + script = "" notification = Notification.objects.get(id=notification_id) notification.mark_as_read() - return redirect(notifications) + if not request.user.notifications.unread(): + script = """""" + return HttpResponse(script) @login_required @@ -5782,26 +5786,27 @@ def view_shift_comment(request, shift_id): @login_required -@permission_required("offboarding.delete_offboardingnote") +@hx_request_required def delete_shift_comment_file(request): """ Used to delete attachment """ ids = request.GET.getlist("ids") - BaserequestFile.objects.filter(id__in=ids).delete() - messages.success(request, _("File deleted successfully")) shift_id = request.GET["shift_id"] - comments = ShiftRequestComment.objects.filter(request_id=shift_id).order_by( - "-created_at" - ) - return render( - request, - "shift_request/htmx/shift_comment.html", - { - "comments": comments, - "request_id": shift_id, - }, - ) + comment_id = request.GET["comment_id"] + comment = ShiftRequestComment.find(comment_id) + script = "" + if ( + request.user.employee_get == comment.employee_id + or request.user.has_perm("base.delete_baserequestfile") + or is_reportingmanager(request) + ): + BaserequestFile.objects.filter(id__in=ids).delete() + messages.success(request, _("File deleted successfully")) + else: + messages.warning(request, _("You don't have permission")) + script = f"""""" + return HttpResponse(script) @login_required @@ -5841,24 +5846,27 @@ def view_work_type_comment(request, work_type_id): @login_required -@permission_required("offboarding.delete_offboardingnote") +@hx_request_required def delete_work_type_comment_file(request): """ Used to delete attachment """ ids = request.GET.getlist("ids") - BaserequestFile.objects.filter(id__in=ids).delete() - messages.success(request, _("File deleted successfully")) - work_type_id = request.GET["work_type_id"] - comments = WorkTypeRequestComment.objects.filter(request_id=work_type_id) - return render( - request, - "work_type_request/htmx/work_type_comment.html", - { - "comments": comments, - "request_id": work_type_id, - }, - ) + request_id = request.GET["request_id"] + comment_id = request.GET["comment_id"] + comment = WorkTypeRequestComment.find(comment_id) + script = "" + if ( + request.user.employee_get == comment.employee_id + or request.user.has_perm("base.delete_baserequestfile") + or is_reportingmanager(request) + ): + BaserequestFile.objects.filter(id__in=ids).delete() + messages.success(request, _("File deleted successfully")) + else: + messages.warning(request, _("You don't have permission")) + script = f"""""" + return HttpResponse(script) @login_required @@ -5868,9 +5876,19 @@ def delete_shiftrequest_comment(request, comment_id): This method is used to delete shift request comments """ comment = ShiftRequestComment.find(comment_id) - comment.delete() - messages.success(request, _("Comment deleted successfully!")) - return HttpResponse() + request_id = comment.request_id.id + script = "" + if ( + request.user.employee_get == comment.employee_id + or request.user.has_perm("base.delete_baserequestfile") + or is_reportingmanager(request) + ): + comment.delete() + messages.success(request, _("Comment deleted successfully!")) + else: + messages.warning(request, _("You don't have permission")) + script = f"""""" + return HttpResponse(script) @login_required @@ -5997,10 +6015,20 @@ def delete_worktyperequest_comment(request, comment_id): """ This method is used to delete Work type request comments """ - comment = WorkTypeRequestComment.objects.filter(id=comment_id) - comment.delete() - messages.success(request, _("Comment deleted successfully!")) - return HttpResponse() + script = "" + comment = WorkTypeRequestComment.find(comment_id) + request_id = comment.request_id.id + if ( + request.user.employee_get == comment.employee_id + or request.user.has_perm("base.delete_baserequestfile") + or is_reportingmanager(request) + ): + comment.delete() + messages.success(request, _("Comment deleted successfully!")) + else: + messages.warning(request, _("You don't have permission")) + script = f"""""" + return HttpResponse(script) @login_required @@ -6026,7 +6054,7 @@ def pagination_settings_view(request): @login_required -@permission_required("base.view_actiontype") +@permission_required("employee.view_actiontype") def action_type_view(request): """ This method is used to show Action Type @@ -6039,7 +6067,7 @@ def action_type_view(request): @login_required @hx_request_required -@permission_required("base.add_actiontype") +@permission_required("employee.add_actiontype") def action_type_create(request): """ This method renders form and template to create Action Type @@ -6053,9 +6081,7 @@ def action_type_create(request): form.save() form = ActiontypeForm() messages.success(request, _("Action has been created successfully!")) - if dynamic == "None": - return HttpResponse("") - else: + if dynamic != "None": url = reverse("create-actions") instance = Actiontype.objects.all().order_by("-id").first() mutable_get = request.GET.copy() @@ -6075,7 +6101,7 @@ def action_type_create(request): @login_required @hx_request_required -@permission_required("base.change_actiontype") +@permission_required("employee.change_actiontype") def action_type_update(request, act_id): """ This method renders form and template to update Action type @@ -6084,7 +6110,10 @@ def action_type_update(request, act_id): form = ActiontypeForm(instance=action) if action.action_type == "warning": - if AccountBlockUnblock.objects.first().is_enabled: + if ( + AccountBlockUnblock.objects.first() + and AccountBlockUnblock.objects.first().is_enabled + ): form.fields["block_option"].widget = forms.HiddenInput() if request.method == "POST": @@ -6096,7 +6125,6 @@ def action_type_update(request, act_id): form.save() form = ActiontypeForm() messages.success(request, _("Action has been updated successfully!")) - return HttpResponse("") return render( request, "base/action_type/action_type_form.html", diff --git a/employee/templates/tabs/note_tab.html b/employee/templates/tabs/note_tab.html index 9cab1d72d..4be186cc2 100644 --- a/employee/templates/tabs/note_tab.html +++ b/employee/templates/tabs/note_tab.html @@ -1,295 +1,164 @@ {% load static %}{% load i18n %} {% load basefilters %} {% if messages %} -
    - {% for message in messages %} -
    -
    - {{ message }} -
    -
    - {% endfor %} -
    + {% endif %} - {% if notes %} - - {% if perms.employee.add_employeenote or request.user|is_reportingmanager %} -
    - {% csrf_token %} -
    - - - {% csrf_token %} - -
    -
    - {{employee}}'s {% trans "Notes" %} - -
    - -
    - - - - -
    -
    - -
    - - {% endif %} -
    -
      - {% for note in notes %} -
      -
    1. - {{note.description}} - {% if perms.employee.delete_employeenote or request.user|is_reportingmanager %} - - - - {% endif %} - - -
      - {% for file in note.note_files.all %} - - {% endfor %} - -
      - {% csrf_token %} - - - -
      -
      - - - {% trans "by" %} - User - {{note.updated_by}} - - - {% trans "at" %}   - {{ note.created_at|date:"Y-m-d" }} -   - {{ note.created_at|time:"H:i" }} - -
      -
      -
      -
    2. -
      - {% endfor %} -
    -{% else %} {% if messages %} -
    - {% for message in messages %} -
    -
    - {{ message }} -
    -
    - {% endfor %} -
    -{% endif %} -
    - -
    - {% csrf_token %} - -
    +{% if notes %} +
    - {{employee}}'s {% trans "Notes" %} - + + {% csrf_token %} +
    +
    + {{employee}}'s {% trans "Notes" %} + {% if perms.employee.add_employeenote or request.user|is_reportingmanager %} + + {% endif %} +
    + +
    + +
    - -
    - - - - -
    -
    - -
    - {% trans "No notes have been added for this employee" %} -
    -
    - -{% endif %} -