def create_profile_callback(sender, instance, created=False, **kwargs): """Automatically create token and profile for user.""" if created: # Create API token Token.objects.create(user=instance, key=get_random_string(40)) # Create profile Profile.objects.create(user=instance) # Create subscriptions if not instance.is_anonymous: create_default_notifications(instance)
def create_profile_callback(sender, instance, created=False, **kwargs): """Automatically create token and profile for user.""" if created: # Create API token instance.auth_token = Token.objects.create( user=instance, key=get_token("wlp" if instance.is_bot else "wlu") ) # Create profile instance.profile = Profile.objects.create(user=instance) # Create subscriptions if not instance.is_anonymous: create_default_notifications(instance)
def migrate_subscriptions(apps, schema_editor): Profile = apps.get_model("accounts", "Profile") profiles = Profile.objects.all().select_related("user") profiles = profiles.exclude(user__username=settings.ANONYMOUS_USER_NAME) for profile in profiles: user = profile.user create_default_notifications(user) for flag, notifications in MAPPING: if getattr(profile, flag): for notification in notifications: user.subscription_set.get_or_create( scope=SCOPE_DEFAULT, notification=notification, defaults={"frequency": FREQ_INSTANT}, )
def migrate_subscriptions(apps, schema_editor): Profile = apps.get_model('accounts', 'Profile') profiles = Profile.objects.all().select_related('user') profiles = profiles.exclude(user__username=settings.ANONYMOUS_USER_NAME) if settings.DEMO_SERVER: profiles = profiles.exclude(user__username__in=('demo', 'review')) for profile in profiles: user = profile.user create_default_notifications(user) for flag, notifications in MAPPING: if getattr(profile, flag): for notification in notifications: user.subscription_set.get_or_create( scope=SCOPE_DEFAULT, notification=notification, defaults={'frequency': FREQ_INSTANT})
def migrate_subscriptions(apps, schema_editor): Profile = apps.get_model('accounts', 'Profile') profiles = Profile.objects.all().select_related('user') profiles = profiles.exclude( user__username=settings.ANONYMOUS_USER_NAME ) for profile in profiles: user = profile.user create_default_notifications(user) for flag, notifications in MAPPING: if getattr(profile, flag): for notification in notifications: user.subscription_set.get_or_create( scope=SCOPE_DEFAULT, notification=notification, defaults={ 'frequency': FREQ_INSTANT } )