Skip to content

Commit

Permalink
Merge pull request #1140 from TOMToolkit/profiles_patch
Browse files Browse the repository at this point in the history
fix profile bug
  • Loading branch information
jchate6 authored Dec 12, 2024
2 parents b63fe7e + bc80f27 commit d830117
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
4 changes: 4 additions & 0 deletions tom_common/apps.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ class TomCommonConfig(AppConfig):
name = 'tom_common'

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
valid_themes = ['plotly', 'plotly_white', 'plotly_dark', 'ggplot2', 'seaborn', 'simple_white', 'none']

Expand Down
11 changes: 5 additions & 6 deletions tom_common/signals.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
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

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)
logger = logging.getLogger(__name__)


@receiver(post_save, sender=User)
Expand All @@ -19,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)

0 comments on commit d830117

Please sign in to comment.