Browse Source

Commments

prieto 8 years ago
parent
commit
999e65951d

+ 71
- 9
plugins/webui/interface/controllers/admin.py View File

1
+# -*- coding: utf-8 -*-
1
 from ...exceptions import *
2
 from ...exceptions import *
2
 from .base import get_response
3
 from .base import get_response
3
 
4
 
8
 import leapi_dyncode as dyncode
9
 import leapi_dyncode as dyncode
9
 import warnings
10
 import warnings
10
 
11
 
12
+##@brief These functions are called by the rules defined in ../urls.py
13
+## To administrate the instance of the editorial model
14
+
15
+##@brief Controller's function to redirect on the home page of the admin 
16
+# @param request : the request (get or post)
17
+# @note the response is given in a html page called in get_response_function
11
 def index_admin(request):
18
 def index_admin(request):
19
+    # We have to be identified to admin the instance
20
+    # temporary, the acl will be more restrictive 
12
     if WebUiClient.is_anonymous():
21
     if WebUiClient.is_anonymous():
13
         return get_response('users/signin.html')
22
         return get_response('users/signin.html')
14
     return get_response('admin/admin.html')
23
     return get_response('admin/admin.html')
15
 
24
 
25
+##@brief Controller's function to update an object of the editorial model 
26
+# @param request : the request (get or post)
27
+# @note the response is given in a html page (in templates/admin) called in get_response_function
16
 def admin_update(request):
28
 def admin_update(request):
29
+    # We have to be identified to admin the instance
30
+    # temporary, the acl will be more restrictive
17
     if WebUiClient.is_anonymous():
31
     if WebUiClient.is_anonymous():
18
         return get_response('users/signin.html')
32
         return get_response('users/signin.html')
19
     msg=''
33
     msg=''
34
+    
35
+    # If the form has been submitted
20
     if request.method == 'POST':
36
     if request.method == 'POST':
21
         error = None
37
         error = None
22
         datas = list()
38
         datas = list()
29
             classname = None
45
             classname = None
30
         if classname is None or target_leo.is_abstract():
46
         if classname is None or target_leo.is_abstract():
31
             raise HttpException(400)
47
             raise HttpException(400)
32
-        fieldnames = target_leo.fieldnames()
33
 
48
 
34
         uid_field = target_leo.uid_fieldname()[0]
49
         uid_field = target_leo.uid_fieldname()[0]
35
         fields = dict()
50
         fields = dict()
36
 
51
 
37
         for in_put, in_value in request.form.items():
52
         for in_put, in_value in request.form.items():
53
+            # The classname is handled by the datasource, we are not allowed to modify it
54
+            # uid is not a fieldname
55
+            # both are hidden in the form, to identify the object here
38
             if in_put != 'classname' and  in_put != 'uid':
56
             if in_put != 'classname' and  in_put != 'uid':
39
                 dhl = target_leo.data_handler(in_put[12:])
57
                 dhl = target_leo.data_handler(in_put[12:])
58
+                # Here, in case of a Reference we transform the str 
59
+                # given by the form in a iterable (a list) 
40
                 if dhl.is_reference() and in_value != '':
60
                 if dhl.is_reference() and in_value != '':
41
                     in_value.replace(" ","")
61
                     in_value.replace(" ","")
42
                     in_value=in_value.split(',')
62
                     in_value=in_value.split(',')
44
                 if in_value != '':
64
                 if in_value != '':
45
                     fields[in_put[12:]] = in_value
65
                     fields[in_put[12:]] = in_value
46
 
66
 
67
+        # We retrieve the object to update
47
         filter_q = '%s = %s' % (uid_field, uid)
68
         filter_q = '%s = %s' % (uid_field, uid)
48
         obj = (target_leo.get((filter_q)))[0]
69
         obj = (target_leo.get((filter_q)))[0]
49
-
70
+        
71
+        # and update it
50
         inserted = obj.update(fields)
72
         inserted = obj.update(fields)
51
         
73
         
52
         if inserted==1:
74
         if inserted==1:
