Formatting and Cleaning code base (#110)
This commit is contained in:
committed by
GitHub
parent
fb10738b39
commit
42c5b34353
@@ -1 +1 @@
|
||||
from horilla_audit import settings
|
||||
from horilla_audit import settings
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
"""
|
||||
admin.py
|
||||
"""
|
||||
|
||||
from django.contrib import admin
|
||||
from horilla_audit.models import HorillaAuditLog, HorillaAuditInfo, AuditTag
|
||||
|
||||
|
||||
@@ -2,5 +2,5 @@ from django.apps import AppConfig
|
||||
|
||||
|
||||
class HorillaAuditConfig(AppConfig):
|
||||
default_auto_field = 'django.db.models.BigAutoField'
|
||||
name = 'horilla_audit'
|
||||
default_auto_field = "django.db.models.BigAutoField"
|
||||
name = "horilla_audit"
|
||||
|
||||
@@ -3,6 +3,7 @@ context_processor.py
|
||||
|
||||
This module is used to register context processor`
|
||||
"""
|
||||
|
||||
from django.urls import path, include
|
||||
from django.http import JsonResponse
|
||||
from horilla_audit.forms import HistoryForm
|
||||
|
||||
@@ -63,8 +63,10 @@ class HistoryTrackingFieldsForm(forms.Form):
|
||||
"additional_info",
|
||||
"experience",
|
||||
]
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
from employee.models import EmployeeWorkInformation as model
|
||||
|
||||
super(HistoryTrackingFieldsForm, self).__init__(*args, **kwargs)
|
||||
field_choices = [
|
||||
(field.name, field.verbose_name)
|
||||
@@ -80,4 +82,4 @@ class HistoryTrackingFieldsForm(forms.Form):
|
||||
"style": "height:270px;",
|
||||
}
|
||||
),
|
||||
)
|
||||
)
|
||||
|
||||
@@ -3,9 +3,11 @@ methods.py
|
||||
|
||||
This module is used to write methods related to the history
|
||||
"""
|
||||
|
||||
from django.db import models
|
||||
from django.contrib.auth.models import User
|
||||
|
||||
|
||||
class Bot:
|
||||
def __init__(self) -> None:
|
||||
self.__str__()
|
||||
@@ -53,14 +55,12 @@ def get_field_label(model_class, field_name):
|
||||
return None
|
||||
|
||||
|
||||
def filter_history(histories,track_fields):
|
||||
def filter_history(histories, track_fields):
|
||||
filtered_histories = []
|
||||
for history in histories:
|
||||
changes = history.get("changes", [])
|
||||
filtered_changes = [
|
||||
change
|
||||
for change in changes
|
||||
if change.get("field_name", "") in track_fields
|
||||
change for change in changes if change.get("field_name", "") in track_fields
|
||||
]
|
||||
if filtered_changes:
|
||||
history["changes"] = filtered_changes
|
||||
@@ -68,6 +68,7 @@ def filter_history(histories,track_fields):
|
||||
histories = filtered_histories
|
||||
return histories
|
||||
|
||||
|
||||
def get_diff(instance):
|
||||
"""
|
||||
This method is used to find the differences in the history
|
||||
@@ -89,7 +90,12 @@ def get_diff(instance):
|
||||
new = change.new
|
||||
field = instance._meta.get_field(change.field)
|
||||
is_fk = False
|
||||
if isinstance(field, models.fields.CharField) and field.choices and old and new:
|
||||
if (
|
||||
isinstance(field, models.fields.CharField)
|
||||
and field.choices
|
||||
and old
|
||||
and new
|
||||
):
|
||||
choices = dict(field.choices)
|
||||
old = choices[old]
|
||||
new = choices[new]
|
||||
@@ -132,9 +138,10 @@ def get_diff(instance):
|
||||
}
|
||||
)
|
||||
from .models import HistoryTrackingFields
|
||||
|
||||
history_tracking_instance = HistoryTrackingFields.objects.first()
|
||||
if history_tracking_instance:
|
||||
track_fields = history_tracking_instance.tracking_fields["tracking_fields"]
|
||||
if track_fields:
|
||||
delta_changes = filter_history(delta_changes,track_fields)
|
||||
delta_changes = filter_history(delta_changes, track_fields)
|
||||
return delta_changes
|
||||
|
||||
Reference in New Issue
Block a user