3 from portal.portalpage import PortalPage
4 from plugins.wizard import Wizard
5 from plugins.form import CreateForm
6 from plugins.raw.raw import Raw # XXX
8 from myslice.viewutils import the_user
10 from django.template.loader import render_to_string
11 from django.template import RequestContext
12 from django.views import generic
13 from django.shortcuts import render
15 from portal.forms import RegisterUserForm
17 from django.contrib.formtools.wizard.views import NamedUrlSessionWizardView
18 #from django.core.files.storage import FileSystemStorage
19 from django.core.files.storage import default_storage
21 #class MerlinWizard(NamedUrlSessionWizardView):
27 # def as_view(cls, *args, **kwargs):
34 # 'url_name': 'merlin_wizard'
36 # return super(MerlinWizard, cls).as_view(*args, **kwargs)
38 class RegisterUserWizardView(NamedUrlSessionWizardView):
39 #class RegisterUserWizardView(LoginRequiredMixin, NamedUrlSessionWizardView):
40 # Notice that I specify a file storage instance. If you don't specify this,
41 # and you need to support FileField or ImageField in your forms, you'll get
42 # errors from Django. This is something else I think could be handled by
43 # the views better. Seems to me that it should just use whatever the
44 # default/specified storage is for the rest of your project/application.
45 file_storage = default_storage # FileSystemStorage()
46 template_name = "register_user_wizard.html"
48 def done(self, form_list, **kwargs):
49 step1_form = form_list[0]
50 step2_form = form_list[1]
52 productext = self.create_product(product_form)
53 shippings = self.create_shippings(productext, shipping_forms)
54 images = self.create_images(productext, image_forms)
56 if all([productext, shippings, images]):
57 del self.request.session["wizard_product_wizard_view"]
59 messages.success(self.request,
60 _("Your product has been created."))
61 return HttpResponseRedirect(self.get_success_url(productext))
63 messages.error(self.request, _("Something went wrong creating your "
64 "product. Please try again or contact support."))
65 return HttpResponseRedirect(reverse("register_wizard"))
67 #def get_form_kwargs(self, step):
68 # if step == "product":
69 # return {"user": self.request.user}
72 # The portal should hook the slice and user creation pages
74 def register_user(request):
76 if request.method == 'POST':
77 form = RegisterUserForm(request.POST) # Nous reprenons les données
79 first_name = form.cleaned_data['first_name']
80 last_name = form.cleaned_data['last_name']
81 email = form.cleaned_data['email']
82 password = form.cleaned_data['password']
83 password2 = form.cleaned_data['password2']
84 keypair = form.cleaned_data['keypair']
85 ## Ici nous pouvons traiter les données du formulaire
86 #sujet = form.cleaned_data['sujet']
87 #message = form.cleaned_data['message']
88 #envoyeur = form.cleaned_data['envoyeur']
89 #renvoi = form.cleaned_data['renvoi']
90 ## Nous pourrions ici envoyer l'e-mail grâce aux données que nous venons de récupérer
93 form = RegisterUserForm()
94 return render(request, 'register_user.html', locals())
98 WIZARD_TITLE = 'User registration'
99 STEP1_TITLE = 'Enter your details'
100 STEP2_TITLE = 'Select your institution'
101 STEP3_TITLE = 'Authentication'
102 STEP4_TITLE = 'Request a slice (optional)'
103 STEP5_TITLE = 'Waiting for validation'
104 STEP6_TITLE = 'Account validated'
106 STEP0 = render_to_string('account_validated.html', context_instance=RequestContext(request))
113 STEP5 = render_to_string('account_validated.html', context_instance=RequestContext(request))
115 p = PortalPage(request)
117 # This is redundant with the Wizard title
118 p << "<h3>User registration</h3>"
124 # If the user already exists (is logged), let's display a summary of his account details
125 # Otherwise propose a form to fill in
126 if the_user(request):
127 # Fill a disabled form with user info
128 # Please logout to register another user
129 sons.append(Raw(page=p, title=STEP1_TITLE, togglable=False, html=STEP0))
132 # We could pass a list of fields also, instead of retrieving them from metadata
133 # Otherwise we need some heuristics to display nice forms
134 # XXX Could we log the user in after the form is validated ?
135 # XXX Explain the password is for XXX
137 'name' : 'First name',
138 'field' : 'firstname',
140 'validate_rx' : '^[a-zA-Z -]+$',
141 'validate_err': 'Your first name must be comprised of letters only',
142 'description' : 'Enter your first name',
144 'name' : 'Last name',
145 'field' : 'lastname',
147 'validate_rx' : '^[a-zA-Z -]+$',
148 'validate_err': 'Your last name must be comprised of letters only',
149 'description' : 'Enter your last name',
154 'description' : 'Enter your email address',
157 'field' : 'password',
159 'description' : 'Enter your password',
161 'name' : 'Confirm password',
162 'field' : 'password2',
164 'description' : 'Enter your password again',
166 sons.append(CreateForm(page = p, title = STEP1_TITLE, togglable = False, object = 'local:user', fields = field_list))
169 # If the user already exists (is logged), let's display a summary of its institution
170 # Otherwise propose a form to fill in (we should base our selection on the email)
171 if the_user(request):
172 # Fill a disabled form with institution
173 # Please logout to register another user
174 sons.append(Raw(page=p, title=STEP2_TITLE, togglable=False, html="User created"))
177 sons.append(CreateForm(page = p, title = STEP2_TITLE, togglable = False, object = 'slice')) #institution'))
180 # Please should your prefered authentication method
181 # This step should allow the user to either choose the user or managed mode in MySlice
182 sons.append(Raw(page = p, title = STEP3_TITLE, togglable = False, html = STEP2_HTML))
184 # Step 4: Request a slice (optional)
185 sons.append(CreateForm(page = p, title = STEP4_TITLE, togglable = False, object = 'slice'))
187 # Step 5: Your request is waiting for validation
189 sons.append(Raw(page = p, title = STEP5_TITLE, togglable = False, html = STEP4))
191 # Step 6: Account validation = welcome for newly validated users
196 sons.append(Raw(page = p, title = STEP6_TITLE, togglable = False, html = STEP5))
200 title = WIZARD_TITLE,
203 start_step = start_step,
206 p << wizard.render(request) # in portal page if possible