55
             msg = 'Oops something wrong happened...object not saved'
77
             msg = 'Oops something wrong happened...object not saved'
56
         return get_response('admin/admin_edit.html', target=target_leo, uidfield = uid_field, lodel_id = uid, msg = msg)
78
         return get_response('admin/admin_edit.html', target=target_leo, uidfield = uid_field, lodel_id = uid, msg = msg)
57
 
79
 
80
+    # Display of the form with the object's values to be updated
58
     if 'classname' in request.GET:
81
     if 'classname' in request.GET:
82
+        # We need the class of the object to update
59
         classname = request.GET['classname']
83
         classname = request.GET['classname']
60
         if len(classname) > 1:
84
         if len(classname) > 1:
61
             raise HttpException(400)
85
             raise HttpException(400)
67
             raise HttpException(400)
91
             raise HttpException(400)
68
         logger.warning('Composed uids broken here')
92
         logger.warning('Composed uids broken here')
69
         uid_field = target_leo.uid_fieldname()[0]
93
         uid_field = target_leo.uid_fieldname()[0]
70
-
94
+    
95
+    # We need the uid of the object
71
     test_valid = 'lodel_id' in request.GET \
96
     test_valid = 'lodel_id' in request.GET \
72
         and len(request.GET['lodel_id']) == 1
97
         and len(request.GET['lodel_id']) == 1
73
 
98
 
74
     if test_valid:
99
     if test_valid:
75
         try:
100
         try:
76
             dh = target_leo.field(uid_field)
101
             dh = target_leo.field(uid_field)
102
+            # we cast the uid extrated form the request to the adequate type
103
+            # given by the datahandler of the uidfield's datahandler
77
             lodel_id = dh.cast_type(request.GET['lodel_id'][0])
104
             lodel_id = dh.cast_type(request.GET['lodel_id'][0])
78
         except (ValueError, TypeError):
105
         except (ValueError, TypeError):
79
             test_valid = False
106
             test_valid = False
81
     if not test_valid:
108
     if not test_valid:
82
         raise HttpException(400)
109
         raise HttpException(400)
83
     else:
110
     else:
111
+        # Check if the object actually exists
112
+        # We get it from the database
84
         query_filters = list()
113
         query_filters = list()
85
         query_filters.append((uid_field,'=',lodel_id))
114
         query_filters.append((uid_field,'=',lodel_id))
86
         obj = target_leo.get(query_filters)
115
         obj = target_leo.get(query_filters)
88
             raise HttpException(404)
117
             raise HttpException(404)
89
     return get_response('admin/admin_edit.html', target=target_leo, lodel_id =lodel_id)
118
     return get_response('admin/admin_edit.html', target=target_leo, lodel_id =lodel_id)
90
 
119
 
120
+##@brief Controller's function to create an object of the editorial model 
121
+# @param request : the request (get or post)
122
+# @note the response is given in a html page (in templates/admin) called in get_response_function
91
 def admin_create(request):
123
 def admin_create(request):
124
+    # We have to be identified to admin the instance
125
+    # temporary, the acl will be more restrictive
92
     if WebUiClient.is_anonymous():
126
     if WebUiClient.is_anonymous():
93
         return get_response('users/signin.html')
127
         return get_response('users/signin.html')
94
     classname = None
128
     classname = None
95
-
129
+     # If the form has been submitted
96
     if request.method == 'POST':
130
     if request.method == 'POST':
97
         error = None
131
         error = None
98
         datas = list()
132
         datas = list()
107
         fields = dict()
141
         fields = dict()
108
 
142
 
109
         for in_put, in_value in request.form.items():
143
         for in_put, in_value in request.form.items():
144
+            # The classname is handled by the datasource, we are not allowed to modify it
145
+            # uid is not a fieldname
146
+            # both are hidden in the form, to identify the object here
110
             if in_put != 'classname' and in_value != '':
147
             if in_put != 'classname' and in_value != '':
111
                 fields[in_put[12:]] = in_value
148
                 fields[in_put[12:]] = in_value
