is_authenticated()
AttributeError will be raised in case of any of these is
-missing, also the following are recommended but notenforced::
+missing, also the following are recommended but not enforced::
first_name = CharField(...)
last_name = CharField(...)
from django.conf import settings
# If User class is overrided, it must provide the following fields:
+#
# username = CharField()
# email = EmailField()
# password = CharField()
+# is_active = BooleanField()
+#
+# and methods:
+#
+# def is_authenticated():
+# ...
MANDATORY_FIELDS = ('username', 'email', 'password', 'last_login')
+MANDATORY_METHODS = ('is_authenticated',)
try: # try to import User model override and validate needed fields
User = models.get_model(*settings.SOCIAL_AUTH_USER_MODEL.split('.'))
if not all(User._meta.get_field(name) for name in MANDATORY_FIELDS):
raise AttributeError, 'Some mandatory field missing'
+ if not all(callable(getattr(User, name, None))
+ for name in MANDATORY_METHODS):
+ raise AttributeError, 'Some mandatory methods missing'
except: # fail silently and fallback to auth.User on any error
from django.contrib.auth.models import User