Skip to content

Commit

Permalink
Ignore old_validated_name if None for val_name_audit_trail
Browse files Browse the repository at this point in the history
  • Loading branch information
Iso5786 committed Oct 8, 2024
1 parent 86e534b commit 700bd67
Showing 1 changed file with 21 additions and 10 deletions.
31 changes: 21 additions & 10 deletions apps/badgrsocialauth/providers/eduid/signals.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import django.dispatch
import logging
import uuid
from django.dispatch import receiver

import django.dispatch
from django.db import models
from django.dispatch import receiver


class ValidatedNameAuditTrail(models.Model):
Expand All @@ -16,20 +17,30 @@ class ValidatedNameAuditTrail(models.Model):

# Signals doc: https://docs.djangoproject.com/en/3.2/topics/signals/
val_name_audit_trail_signal = django.dispatch.Signal(
providing_args=['user', 'old_validated_name', 'new_validated_name']
providing_args=["user", "old_validated_name", "new_validated_name"]
) # creates a custom signal and specifies the args required.

logger = logging.getLogger(__name__)


@receiver(val_name_audit_trail_signal)
def new_val_name_audit_trail(sender, user, old_validated_name, new_validated_name, **kwargs):
def new_val_name_audit_trail(
sender, user, old_validated_name, new_validated_name, **kwargs
):
try:
audit_trail = ValidatedNameAuditTrail.objects.create(
user=user,
old_validated_name=old_validated_name,
new_validated_name=new_validated_name,
if old_validated_name is None:
audit_trail = ValidatedNameAuditTrail.objects.create(
user=user,
new_validated_name=new_validated_name,
)
else:
audit_trail = ValidatedNameAuditTrail.objects.create(
user=user,
old_validated_name=old_validated_name,
new_validated_name=new_validated_name,
)
logger.info(
f"val_name_audit_trail created {audit_trail.id} for user {audit_trail.user}"
)
logger.info(f'val_name_audit_trail created {audit_trail.id} for user {audit_trail.user}')
except Exception as e:
logger.error('val_name_audit_trail error: %s' % (e))
logger.error("val_name_audit_trail error: %s" % (e))

0 comments on commit 700bd67

Please sign in to comment.