This repository has been archived on 2023-02-21. You can view files and clone it, but cannot push or open issues or pull requests.
paul-synchro/django/sp_sso/saml/forms.py

138 lines
5.3 KiB
Python

from django.utils.translation import ugettext_lazy as _
from django import forms
from .utils import ldap_get_unites, ldap_get_etablissements, sso_attributes, \
sso_select_attributes, sso_tupled_attributes
AFFILIATION_CHOICES = (
('researcher', _('Researcher')),
('teacher', _('Teacher')),
('emeritus', _('Emeritus')),
('student', _('Student')),
('staff', _('Staff')),
('registered-reader', _('Registered-reader')),
)
AFFECTATION_CHOICES = (
('B', 'Bleue'),
('V', 'Verte'),
('J', 'Jaune'),
('N', 'Noire'),
('R', 'Rouge'),
)
EMP_CORPS_CHOICES = (
('{NCORPS}056', "ADJ. ADM DE L'EN ET DE L'ENS SUP"),
('{NCORPS}837', 'ADJOINT TECHNIQUE DE RECH.ET FORMATION'),
('{NCORPS}839', 'ADJOINT TECHNIQUE-RECHERCHE & FORMATION'),
('{NCORPS}278', 'ADJOINT TECHNIQUE ( RECHERCHE CNRS)'),
('{NCORPS}305', "ASSISTANT DE L'ENSEIGNEMENT SUPERIEUR"),
('{NCORPS}275', 'ASSISTANT INGENIEUR ( RECHERCHE CNRS)'),
('{NCORPS}051', "ATTACHE D'ADMINISTRATION DE L'ETAT"),
('{NCORPS}562', "CHARGE D'ENSEIGNEMENT HORS EPS"),
('{NCORPS}355', "DIR. D'ETUDES EPHE ENC EFEO"),
('{NCORPS}276', "INGENIEUR D'ETUDES(RECHERCHE CNRS)"),
('{NCORPS}835', "INGENIEUR D'ETUDES (RECH ET FORM)"),
('{NCORPS}836', 'INGENIEUR DE RECHERCHE (RECH ET FORM)'),
('{NCORPS}277', 'INGENIEUR DE RECHERCHE (RECHERCHE CNRS)'),
('{NCORPS}301', 'MAITRE DE CONFERENCES DES UNIVERSITES'),
('{NCORPS}311', 'MAITRE DE CONF PRATICIEN HOSPITALIER '),
('{NCORPS}310', 'PROF DES UNIV.- PRATICIEN HOSPITALIER'),
('{NCORPS}551', 'PROFESSEUR AGREGE'),
('{NCORPS}553', 'PROFESSEUR CERTIFIE'),
('{NCORPS}300', 'PROFESSEUR DES UNIVERSITES'),
('{NCORPS}054', 'SECRETAIRE ADMINISTRATIF'),
('{NCORPS}279', 'TECHNICIEN ( RECHERCHE CNRS)'),
('{NCORPS}830', 'TECHNICIEN DE RECHERCHE & FORMATION(NES)'),
('{NCORPS}841', 'TECHNIQUE CONTRACTUEL CNRS')
)
ETABLISSEMENT_CHOICES = ()
UNITE_CHOICES = ()
class RegistrationForm(forms.Form):
"""
Main registration form when requesting access to the Campus.
User data may be fetched for a single sign-on (SSO) procedure and used to
pre-fill the fields. Pre-filled fields are also set as readonly to ensure
that the data fetched from the SSO process and sent to w.c.s. is genuine.
"""
user_help_msg = ''
user_nickname = ''
def __init__(self, *args, **kwargs):
super(RegistrationForm, self).__init__(*args, **kwargs)
self.user_nickname = kwargs['initial'].get('user_nickname', '')
self.user_help_msg = kwargs['initial'].get('user_help_msg', '')
for field in sso_attributes:
if kwargs['initial'].get(field,'') != '':
if field in sso_select_attributes:
simple_choice = '%s' % kwargs['initial'][field]
self.fields[field].choices = ((simple_choice, (simple_choice)),)
if field in sso_tupled_attributes.keys():
simple_choice = '%s' % kwargs['initial'][field]
backend_dict = dict(globals().get(sso_tupled_attributes[field], {}))
if backend_dict.get(simple_choice):
self.fields[field].choices = ((simple_choice,
backend_dict.get(simple_choice)),)
self.fields[field].widget.attrs['readonly'] = True
nom = forms.CharField(max_length=100, label=_("Last name"))
prenom = forms.CharField(max_length=100, label=_("First name"))
email = forms.CharField(max_length=100, label=_("Email address"))
# Attributes from the Internet2 eduPerson and RENATER SupAnn2009 specs.
# ep_* -> eduPerson attributes:
ep_principal_name = forms.CharField(
required=False,
max_length=100,
label="eduPersonPrincipalName"
)
# eduPersonPrimaryAffiliation
ep_primary_affiliation = forms.ChoiceField(
required=False,
choices=AFFILIATION_CHOICES,
label=_("Affiliation")
)
# eduPersonPrimaryAffiliation
ep_affiliation = forms.MultipleChoiceField(
required=False, choices=AFFILIATION_CHOICES, label=_("Affiliations"))
# s_* -> supannPerson attributes:
# supannEtablissement
s_etablissement = forms.CharField(
required=False, max_length=100, label=_("Institution"))
invite_unite = forms.CharField(
required=False, label=_("Research entity or unit"), initial='')
# supannEntiteAffectationPrincipale
s_entite_affectation_principale = forms.CharField(
required=False, max_length=100, label=_("Assignment unit"))
# supannEntiteAffectation
s_entite_affectation = forms.CharField(
required=False, max_length=100, label=_("Assignment units"))
# supannEmpCorps
s_emp_corps = forms.ChoiceField(
choices=EMP_CORPS_CHOICES, label=_("Source entity"))
# supannListeRouge
s_liste_rouge = forms.BooleanField(
initial=True, required=False, label=_("Unlist contact information"))
# hote_* -> host attributes:
hote_etablissement = forms.ChoiceField(
required=False, choices=ldap_get_etablissements(),
label=_("Institution"), initial=None)
hote_unite = forms.ChoiceField(
required=False, choices=ldap_get_unites(),
label=_("Research entity or unit"), initial=None)
hote_commentaire = forms.CharField(
widget=forms.Textarea(), max_length=999,
label=_("Comments to your host"), required=False)
class Meta:
widgets= {'form' : forms.HiddenInput()}