Skip to content

Commit

Permalink
fix: issue with phone number lib being imported when not used, causin…
Browse files Browse the repository at this point in the history
…g crash
  • Loading branch information
dhruv committed Aug 23, 2023
1 parent 7339c3c commit a51ed39
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions two_factor/views/profile.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from django.apps.registry import apps
from django.conf import settings
from django.contrib.auth.decorators import login_required
from django.shortcuts import redirect, resolve_url
Expand Down Expand Up @@ -31,17 +32,24 @@ class ProfileView(TemplateView):
def get_context_data(self, **kwargs):
try:
backup_tokens = self.request.user.staticdevice_set.all()[0].token_set.count()

except Exception:
backup_tokens = 0

return {
context = {
'default_device': default_device(self.request.user),
'default_device_type': default_device(self.request.user).__class__.__name__,
'backup_phones': backup_phones(self.request.user),
'backup_tokens': backup_tokens,
'available_phone_methods': get_available_phone_methods()
}

if (apps.is_installed("phonenumber")):
context.update({
'backup_phones': backup_phones(self.request.user),
'phone_methods': get_available_phone_methods(),
})

return context


@class_view_decorator(never_cache)
class DisableView(FormView):
Expand Down

0 comments on commit a51ed39

Please sign in to comment.