summaryrefslogtreecommitdiffstats
path: root/django/sp_sso/invite/forms.py
blob: 0736a3cb3f7452e00b09ab4e29483c4e253176e1 (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
from django.utils.translation import ugettext_lazy as _
from django import forms

from .utils import get_invitaton_attributes_mapping, get_additional_prefilled_fields


class InvitationForm(forms.Form):
    """ Used when sending invites to the Campus

    Invites are sent to the `email` field. Multiple adresses are handled if
    they are separated by a blank space ` ` character.

    This form is restricted to users having previously registered to the
    Campus ; therefore they must log in to their RENATER-federated account
    before accessing the form.
    """
    def __init__(self, *args, **kwargs):
        """
        Attributes fetched from the identity provider are used to pre-fill
        the fields.
        An extra hidden field is used to store the user's
        eduPersonPrincipalName, used as key identity attribute in the
        corresponding LDAP entry.
        """
        super(InvitationForm, self).__init__(*args, **kwargs)
        # Add a help text for sending multiple invitations
        self.fields['email'].help_text = _(
            _('Blank-separated emails if multiple adresses.'))
        # Pre-filled fields are readonly
        for prefilled_field in get_invitaton_attributes_mapping().values() + \
                get_additional_prefilled_fields():
            if  kwargs['initial'].get(prefilled_field):
                self.fields[prefilled_field].widget.attrs['readonly'] = True

    # Blank-seperated list of recipient email adresses
    email = forms.CharField(
            max_length=100,
            label=_('Email address(es) where to send an invite'))
    # Invitation message that will be sent with the invite
    message = forms.CharField(
            widget=forms.Textarea(), max_length=999,
            label=_("Invitation message"), required=False)

    # Host identity
    #  If the RENATER identity federation is used, this field will be pre-
    #  filled with the host's EPPN (EduPersonPrincalName)
    hote_identite = forms.CharField(
            max_length=100, label=_("Your RENATER identifier"))

    hote_nom = forms.CharField(
            max_length=100, label=_("Your lastname"))

    hote_prenom = forms.CharField(
            max_length=100, label=_("Your firstname"))

    hote_etablissement = forms.CharField(
            max_length=100, label=_("Your institution"))

    hote_unite = forms.CharField(
            max_length=100, label=_("Your research unit"))

    hote_courriel = forms.CharField(
            max_length=100, label=_("Your email address"))