From 08a47150db9fd84c30f0002619213b55db354a26 Mon Sep 17 00:00:00 2001 From: Evarin Date: Sun, 3 Jun 2018 22:26:53 +0200 Subject: [PATCH] Populate user model with promotion infos As requested by Erkan et Martin --- README.rst | 11 +++++------ allauth_ens/adapter.py | 10 ++++++++++ allauth_ens/utils.py | 1 - 3 files changed, 15 insertions(+), 7 deletions(-) diff --git a/README.rst b/README.rst index 4a06279..28914db 100644 --- a/README.rst +++ b/README.rst @@ -181,12 +181,11 @@ Configuration Auto-signup Populated data - - username: ``@`` - - email: from LDAP's *mailRoutingAddress* field, or ``@clipper.ens.fr`` - - first_name, last_name from LDAP's *cn* field - - extra_data in SocialAccount instance, containing these field, plus *annee* -and *promotion* parsed from LDAP's *homeDirectory* field (available only on -first connection) + - *username*: ``@`` + - *email*: from LDAP's *mailRoutingAddress* field, or ``@clipper.ens.fr`` + - *first_name*, *last_name* from LDAP's *cn* field + - *entrance_year* (as 2-digit string), *department_code*, *department* and *promotion* (department+year) parsed from LDAP's *homeDirectory* field + - *extra_data* in SocialAccount instance, containing all these field except *promotion* (and available only on first connection) Account deprecation At the beginning of each year (i.e. early November), to prevent clipper diff --git a/allauth_ens/adapter.py b/allauth_ens/adapter.py index 50c5d33..e85d978 100644 --- a/allauth_ens/adapter.py +++ b/allauth_ens/adapter.py @@ -100,6 +100,16 @@ class LongTermClipperAccountAdapter(DefaultSocialAccountAdapter): user_field(user, 'first_name', name_parts[0]) user_field(user, 'last_name', ' '.join(name_parts[1:])) + # Entrance year and department, if the user has these fields + entrance_year = ldap_data.get('entrance_year', '') + dep_code = ldap_data.get('department_code', '') + dep_fancy = ldap_data.get('department', '') + promotion = u'%s %s' % (dep_fancy, entrance_year) + user_field(user, 'entrance_year', entrance_year) + user_field(user, 'department_code', dep_code) + user_field(user, 'department', dep_fancy) + user_field(user, 'promotion', promotion) + # Ignore form get_account_adapter().populate_username(request, user) diff --git a/allauth_ens/utils.py b/allauth_ens/utils.py index 57df7b1..230d55d 100644 --- a/allauth_ens/utils.py +++ b/allauth_ens/utils.py @@ -49,7 +49,6 @@ def extract_infos_from_ldap(infos): annee = dirs[2] dep = dirs[3] dep_fancy = DEPARTMENTS_LIST.get(dep.lower(), '') - promotion = u'%s %s' % (dep, annee) data['entrance_year'] = annee data['department_code'] = dep data['department'] = dep_fancy