Ejemplo n.º 1
0
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)
Ejemplo n.º 2
0
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)
Ejemplo n.º 3
0
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)
Ejemplo n.º 4
0
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},
                    )
Ejemplo n.º 5
0
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})
Ejemplo n.º 6
0
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
                        }
                    )