112
-
149
+        
150
+        # Insertion in the database of the values corresponding to a new object
113
         new_uid = target_leo.insert(fields)
151
         new_uid = target_leo.insert(fields)
114
         
152
         
153
+        # reurn to the form with a confirmation or error message
115
         if not new_uid is None:
154
         if not new_uid is None:
116
             msg = 'Successfull creation';
155
             msg = 'Successfull creation';
117
         else:
156
         else:
118
             msg = 'Oops something wrong happened...object not saved'
157
             msg = 'Oops something wrong happened...object not saved'
119
         return get_response('admin/admin_create.html', target=target_leo, msg = msg)
158
         return get_response('admin/admin_create.html', target=target_leo, msg = msg)
120
     
159
     
160
+    # Display of an empty form
121
     if 'classname' in request.GET:
161
     if 'classname' in request.GET:
162
+        # We need the class to create an object in
122
         classname = request.GET['classname']
163
         classname = request.GET['classname']
123
         if len(classname) > 1:
164
         if len(classname) > 1:
124
             raise HttpException(400)
165
             raise HttpException(400)
127
             target_leo = dyncode.Object.name2class(classname)
168
             target_leo = dyncode.Object.name2class(classname)
128
         except LeApiError:
169
         except LeApiError:
129
             classname = None
170
             classname = None
130
-    msg = None
131
-    if 'msg' in request.GET:
132
-        msg = request.GET['msg']
171
+
133
     if classname is None or target_leo.is_abstract():
172
     if classname is None or target_leo.is_abstract():
134
         raise HttpException(400)
173
         raise HttpException(400)
135
     return get_response('admin/admin_create.html', target=target_leo)
174
     return get_response('admin/admin_create.html', target=target_leo)
136
 
175
 
176
+##@brief Controller's function to delete an object of the editorial model 
177
+# @param request : the request (get)
178
+# @note the response is given in a html page (in templates/admin) called in get_response_function
137
 def admin_delete(request):
179
 def admin_delete(request):
180
+    # We have to be identified to admin the instance
181
+    # temporary, the acl will be more restrictive
138
     if WebUiClient.is_anonymous():
182
     if WebUiClient.is_anonymous():
139
         return get_response('users/signin.html')
183
         return get_response('users/signin.html')
140
     classname = None
184
     classname = None
141
 
185
 
142
     if 'classname' in request.GET:
186
     if 'classname' in request.GET:
187
+        # We need the class to delete an object in
143
         classname = request.GET['classname']
188
         classname = request.GET['classname']
144
         if len(classname) > 1:
189
         if len(classname) > 1:
145
             raise HttpException(400)
190
             raise HttpException(400)
151
             raise HttpException(400)
196
             raise HttpException(400)
152
         logger.warning('Composed uids broken here')
197
         logger.warning('Composed uids broken here')
153
         uid_field = target_leo.uid_fieldname()[0]
198
         uid_field = target_leo.uid_fieldname()[0]
154
-
199
+        
200
+    # We also need the uid of the object to delete
155
     test_valid = 'lodel_id' in request.GET \
201
     test_valid = 'lodel_id' in request.GET \
156
         and len(request.GET['lodel_id']) == 1
202
         and len(request.GET['lodel_id']) == 1
157
 
203
 
158
     if test_valid:
204
     if test_valid:
159
         try:
205
         try:
160
             dh = target_leo.field(uid_field)
206
             dh = target_leo.field(uid_field)
207
+            # we cast the uid extrated form the request to the adequate type
208
+            # given by the datahandler of the uidfield's datahandler
161
             lodel_id = dh.cast_type(request.GET['lodel_id'][0])
209
             lodel_id = dh.cast_type(request.GET['lodel_id'][0])
162
         except (ValueError, TypeError):
210
         except (ValueError, TypeError):
163
             test_valid = False
211
             test_valid = False
179
         
227
         
180
         
228
         
181
 def admin_classes(request):
229
 def admin_classes(request):
230
+    # We have to be identified to admin the instance
231
+    # temporary, the acl will be more restrictive
182
     if WebUiClient.is_anonymous():
