added misc plugins towards wizards for the portal
[myslice.git] / portal / views.py
1 from portal.portalpage  import PortalPage
2 from plugins.wizard     import Wizard
3 from plugins.form       import CreateForm
4 from plugins.raw.raw    import Raw          # XXX
5
6 from myslice.viewutils  import the_user
7
8 from django.template.loader import render_to_string
9 from django.template import RequestContext
10
11 def index(request):
12
13     WIZARD_TITLE = 'User registration'
14     STEP1_TITLE  = 'Enter your details'
15     STEP2_TITLE  = 'Select your institution'
16     STEP3_TITLE  = 'Authentication'
17     STEP4_TITLE  = 'Request a slice (optional)'
18     STEP5_TITLE  = 'Waiting for validation'
19     STEP6_TITLE  = 'Account validated'
20
21     STEP0 = render_to_string('account_validated.html', context_instance=RequestContext(request))
22     STEP2_HTML   = """
23     coucou
24     """
25     STEP4 = """
26     mede
27     """
28     STEP5 = render_to_string('account_validated.html', context_instance=RequestContext(request))
29
30     p = PortalPage(request)
31
32     # This is redundant with the Wizard title
33     p << "<h3>User registration</h3>"
34
35     sons = []
36     # STEP 1
37     # If the user already exists (is logged), let's display a summary of his account details
38     # Otherwise propose a form to fill in
39     if the_user(request):
40         # Fill a disabled form with user info
41         # Please logout to register another user
42         sons.append(Raw(page=p, title=STEP1_TITLE, togglable=False, html=STEP0))
43     else:
44         # XXX This should become local:user
45         sons.append(CreateForm(page = p, title = STEP1_TITLE, togglable = False, object = 'user'))
46
47     # STEP 2
48     # If the user already exists (is logged), let's display a summary of its institution
49     # Otherwise propose a form to fill in (we should base our selection on the email)
50     if the_user(request):
51         # Fill a disabled form with institution
52         # Please logout to register another user
53         sons.append(Raw(page=p, title=STEP2_TITLE, togglable=False, html="User created"))
54     else:
55         sons.append(CreateForm(page = p, title = STEP2_TITLE, togglable = False, object = 'institution'))
56
57     # STEP3
58     # Please should your prefered authentication method
59     # This step should allow the user to either choose the user or managed mode in MySlice
60     sons.append(Raw(page = p, title = STEP3_TITLE, togglable = False, html = STEP2_HTML))
61
62     # Step 4: Request a slice (optional)
63     sons.append(CreateForm(page = p, title = STEP4_TITLE, togglable = False, object = 'slice'))
64
65     # Step 5: Your request is waiting for validation
66     # Periodic refresh
67     sons.append(Raw(page = p, title = STEP5_TITLE, togglable = False, html = STEP4))
68
69     # Step 6: Account validation  = welcome for newly validated users
70     # . delegation
71     # . platforms
72     # . slice
73     # . pointers
74     sons.append(Raw(page = p, title = STEP6_TITLE, togglable = False, html = STEP5))
75
76     wizard = Wizard(
77         page       = p,
78         title      = WIZARD_TITLE,
79         togglable  = False,
80         sons       = sons,
81         start_step = 2,
82     )
83
84     p << wizard.render(request) # in portal page if possible
85
86     return p.render()