From: Matías Aguirre Date: Tue, 23 Nov 2010 05:45:58 +0000 (-0200) Subject: Doc fix and added missing check X-Git-Url: https://git.parisson.com/?a=commitdiff_plain;h=b713dc6b02bd8c9343bd4f2b79aeb8dc3996968f;p=django-social-auth.git Doc fix and added missing check --- diff --git a/README.rst b/README.rst index ed364da..d03e320 100644 --- a/README.rst +++ b/README.rst @@ -108,7 +108,7 @@ and the methods:: 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(...) diff --git a/social_auth/models.py b/social_auth/models.py index 325f6dd..c09137a 100644 --- a/social_auth/models.py +++ b/social_auth/models.py @@ -3,15 +3,26 @@ from django.db import models 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