diff --git a/attendance/templates/attendance/late_come_early_out/tracking.html b/attendance/templates/attendance/late_come_early_out/tracking.html index b012bd450..4b4982b81 100644 --- a/attendance/templates/attendance/late_come_early_out/tracking.html +++ b/attendance/templates/attendance/late_come_early_out/tracking.html @@ -9,4 +9,4 @@ {{ form.is_enable.errors }} -{% endblock %} \ No newline at end of file +{% endblock %} diff --git a/horilla_audit/methods.py b/horilla_audit/methods.py index 29540ff7d..7a9fa8d8a 100644 --- a/horilla_audit/methods.py +++ b/horilla_audit/methods.py @@ -5,7 +5,11 @@ This module is used to write methods related to the history """ from django.contrib.auth.models import User +from django.core.paginator import Paginator from django.db import models +from django.shortcuts import render + +from horilla.decorators import apply_decorators class Bot: @@ -146,3 +150,27 @@ def get_diff(instance): if track_fields: delta_changes = filter_history(delta_changes, track_fields) return delta_changes + + +def history_tracking(request, obj_id, **kwargs): + model = kwargs.get("model") + decorator_strings = kwargs.get("decorators", []) + + @apply_decorators(decorator_strings) + def _history_tracking(request, obj_id, model): + instance = model.objects.get(pk=obj_id) + histories = instance.horilla_history.all() + page_number = request.GET.get("page", 1) + paginator = Paginator(histories, 4) + page_obj = paginator.get_page(page_number) + context = { + "histories": page_obj, + "model_name": model, + } + return render( + request, + "horilla_audit/history_tracking.html", + context, + ) + + return _history_tracking(request, obj_id, model) diff --git a/horilla_audit/templates/horilla_audit/history_tracking.html b/horilla_audit/templates/horilla_audit/history_tracking.html new file mode 100644 index 000000000..a3a684b5b --- /dev/null +++ b/horilla_audit/templates/horilla_audit/history_tracking.html @@ -0,0 +1,144 @@ +{% load static %} {% load i18n %} {% load audit_filters %} +
+ + + +

+ {{model_name|verbose_name}} {% trans "History" %} +

+
+
+
+ {% if histories %} {% for history in histories %} +
+
+ + {{ history.timestamp|date:"M. d, Y" }} ,  + {{ history.timestamp|date:"g:i A" }} + +
+
+
+ {% if history.actor.employee_get %} + + {% else %} + + {% endif %} +
+
+ +
+ {% if history.actor.employee_get %} {{history.actor.employee_get.get_full_name}} {% else %} Horilla Bot {% endif %} +
+ + {% if history.action == 0 %} + {% trans "Created" %} {{model_name|verbose_name}} + {% elif history.action == 1 %} + {% trans "Updated" %} {{model_name|verbose_name}} + {% endif %} + +
+
+
+
    + {% for change,value in history.changes_dict.items %} + {% if value.type == 'm2m' %} +
  • +
    + {{model_name|verbose_name:change}} + + {{value.objects|join:", "}} +
    +
  • + {% endif %} + {% endfor %} + {% for change,value in history.changes_display_dict.items %} + {% if not value.0 == "type" %} +
  • +
    + {{change}} + ({{value.0}}) + + ({{value.1}}) +
    +
  • + {% endif %} + {% endfor %} +
+
+
+
+
+ {% if histories.has_next and forloop.last %} +
+
+ {% endif %} +
+ {% endfor %} + {% else %} +
+
{% trans "No history found." %}
+
+ {% endif %} +
+
+ \ No newline at end of file diff --git a/horilla_audit/templatetags/audit_filters.py b/horilla_audit/templatetags/audit_filters.py index e5a6c4a29..f157da96d 100644 --- a/horilla_audit/templatetags/audit_filters.py +++ b/horilla_audit/templatetags/audit_filters.py @@ -1,9 +1,5 @@ -from django import template -from django.core.paginator import Page, Paginator from django.template.defaultfilters import register -from employee.models import Employee, EmployeeWorkInformation - @register.filter(name="fk_history") def fk_history(instance, change): @@ -18,3 +14,19 @@ def fk_history(instance, change): value = str(value) + f" (Previous {change['field']} deleted)" pass return value + + +@register.filter(name="verbose_name") +def verbose_name(model, field_name=None): + """ " + This method is used to fine the verbose name of a field + """ + if not field_name: + model_name = model._meta.verbose_name.capitalize() + return model_name + + try: + field = model._meta.get_field(field_name) + return field.verbose_name + except: + return field_name diff --git a/templates/index.html b/templates/index.html index c918d5dd9..4dc9d85d3 100755 --- a/templates/index.html +++ b/templates/index.html @@ -441,7 +441,7 @@ $(document).on("htmx:beforeRequest", function (event, data) { var response = event.detail.xhr.response; var target = $(event.detail.elt.getAttribute("hx-target")); - var avoid_target = ["BiometricDeviceTestFormTarget","reloadMessages"]; + var avoid_target = ["BiometricDeviceTestFormTarget","reloadMessages", "infinite"]; if (!target.closest("form").length && avoid_target.indexOf(target.attr("id")) === -1) { target.html(`
`); }