POC Campus Condorcet : reecriture du gabarit de formulaire, partie 2
This commit is contained in:
parent
e42c6124fd
commit
0d9047d47b
|
@ -1,6 +1,7 @@
|
|||
from django import forms
|
||||
#from .utils import ldap_get_etablissements, ldap_get_unites
|
||||
from .utils import ldap_get_unites, ldap_get_etablissements
|
||||
from .utils import get_form_init_data
|
||||
|
||||
|
||||
AFFILIATION_CHOICES = (
|
||||
|
@ -25,6 +26,15 @@ UNITE_CHOICES = ()
|
|||
|
||||
class RegistrationForm(forms.Form):
|
||||
|
||||
user_help_msg = ""
|
||||
user_nickname = ""
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
super(RegistrationForm, self).__init__(*args, **kwargs)
|
||||
form_init_data = get_form_init_data()
|
||||
self.user_help_msg = form_init_data['user_help_msg']
|
||||
self.user_nickname = form_init_data['user_nickname']
|
||||
|
||||
nom = forms.CharField(max_length=100, label="Nom")
|
||||
prenom = forms.CharField(max_length=100, label="Prenom")
|
||||
email = forms.CharField(max_length=100, label="Courriel")
|
||||
|
|
|
@ -28,8 +28,22 @@ sso_attributes = ['prenom',
|
|||
's_entite_affectation',
|
||||
's_emp_corps',
|
||||
's_liste_rouge']
|
||||
form_init_data = {
|
||||
'user_help_msg':"Completez votre demande et validez votre demande d'inscription",
|
||||
'user_nickname':"aaa"
|
||||
}
|
||||
|
||||
def get_form_init_data():
|
||||
return form_init_data
|
||||
|
||||
def set_form_init_data(init_data):
|
||||
for key, value in init_data.items():
|
||||
form_init_data[key] = value
|
||||
|
||||
def craft_user_nickname(mellon_dict):
|
||||
prenom = mellon_dict.get('prenom')[0]
|
||||
nom = mellon_dict.get('nom')[0]
|
||||
return " "+prenom+" "+nom
|
||||
|
||||
def ldap_init():
|
||||
# The server's hostname:
|
||||
|
|
|
@ -2,7 +2,9 @@ from django.views.generic import FormView
|
|||
from django.shortcuts import render
|
||||
|
||||
from .forms import RegistrationForm
|
||||
from .utils import ldap_contains_user, wcs_submit, sso_attributes
|
||||
from .utils import ldap_contains_user, wcs_submit, \
|
||||
sso_attributes, set_form_init_data, \
|
||||
craft_user_nickname
|
||||
|
||||
|
||||
# TODOs
|
||||
|
@ -36,6 +38,15 @@ class RegistrationFormView(FormView):
|
|||
template_name = 'registration_form.html'
|
||||
success_url = '/register/wcs_post' # Mandatory?
|
||||
|
||||
|
||||
def dispatch(self, request, *args, **kwargs):
|
||||
if 'mellon_session' in request.session:
|
||||
set_form_init_data({'user_help_msg':
|
||||
"Confirmez les elements ci-dessous, completez votre demande et validez votre demande d'inscription",
|
||||
'user_nickname':
|
||||
craft_user_nickname(request.session['mellon_session'])})
|
||||
return super(RegistrationFormView, self).dispatch(request, *args, **kwargs)
|
||||
|
||||
def get_initial(self):
|
||||
initial = super(RegistrationFormView, self).get_initial()
|
||||
|
||||
|
@ -43,6 +54,7 @@ class RegistrationFormView(FormView):
|
|||
for attribute in sso_attributes:
|
||||
attribute_element = self.request.session['mellon_session'].get(attribute, [''])[0]
|
||||
initial[attribute] = str(attribute_element)
|
||||
initial['user_help_msg'] = 'foo'
|
||||
return initial
|
||||
|
||||
def form_valid(self, form):
|
||||
|
|
|
@ -2,8 +2,8 @@
|
|||
|
||||
{% block content %}
|
||||
|
||||
Bonjour<br>
|
||||
Veuillez confirmer votre identite et mentionner votre unite d'affectation.<br><br>
|
||||
Bonjour {{ form.user_nickname }}<br>
|
||||
{{ form.user_help_msg }} <br><br>
|
||||
|
||||
<form action="{% url "register" %}" method="post">
|
||||
{% csrf_token %}
|
||||
|
|
Reference in New Issue