1- from django .apps import AppConfig
1+ from django .apps import AppConfig , apps
22from django .conf import settings
33from django .test .signals import setting_changed
44
@@ -12,19 +12,21 @@ class TwoFactorPhoneNumberConfig(AppConfig):
1212 url_prefix = 'phone'
1313
1414 def ready (self ):
15- register_methods (self , None , None )
16- setting_changed .connect (register_methods )
15+ updated_registered_methods (self , None , None )
16+ setting_changed .connect (updated_registered_methods )
1717
1818
19- def register_methods (sender , setting , value , ** kwargs ):
19+ def updated_registered_methods (sender , setting , value , ** kwargs ):
2020 # This allows for dynamic registration, typically when testing.
2121 from .method import PhoneCallMethod , SMSMethod
2222
23- if getattr (settings , 'TWO_FACTOR_CALL_GATEWAY' , None ):
23+ phone_number_app_installed = apps .is_installed ('two_factor.plugins.phonenumber' )
24+
25+ if phone_number_app_installed and getattr (settings , 'TWO_FACTOR_CALL_GATEWAY' , None ):
2426 registry .register (PhoneCallMethod ())
2527 else :
2628 registry .unregister ('call' )
27- if getattr (settings , 'TWO_FACTOR_SMS_GATEWAY' , None ):
29+ if phone_number_app_installed and getattr (settings , 'TWO_FACTOR_SMS_GATEWAY' , None ):
2830 registry .register (SMSMethod ())
2931 else :
3032 registry .unregister ('sms' )
0 commit comments