From dc16045739e70db87001c6f171c9cd17c77ad521 Mon Sep 17 00:00:00 2001 From: Horilla Date: Tue, 16 Sep 2025 17:30:48 +0530 Subject: [PATCH] [UPDT] EMPLOYEE: Updated pagination to document request --- employee/cbv/document_request.py | 72 ++++- employee/filters.py | 21 +- .../cbv/documents/document_list.html | 274 ++++++++++++++++++ .../templates/cbv/documents/pipeline.html | 65 +++++ employee/urls.py | 20 +- 5 files changed, 444 insertions(+), 8 deletions(-) create mode 100644 employee/templates/cbv/documents/document_list.html create mode 100644 employee/templates/cbv/documents/pipeline.html diff --git a/employee/cbv/document_request.py b/employee/cbv/document_request.py index 3a18fd480..dcc346a94 100644 --- a/employee/cbv/document_request.py +++ b/employee/cbv/document_request.py @@ -13,7 +13,7 @@ from django.utils.decorators import method_decorator from django.utils.translation import gettext_lazy as _ from base.methods import choosesubordinates, is_reportingmanager -from employee.filters import DocumentRequestFilter +from employee.filters import DocumentPipelineFilter, DocumentRequestFilter from employee.models import Employee from horilla.decorators import manager_can_enter from horilla_documents.forms import DocumentForm @@ -21,7 +21,12 @@ from horilla_documents.forms import DocumentRejectCbvForm as RejectForm from horilla_documents.forms import DocumentRequestForm, DocumentUpdateForm from horilla_documents.models import Document, DocumentRequest from horilla_views.cbv_methods import login_required -from horilla_views.generic.cbv.views import HorillaFormView, HorillaNavView +from horilla_views.generic.cbv.pipeline import Pipeline +from horilla_views.generic.cbv.views import ( + HorillaFormView, + HorillaListView, + HorillaNavView, +) from notifications.signals import notify @@ -179,6 +184,7 @@ class DocumentUploadForm(HorillaFormView): ) except: pass + form.instance.status = "requested" form.save() return HttpResponse("") return super().form_valid(form) @@ -239,3 +245,65 @@ class DocumentRequestNav(HorillaNavView): filter_instance = DocumentRequestFilter() filter_form_context_name = "form" search_swap_target = "#view-container" + + +class DocumentRequestPipelineView(Pipeline): + """ + Pipeline view for document request + """ + + model = Document + filter_class = DocumentRequestFilter + grouper = "document_request_id" + template_name = "cbv/documents/pipeline.html" + + allowed_fields = [ + { + "field": "document_request_id", + "model": DocumentRequest, + "filter": DocumentPipelineFilter, + "url": reverse_lazy("document-request-list"), + "parameters": [ + "document_request_id={pk}", + ], + "actions": [ + { + "action": _("Edit"), + "attrs": """ + class="oh-dropdown__link oh-dropdown__link" + data-toggle="oh-modal-toggle" + data-target="#objectCreateModal" + hx-get="{get_edit_url}" + hx-target="#objectCreateModalTarget" + """, + }, + { + "action": _("Delete"), + "attrs": """ + class="oh-dropdown__link oh-dropdown__link" + hx-confirm="Are you sure you want to delete this document request?" + hx-post="{get_delete_url}" + hx-target="body" + """, + }, + ], + } + ] + + +class DocumentListView(HorillaListView): + """ + List view for document request + """ + + model = Document + filter_class = DocumentRequestFilter + template_name = "cbv/documents/document_list.html" + filter_keys_to_remove = ["document_request_id"] + + def get_queryset(self, queryset=None, filtered=False, *args, **kwargs): + queryset = super().get_queryset(queryset, filtered, *args, **kwargs) + queryset = queryset.filter( + document_request_id__pk=self.request.GET.get("document_request_id") + ) + return queryset diff --git a/employee/filters.py b/employee/filters.py index 83dc8bfa5..f793df885 100644 --- a/employee/filters.py +++ b/employee/filters.py @@ -24,7 +24,7 @@ from employee.models import ( ) from horilla.filters import FilterSet, HorillaFilterSet, filter_by_name from horilla.horilla_middlewares import _thread_locals -from horilla_documents.models import Document +from horilla_documents.models import Document, DocumentRequest from horilla_views.templatetags.generic_template_filters import getattribute @@ -298,6 +298,25 @@ class DocumentRequestFilter(FilterSet): ] +class DocumentPipelineFilter(HorillaFilterSet): + """ + Filter set class for TaxBracket model. + """ + + search = django_filters.CharFilter(method="search_method") + + class Meta: + model = DocumentRequest + fields = "__all__" + + def search_method(self, queryset, _, value): + """ + This method is used to search + """ + + return queryset.filter(title__icontains=value).distinct() + + class DisciplinaryActionFilter(FilterSet): """ Custom filter for Disciplinary Action. diff --git a/employee/templates/cbv/documents/document_list.html b/employee/templates/cbv/documents/document_list.html new file mode 100644 index 000000000..aed727197 --- /dev/null +++ b/employee/templates/cbv/documents/document_list.html @@ -0,0 +1,274 @@ +{% load static i18n generic_template_filters %} + +
+ + + + + {% if show_filter_tags %} {% include "generic/filter_tags.html" %} {% endif %} + + {% if queryset|length %} + +
+
+
+ + + {% for document in queryset %} +
+ {% if document.document %} + {% if document.status == "approved" %} +
+ +
+ {% elif document.status == 'rejected' %} +
+ +
+ {% else %} +
+ +
+ {% endif %} + {% else %} +
+ +
+ {% endif %} + +
+
+
+ {{ document.title }} -- {{document.employee_id.get_full_name}} +
+ + +
+
+ +
+
+ {% if document.document %} {{document.status}} + {% else %} {% trans "No Document" %} + {% endif %} +
+
+ +
+ {% if document.issue_date %} {{document.issue_date}}{% else %} - {% endif %} +
+ +
+ {% if document.document %} + {% if perms.horilla_document.change_documentrequest %} + {% if document.status == "approved" %} + + + + {% else %} + + + {% endif %} + {% endif %} + {% else %} + + {% endif %} + + {% if not document.document_request_id or perms.horilla_document.change_documentrequest %} +
+ {% csrf_token %} + +
+ {% endif %} +
+
+ {% endfor %} +
+
+ {% if queryset.has_previous or queryset.has_next %} +
+

{% trans "Page" %} {{ queryset.number }} {% trans "of" %} {{ queryset.paginator.num_pages }}

+
+ {% if queryset.has_previous %} + + {% endif %} + {{ queryset.number }} / {{ queryset.paginator.num_pages }} + {% if queryset.has_next %} + + {% endif %} +
+
+ {% endif %} +
+ {% else %} +
+
+
+ +

{% trans "No Documents available at the moment" %}

+
+
+
+ {% endif %} +
+ + + + \ No newline at end of file diff --git a/employee/templates/cbv/documents/pipeline.html b/employee/templates/cbv/documents/pipeline.html new file mode 100644 index 000000000..4822b6d19 --- /dev/null +++ b/employee/templates/cbv/documents/pipeline.html @@ -0,0 +1,65 @@ +{% load i18n generic_template_filters %} + +
+ {% for group in groups %} +
+
+
+
+ {{group}} + +
+
+ + +
+
+
+
+
+
+
+ {% endfor %} +
+ \ No newline at end of file diff --git a/employee/urls.py b/employee/urls.py index 028c0935f..f2487a77a 100644 --- a/employee/urls.py +++ b/employee/urls.py @@ -430,11 +430,11 @@ urlpatterns = [ views.document_request_view, name="document-request-view", ), - path( - "document-request-filter-view", - views.document_filter_view, - name="document-request-filter-view", - ), + # path( + # "document-request-filter-view", + # views.document_filter_view, + # name="document-request-filter-view", + # ), path( "document-request-create", document_request.DocumentRequestCreateForm.as_view(), @@ -450,6 +450,16 @@ urlpatterns = [ document_request.DocumentRequestNav.as_view(), name="document-request-nav-cbv", ), + path( + "document-request-filter-view", + document_request.DocumentRequestPipelineView.as_view(), + name="document-request-filter-view", + ), + path( + "document-request-list", + document_request.DocumentListView.as_view(), + name="document-request-list", + ), path( "document-request-update//", document_request.DocumentRequestCreateForm.as_view(),