Skip to content

Commit

Permalink
refactor(socialaccount): Remove registry loading magic at import time
Browse files Browse the repository at this point in the history
  • Loading branch information
pennersr committed Mar 8, 2024
1 parent b165d5e commit 13ad1ce
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 6 deletions.
10 changes: 8 additions & 2 deletions allauth/socialaccount/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@

from allauth import app_settings
from allauth.account.adapter import get_adapter

from .models import SocialAccount, SocialApp, SocialToken
from allauth.socialaccount import providers
from allauth.socialaccount.models import SocialAccount, SocialApp, SocialToken


class SocialAppForm(forms.ModelForm):
Expand All @@ -17,6 +17,12 @@ class Meta:
"secret": forms.TextInput(attrs={"size": "100"}),
}

def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.fields["provider"] = forms.ChoiceField(
choices=providers.registry.as_choices()
)


class SocialAppAdmin(admin.ModelAdmin):
form = SocialAppForm
Expand Down
5 changes: 5 additions & 0 deletions allauth/socialaccount/apps.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,8 @@ class SocialAccountConfig(AppConfig):
name = "allauth.socialaccount"
verbose_name = _("Social Accounts")
default_auto_field = app_settings.DEFAULT_AUTO_FIELD or "django.db.models.AutoField"

def ready(self):
from allauth.socialaccount.providers import registry

registry.load()
3 changes: 0 additions & 3 deletions allauth/socialaccount/migrations/0001_initial.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
from django.db import migrations, models

from allauth import app_settings
from allauth.socialaccount.providers import registry


class Migration(migrations.Migration):
Expand Down Expand Up @@ -37,7 +36,6 @@ class Migration(migrations.Migration):
models.CharField(
max_length=30,
verbose_name="provider",
choices=registry.as_choices(),
),
),
(
Expand Down Expand Up @@ -91,7 +89,6 @@ class Migration(migrations.Migration):
models.CharField(
max_length=30,
verbose_name="provider",
choices=registry.as_choices(),
),
),
("name", models.CharField(max_length=40, verbose_name="name")),
Expand Down
1 change: 0 additions & 1 deletion allauth/socialaccount/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ class SocialApp(models.Model):
provider = models.CharField(
verbose_name=_("provider"),
max_length=30,
choices=providers.registry.as_choices(),
)
# For providers that support subproviders, such as OpenID Connect and SAML,
# this ID identifies that instance. SocialAccount's originating from app
Expand Down

0 comments on commit 13ad1ce

Please sign in to comment.