232
     if WebUiClient.is_anonymous():
183
         return get_response('users/signin.html')
233
         return get_response('users/signin.html')
184
     return get_response('admin/list_classes_admin.html', my_classes = dyncode.dynclasses)
234
     return get_response('admin/list_classes_admin.html', my_classes = dyncode.dynclasses)
185
 
235
 
186
 def create_object(request):
236
 def create_object(request):
237
+    # We have to be identified to admin the instance
238
+    # temporary, the acl will be more restrictive
187
     if WebUiClient.is_anonymous():
239
     if WebUiClient.is_anonymous():
188
         return get_response('users/signin.html')
240
         return get_response('users/signin.html')
189
     return get_response('admin/list_classes_create.html', my_classes = dyncode.dynclasses)
241
     return get_response('admin/list_classes_create.html', my_classes = dyncode.dynclasses)
190
 
242
 
191
 def delete_object(request):
243
 def delete_object(request):
244
+    # We have to be identified to admin the instance
245
+    # temporary, the acl will be more restrictive
192
     if WebUiClient.is_anonymous():
246
     if WebUiClient.is_anonymous():
193
         return get_response('users/signin.html')
247
         return get_response('users/signin.html')
194
     return get_response('admin/list_classes_delete.html', my_classes = dyncode.dynclasses)
248
     return get_response('admin/list_classes_delete.html', my_classes = dyncode.dynclasses)
195
     
249
     
196
 def admin_class(request):
250
 def admin_class(request):
251
+    # We have to be identified to admin the instance
252
+    # temporary, the acl will be more restrictive
197
     if WebUiClient.is_anonymous():
253
     if WebUiClient.is_anonymous():
198
         return get_response('users/signin.html')
254
         return get_response('users/signin.html')
255
+    # We need the class we'll list to select the object to edit
199
     if 'classname' in request.GET:
256
     if 'classname' in request.GET:
200
         classname = request.GET['classname']
257
         classname = request.GET['classname']
201
         if len(classname) > 1:
258
         if len(classname) > 1:
210
     return get_response('admin/show_class_admin.html', target=target_leo)
267
     return get_response('admin/show_class_admin.html', target=target_leo)
211
 
268
 
212
 def delete_in_class(request):
269
 def delete_in_class(request):
270
+    # We have to be identified to admin the instance
271
+    # temporary, the acl will be more restrictive
213
     if WebUiClient.is_anonymous():
272
     if WebUiClient.is_anonymous():
214
         return get_response('users/signin.html')
273
         return get_response('users/signin.html')
274
+    # We need the class we'll list to select the object to delete
215
     if 'classname' in request.GET:
275
     if 'classname' in request.GET:
216
         classname = request.GET['classname']
276
         classname = request.GET['classname']
217
         if len(classname) > 1:
277
         if len(classname) > 1:
226
     return get_response('admin/show_class_delete.html', target=target_leo)
286
     return get_response('admin/show_class_delete.html', target=target_leo)
227
 
287
 
228
 def admin(request):
288
 def admin(request):
289
+    # We have to be identified to admin the instance
290
+    # temporary, the acl will be more restrictive
229
     if WebUiClient.is_anonymous():
291
     if WebUiClient.is_anonymous():
230
         return get_response('users/signin.html')
292
         return get_response('users/signin.html')
231
     return get_response('admin/admin.html')
293
     return get_response('admin/admin.html')

+ 12
- 0
plugins/webui/interface/controllers/listing.py View File

4
 from lodel import logger
4
 from lodel import logger
5
 import leapi_dyncode as dyncode
5
 import leapi_dyncode as dyncode
6
 
6
 
7
+##@brief These functions are called by the rules defined in ../urls.py
8
+## To browse the editorial model
9
+
10
+##@brief Controller's function to list all types (classes) of the editorial model
11
+# @param request : the request (get or post)
12
+# @note the response is given in a html page called in get_response_function
7
 def list_classes(request):
13
 def list_classes(request):
8
     if 'allclasses' in request.GET:
14
     if 'allclasses' in request.GET:
