Browse Source

Commments

prieto 7 years ago
parent
commit
999e65951d

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

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

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

@@ -4,6 +4,12 @@ from ...exceptions import *
4 4
 from lodel import logger
5 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 13
 def list_classes(request):
8 14
     if 'allclasses' in request.GET:
9 15
         allclasses = request.GET['allclasses']
@@ -11,6 +17,9 @@ def list_classes(request):
11 17
         allclasses = 1
12 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 23
 def show_class(request):
15 24
     if 'classname' in request.GET:
16 25
         classname = request.GET['classname']
@@ -25,6 +34,9 @@ def show_class(request):
25 34
         raise HttpException(400)
26 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 40
 def show_object(request):
29 41
     if 'classname' in request.GET:
30 42
         classname = request.GET['classname']

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

@@ -6,10 +6,19 @@ from ...client import WebUiClient as WebUiClient
6 6
 from lodel import logger
7 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 15
 def signin(request):
10 16
     msg=''
17
+    # The form send the login and password, we can authenticate the user
11 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 22
         uid=WebUiClient['__auth_user_infos']['uid']
14 23
         leoclass=WebUiClient['__auth_user_infos']['leoclass']
15 24
         query_filter=list()
@@ -18,7 +27,10 @@ def signin(request):
18 27
         return get_response('users/welcome.html', username = user[0].data('login'))
19 28
     else:
20 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 34
 def signout(request):
23 35
     WebUiClient.destroy()
24 36
     return get_response('users/signin.html')

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

@@ -11,7 +11,7 @@
11 11
   <div class="form-group">
12 12
     <label for="inputLogin" class="col-sm-2 control-label">Login</label>
13 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 15
     </div>
16 16
   </div>
17 17
   <div class="form-group">

Loading…
Cancel
Save