updated 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     start_step = 1
37
38     # STEP 1
39     # If the user already exists (is logged), let's display a summary of his account details
40     # Otherwise propose a form to fill in
41     if the_user(request):
42         # Fill a disabled form with user info
43         # Please logout to register another user
44         sons.append(Raw(page=p, title=STEP1_TITLE, togglable=False, html=STEP0))
45         start_step += 1
46     else:
47         # We could pass a list of fields also, instead of retrieving them from metadata
48         # Otherwise we need some heuristics to display nice forms
49         # XXX Could we log the user in after the form is validated ?
50         # XXX Explain the password is for XXX
51         field_list = [{
52             'name'        : 'First name',
53             'field'       : 'firstname',
54             'type'        : 'text',
55             'validate_rx' : '^[a-zA-Z -]+$',
56             'validate_err': 'Your first name must be comprised of letters only',
57             'description' : 'Enter your first name',
58         }, {
59             'name'        : 'Last name',
60             'field'       : 'lastname',
61             'type'        : 'text',
62             'validate_rx' : '^[a-zA-Z -]+$',
63             'validate_err': 'Your last name must be comprised of letters only',
64             'description' : 'Enter your last name',
65         }, { 
66             'name'        : 'Email',
67             'field'       : 'email',
68             'type'        : 'text',
69             'description' : 'Enter your email address',
70         }, {
71             'name'        : 'Password',
72             'field'       : 'password',
73             'type'        : 'password',
74             'description' : 'Enter your password',
75         }, {
76             'name'        : 'Confirm password',
77             'field'       : 'password2',
78             'type'        : 'password',
79             'description' : 'Enter your password again',
80         }]
81         sons.append(CreateForm(page = p, title = STEP1_TITLE, togglable = False, object = 'local:user', fields = field_list))
82
83     # STEP 2
84     # If the user already exists (is logged), let's display a summary of its institution
85     # Otherwise propose a form to fill in (we should base our selection on the email)
86     if the_user(request):
87         # Fill a disabled form with institution
88         # Please logout to register another user
89         sons.append(Raw(page=p, title=STEP2_TITLE, togglable=False, html="User created"))
90         start_step += 1
91     else:
92         sons.append(CreateForm(page = p, title = STEP2_TITLE, togglable = False, object = 'slice')) #institution'))
93
94     # STEP3
95     # Please should your prefered authentication method
96     # This step should allow the user to either choose the user or managed mode in MySlice
97     sons.append(Raw(page = p, title = STEP3_TITLE, togglable = False, html = STEP2_HTML))
98
99     # Step 4: Request a slice (optional)
100     sons.append(CreateForm(page = p, title = STEP4_TITLE, togglable = False, object = 'slice'))
101
102     # Step 5: Your request is waiting for validation
103     # Periodic refresh
104     sons.append(Raw(page = p, title = STEP5_TITLE, togglable = False, html = STEP4))
105
106     # Step 6: Account validation  = welcome for newly validated users
107     # . delegation
108     # . platforms
109     # . slice
110     # . pointers
111     sons.append(Raw(page = p, title = STEP6_TITLE, togglable = False, html = STEP5))
112
113     wizard = Wizard(
114         page       = p,
115         title      = WIZARD_TITLE,
116         togglable  = False,
117         sons       = sons,
118         start_step = start_step,
119     )
120
121     p << wizard.render(request) # in portal page if possible
122
123     return p.render()