9
         allclasses = request.GET['allclasses']
15
         allclasses = request.GET['allclasses']
11
         allclasses = 1
17
         allclasses = 1
12
     return get_response('listing/list_classes.html', my_classes=dyncode.dynclasses, allclasses = allclasses)
18
     return get_response('listing/list_classes.html', my_classes=dyncode.dynclasses, allclasses = allclasses)
13
 
19
 
20
+##@brief Controller's function to display a type (class) of the editorial model
21
+# @param request : the request (get or post)
22
+# @note the response is given in a html page called in get_response_function
14
 def show_class(request):
23
 def show_class(request):
15
     if 'classname' in request.GET:
24
     if 'classname' in request.GET:
16
         classname = request.GET['classname']
25
         classname = request.GET['classname']
25
         raise HttpException(400)
34
         raise HttpException(400)
26
     return get_response('listing/show_class.html', classname=classname)
35
     return get_response('listing/show_class.html', classname=classname)
27
 
36
 
37
+##@brief Controller's function to display an instance or a certain type
38
+# @param request : the request (get or post)
39
+# @note the response is given in a html page called in get_response_function
28
 def show_object(request):
40
 def show_object(request):
29
     if 'classname' in request.GET:
41
     if 'classname' in request.GET:
30
         classname = request.GET['classname']
42
         classname = request.GET['classname']

+ 14
- 2
plugins/webui/interface/controllers/users.py View File

6
 from lodel import logger
6
 from lodel import logger
7
 import leapi_dyncode as dyncode
7
 import leapi_dyncode as dyncode
8
 
8
 
9
+##@brief These functions are called by the rules defined in ../urls.py
10
+## Their goal is to handle the user authentication
11
+
12
+##@brief Controller's function to login a user, the corresponding form is in interface/users
13
+# @param request : the request (get or post)
14
+# @note the response is given in a html page called in get_response_function
9
 def signin(request):
15
 def signin(request):
10
     msg=''
16
     msg=''
17
+    # The form send the login and password, we can authenticate the user
11
     if request.method == 'POST':
18
     if request.method == 'POST':
12
-        WebUiClient.authenticate(request.form['inputLogin'], request.form['inputPassword'])
19
+        login = request.form['inputLogin']
20
+        WebUiClient.authenticate(login, request.form['inputPassword'])
21
+        # We get the informations about the user
13
         uid=WebUiClient['__auth_user_infos']['uid']
22
         uid=WebUiClient['__auth_user_infos']['uid']
14
         leoclass=WebUiClient['__auth_user_infos']['leoclass']
23
         leoclass=WebUiClient['__auth_user_infos']['leoclass']
15
         query_filter=list()
24
         query_filter=list()
18
         return get_response('users/welcome.html', username = user[0].data('login'))
27
         return get_response('users/welcome.html', username = user[0].data('login'))
19
     else:
28
     else:
20
         return get_response('users/signin.html')
29
         return get_response('users/signin.html')
21
-
30
+    
31
+##@brief Controller's function to logout a user
32
+# @param request : the request (get or post)
33
+# @note the response is given in the login html page 
22
 def signout(request):
34
 def signout(request):
23
     WebUiClient.destroy()
35
     WebUiClient.destroy()
24
     return get_response('users/signin.html')
36
     return get_response('users/signin.html')

+ 1
- 1
plugins/webui/templates/users/signin.html View File

11
   <div class="form-group">
11
   <div class="form-group">
12
     <label for="inputLogin" class="col-sm-2 control-label">Login</label>
12
     <label for="inputLogin" class="col-sm-2 control-label">Login</label>
13
     <div class="col-xs-4">
13
     <div class="col-xs-4">
14
-      <input type="text" class="form-control" id="inputLogin" name="inputLogin" placeholder="Login">
14
+      <input type="text" class="form-control" id="inputLogin" name="inputLogin" placeholder="Login" required>
15
     </div>
15
     </div>
16
   </div>
16
   </div>
17
   <div class="form-group">
17
   <div class="form-group">

Loading…
Cancel
Save