-
Notifications
You must be signed in to change notification settings - Fork 8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Adding a fast sign-in with google #66
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,11 +22,22 @@ def __init__(self, general_model, admin_site): | |
super(ListAdminMixin, self).__init__(general_model, admin_site) | ||
|
||
|
||
def is_related_to_social_signing(suspected_model): | ||
return ( | ||
suspected_model._meta.model.__name__ == "Site" | ||
or suspected_model._meta.model.__name__ == "EmailAddress" | ||
or suspected_model._meta.model.__name__ == "SocialApp" | ||
or suspected_model._meta.model.__name__ == "SocialToken" | ||
or suspected_model._meta.model.__name__ == "SocialAccount" | ||
) | ||
|
||
|
||
# Register all other models automatically - should stay last in file. | ||
models = apps.get_models() | ||
for model in models: | ||
admin_class = type('AdminClass', (ListAdminMixin, admin.ModelAdmin), {}) | ||
try: | ||
admin.site.register(model, admin_class) | ||
except admin.sites.AlreadyRegistered: | ||
pass | ||
if not is_related_to_social_signing(model): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is not clear to me, Does the app could run both? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. no, It's somehow registered automatically, so In order to avoid conflicts of registering twice I used this bad solution, but If it makes too much trouble we can give up on this PR, the other mentors have told me it's not a great idea There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sorry, i was asking misleading question, There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @Yarboa sorry I'm still not entirely understand your question, what do you mean by 'social media is set in admin'? I wasn't setting anything since Django is registering the social media models related to OAuth2 of google, and these specific models are making trouble with the auto-model registration code since it's trying to register the models again. I don't think I can give up on those settings (and this is what generates these social media models of Django), I followed a tutorial so I believe every setting is crucial, and Django is having a very specific way to do so, as I read from several sources. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There is pip install of django-allauth This is default user, no option to work with non allauth.urls? Ok looking here https://django- Signup of both local and social accounts, did you check that you can login local? How do you plan to test this feature? NOTE: I suggest to describe better in the comment what are the capabilities, |
||
try: | ||
admin.site.register(model, admin_class) | ||
except admin.sites.AlreadyRegistered: | ||
pass |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a bad solution but I couldn't find any other solution to exclude these models relates to the 'sites' and 'all-auth' models of Django (since there is an auto-registration of those models and then I kept getting the Already registered exception)- please give me your input here - @EdDev @guy9050 @Yarboa
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you please elaborate more what the problem is and how does this function solve it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The automation of the model registration suppose to register to admin only models that haven't been registered already, regarding the 4, 5 models provided by Django that are allowing social account logins (like google sign in) are already registered by Django and then the code tries to register it although it already has been registered, and this causes an exception. I couldn't find a solution so I enforced the automation part to avoid registering the 4, 5 problematic models that have been registered by Django to avoid the problem using an ugly if statement that assuring the model that is registered is not one of these problematic ones (it might have something to do with the fact the social account models are registered differently because it happened automatically after adding the new settings to support social login)