From bef752039933df91f4568ad5a06e5e0820997768 Mon Sep 17 00:00:00 2001 From: Joey Chatelain Date: Tue, 10 Dec 2024 15:56:40 -0800 Subject: [PATCH 1/3] fix profile bug --- tom_common/apps.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tom_common/apps.py b/tom_common/apps.py index fae63b5fc..0a711d4a5 100644 --- a/tom_common/apps.py +++ b/tom_common/apps.py @@ -7,6 +7,9 @@ class TomCommonConfig(AppConfig): name = 'tom_common' def ready(self): + # Import signals for automatically saving profiles when updating User objects + import tom_common.signals # noqa + # Set default plotly theme on startup valid_themes = ['plotly', 'plotly_white', 'plotly_dark', 'ggplot2', 'seaborn', 'simple_white', 'none'] From 1354c7691e1ae5447dbcb13dd0c05439bf47728c Mon Sep 17 00:00:00 2001 From: Joey Chatelain Date: Tue, 10 Dec 2024 16:13:34 -0800 Subject: [PATCH 2/3] remove redundant signal --- tom_common/signals.py | 7 ------- 1 file changed, 7 deletions(-) diff --git a/tom_common/signals.py b/tom_common/signals.py index e2e761918..b36846a48 100644 --- a/tom_common/signals.py +++ b/tom_common/signals.py @@ -4,13 +4,6 @@ from tom_common.models import Profile -@receiver(post_save, sender=User) -def create_profile(sender, instance, created, **kwargs): - """When a new user is created, create a profile for them.""" - if created: - Profile.objects.create(user=instance) - - @receiver(post_save, sender=User) def save_profile(sender, instance, **kwargs): """When a user is saved, save their profile.""" From bc80f27fe2367cb6fdf90ffab4a3cdbe8fb923b2 Mon Sep 17 00:00:00 2001 From: Joey Chatelain Date: Wed, 11 Dec 2024 14:44:47 -0800 Subject: [PATCH 3/3] update logs/docs --- tom_common/apps.py | 1 + tom_common/signals.py | 6 ++++++ 2 files changed, 7 insertions(+) diff --git a/tom_common/apps.py b/tom_common/apps.py index 0a711d4a5..b242634fc 100644 --- a/tom_common/apps.py +++ b/tom_common/apps.py @@ -8,6 +8,7 @@ class TomCommonConfig(AppConfig): def ready(self): # Import signals for automatically saving profiles when updating User objects + # https://docs.djangoproject.com/en/5.1/topics/signals/#connecting-receiver-functions import tom_common.signals # noqa # Set default plotly theme on startup diff --git a/tom_common/signals.py b/tom_common/signals.py index b36846a48..4091c21ce 100644 --- a/tom_common/signals.py +++ b/tom_common/signals.py @@ -1,8 +1,13 @@ +import logging + from django.db.models.signals import post_save from django.contrib.auth.models import User from django.dispatch import receiver + from tom_common.models import Profile +logger = logging.getLogger(__name__) + @receiver(post_save, sender=User) def save_profile(sender, instance, **kwargs): @@ -12,4 +17,5 @@ def save_profile(sender, instance, **kwargs): try: instance.profile.save() except User.profile.RelatedObjectDoesNotExist: + logger.info(f'No Profile found for {instance}. Creating Profile.') Profile.objects.create(user=instance)