summaryrefslogtreecommitdiffstats
path: root/django/sp_sso/saml/forms.py
blob: dc1c583f8dbcfa068fc04a1876dffb8349c6b62f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
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


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}051', "ATTACHE D'ADMINISTRATION DE L'ETAT"),
('{NCORPS}054', 'SECRETAIRE ADMINISTRATIF'),
('{NCORPS}056', " ADJ. ADM DE L'EN ET DE L'ENS SUP "),
('{NCORPS}275', 'ASSISTANT INGENIEUR ( RECHERCHE CNRS)'),
('{NCORPS}276', "INGENIEUR D'ETUDES( RECHERCHE CNRS)"),
('{NCORPS}277', 'INGENIEUR DE RECHERCHE ( RECHERCHE CNRS)'),
('{NCORPS}278', 'ADJOINT TECHNIQUE ( RECHERCHE CNRS)'),
('{NCORPS}279', 'TECHNICIEN ( RECHERCHE CNRS)'),
('{NCORPS}300', 'PROFESSEUR DES UNIVERSITES'),
('{NCORPS}301', 'MAITRE DE CONFERENCES DES UNIVERSITES'),
('{NCORPS}305', "ASSISTANT DE L'ENSEIGNEMENT SUPERIEUR"),
('{NCORPS}310', 'PROF DES UNIV.- PRATICIEN HOSPITALIER'),
('{NCORPS}311', 'MAITRE DE CONF PRATICIEN HOSPITALIER '),
('{NCORPS}355', "DIR. D'ETUDES EPHE ENC EFEO"),
('{NCORPS}551', 'PROFESSEUR AGREGE'),
('{NCORPS}553', 'PROFESSEUR CERTIFIE'),
('{NCORPS}562', "CHARGE D'ENSEIGNEMENT HORS EPS"),
('{NCORPS}830', 'TECHNICIEN DE RECHERCHE & FORMATION(NES)'),
('{NCORPS}835', "INGENIEUR D'ETUDES (RECH ET FORM)"),
('{NCORPS}836', 'INGENIEUR DE RECHERCHE (RECH ET FORM)'),
('{NCORPS}837', 'ADJOINT TECHNIQUE DE RECH.ET FORMATION'),
('{NCORPS}839', 'ADJOINT TECHNIQUE-RECHERCHE & FORMATION'),
('{NCORPS}841', 'TECHNIQUE CONTRACTUEL CNRS')
)


ETABLISSEMENT_CHOICES = ()

UNITE_CHOICES = ()

class RegistrationForm(forms.Form):

    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)),)
                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"))
    # 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()}