Browse Source

Changes in the interface - adding delete option

prieto 8 years ago
parent
commit
500b75d86c

+ 73
- 4
plugins/webui/interface/controllers/admin.py View File

36
 
36
 
37
         for in_put, in_value in request.form.items():
37
         for in_put, in_value in request.form.items():
38
             if in_put != 'classname' and  in_put != 'uid':
38
             if in_put != 'classname' and  in_put != 'uid':
39
-                fields[in_put[12:]] = in_value
40
-            #elif in_put == 'classname':
41
-            #    fields['classname'] = in_value
39
+                dhl = target_leo.data_handler(in_put[12:])
40
+                if dhl.is_reference() and in_value != '':
41
+                    in_value.replace(" ","")
42
+                    in_value=in_value.split(',')
43
+                    in_value=list(in_value)
44
+                if in_value != '':
45
+                    fields[in_put[12:]] = in_value
42
 
46
 
43
         filter_q = '%s = %s' % (uid_field, uid)
47
         filter_q = '%s = %s' % (uid_field, uid)
44
         obj = (target_leo.get((filter_q)))[0]
48
         obj = (target_leo.get((filter_q)))[0]
130
         raise HttpException(400)
134
         raise HttpException(400)
131
     return get_response('admin/admin_create.html', target=target_leo)
135
     return get_response('admin/admin_create.html', target=target_leo)
132
 
136
 
137
+def admin_delete(request):
138
+    if WebUiClient.is_anonymous():
139
+        return get_response('users/signin.html')
140
+    classname = None
141
+
142
+    if 'classname' in request.GET:
143
+        classname = request.GET['classname']
144
+        if len(classname) > 1:
145
+            raise HttpException(400)
146
+        classname = classname[0]
147
+        try:
148
+            target_leo = dyncode.Object.name2class(classname)
149
+        except LeApiError:
150
+            # classname = None
151
+            raise HttpException(400)
152
+        logger.warning('Composed uids broken here')
153
+        uid_field = target_leo.uid_fieldname()[0]
154
+
155
+    test_valid = 'lodel_id' in request.GET \
156
+        and len(request.GET['lodel_id']) == 1
157
+
158
+    if test_valid:
159
+        try:
160
+            dh = target_leo.field(uid_field)
161
+            lodel_id = dh.cast_type(request.GET['lodel_id'][0])
162
+        except (ValueError, TypeError):
163
+            test_valid = False
164
+
165
+    if not test_valid:
166
+        raise HttpException(400)
167
+    else:
168
+        query_filters = list()
169
+        query_filters.append((uid_field,'=',lodel_id))
170
+        nb_deleted = target_leo.delete_bundle(query_filters)
171
+
172
+    if nb_deleted == 1:
173
+            msg = 'Object successfully deleted';
174
+    else:
175
+            msg = 'Oops something wrong happened...object still here'
176
+            
177
+    return get_response('admin/admin_delete.html', target=target_leo, lodel_id =lodel_id, msg = msg)
178
+
179
+        
180
+        
133
 def admin_classes(request):
181
 def admin_classes(request):
134
     if WebUiClient.is_anonymous():
182
     if WebUiClient.is_anonymous():
135
         return get_response('users/signin.html')
183
         return get_response('users/signin.html')
139
     if WebUiClient.is_anonymous():
187
     if WebUiClient.is_anonymous():
140
         return get_response('users/signin.html')
188
         return get_response('users/signin.html')
141
     return get_response('admin/list_classes_create.html', my_classes = dyncode.dynclasses)
189
     return get_response('admin/list_classes_create.html', my_classes = dyncode.dynclasses)
190
+
191
+def delete_object(request):
192
+    if WebUiClient.is_anonymous():
193
+        return get_response('users/signin.html')
194
+    return get_response('admin/list_classes_delete.html', my_classes = dyncode.dynclasses)
142
     
195
     
143
 def admin_class(request):
196
 def admin_class(request):
144
     if WebUiClient.is_anonymous():
197
     if WebUiClient.is_anonymous():
155
     if classname is None or target_leo.is_abstract():
208
     if classname is None or target_leo.is_abstract():
156
         raise HttpException(400)
209
         raise HttpException(400)
157
     return get_response('admin/show_class_admin.html', target=target_leo)
210
     return get_response('admin/show_class_admin.html', target=target_leo)
158
-   
211
+
212
+def delete_in_class(request):
213
+    if WebUiClient.is_anonymous():
214
+        return get_response('users/signin.html')
215
+    if 'classname' in request.GET:
216
+        classname = request.GET['classname']
217
+        if len(classname) > 1:
218
+            raise HttpException(400)
219
+        classname = classname[0]
220
+        try:
221
+            target_leo = dyncode.Object.name2class(classname)
222
+        except LeApiError:
223
+            classname = None
224
+    if classname is None or target_leo.is_abstract():
225
+        raise HttpException(400)
226
+    return get_response('admin/show_class_delete.html', target=target_leo)
227
+
159
 def admin(request):
228
 def admin(request):
160
     if WebUiClient.is_anonymous():
229
     if WebUiClient.is_anonymous():
161
         return get_response('users/signin.html')
230
         return get_response('users/signin.html')

+ 3
- 0
plugins/webui/interface/urls.py View File

6
     (r'^/admin/?$', admin),
6
     (r'^/admin/?$', admin),
7
     (r'^/admin/create$', admin_create),
7
     (r'^/admin/create$', admin_create),
8
     (r'^/admin/update$', admin_update),
8
     (r'^/admin/update$', admin_update),
9
+    (r'^/admin/delete$', admin_delete),
9
     (r'^/admin/classes_admin', admin_classes),
10
     (r'^/admin/classes_admin', admin_classes),
10
     (r'^/admin/object_create', create_object),
11
     (r'^/admin/object_create', create_object),
12
+    (r'^/admin/object_delete', delete_object),
11
     (r'^/admin/class_admin$', admin_class),
13
     (r'^/admin/class_admin$', admin_class),
14
+    (r'^/admin/class_delete$', delete_in_class),
12
     (r'/test/(?P<id>.*)$', test),
15
     (r'/test/(?P<id>.*)$', test),
13
     (r'^/test/?$', test),
16
     (r'^/test/?$', test),
14
     (r'^/list_classes', list_classes),
17
     (r'^/list_classes', list_classes),

+ 3
- 2
plugins/webui/templates/admin/admin.html View File

6
 </ol>
6
 </ol>
7
 <h1 class="h1_lodel">{{settings.sitename}} administration</h1>
7
 <h1 class="h1_lodel">{{settings.sitename}} administration</h1>
8
 <ul>
8
 <ul>
9
-    <li><a href="admin/classes_admin">Edit object</a></li>
10
-    <li><a href="admin/object_create">Create object</a></li>
9
+    <li><a href="admin/classes_admin">Edit an object</a></li>
10
+    <li><a href="admin/object_create">Create an object</a></li>
11
+    <li><a href="admin/object_delete">Delete an object</a></li>
11
 </ul>
12
 </ul>
12
 
13
 
13
 {% endblock %}
14
 {% endblock %}

+ 4
- 1
plugins/webui/templates/admin/editable_component.html View File

1
 {% macro input(fieldname, field, value='') -%}
1
 {% macro input(fieldname, field, value='') -%}
2
 	<label for="field_input_{{fieldname}}" class="col-sm-2 control-label">{{fieldname}}</label>
2
 	<label for="field_input_{{fieldname}}" class="col-sm-2 control-label">{{fieldname}}</label>
3
     <div class="col-xs-6">
3
     <div class="col-xs-6">
4
+	{% if value == None %}
5
+		{% set value = '' %}
6
+	{% endif %}
4
 	{% if field.base_type == 'bool' %}
7
 	{% if field.base_type == 'bool' %}
5
 		<input id="field_input_{{fieldname}}" class="form-control" name="field_input_{{fieldname}}" type="checkbox" checked="{% if value %}checked{% endif %}" >
8
 		<input id="field_input_{{fieldname}}" class="form-control" name="field_input_{{fieldname}}" type="checkbox" checked="{% if value %}checked{% endif %}" >
6
 	{% elif field.base_type == 'password' %}
9
 	{% elif field.base_type == 'password' %}
15
         {% endif %}
18
         {% endif %}
16
         {% if field.directly_editable %}
19
         {% if field.directly_editable %}
17
             <input id="{{fieldname}}" class="form-control" name="field_input_{{fieldname}}" type="text" value="{{sval}}" >
20
             <input id="{{fieldname}}" class="form-control" name="field_input_{{fieldname}}" type="text" value="{{sval}}" >
18
-            {% set l_classe = field.linked_classes %}
21
+            {% set l_classe = field.allowed_classes %}
19
             <p> Please enter uids to instances of {{ l_classe.__name__ }} separated by commas </p>
22
             <p> Please enter uids to instances of {{ l_classe.__name__ }} separated by commas </p>
20
         {% else %}
23
         {% else %}
21
             <input id="{{fieldname}}" class="form-control" name="field_input_{{fieldname}}" type="text" value="{{sval}}" readonly >
24
             <input id="{{fieldname}}" class="form-control" name="field_input_{{fieldname}}" type="text" value="{{sval}}" readonly >

+ 1
- 0
plugins/webui/templates/base_backend.html View File

28
             <li class="active"><a href="/{{ root_url }}/admin">Home</a></li>
28
             <li class="active"><a href="/{{ root_url }}/admin">Home</a></li>
29
             <li><a href="/{{ root_url }}/admin/object_create">Create</a></li>
29
             <li><a href="/{{ root_url }}/admin/object_create">Create</a></li>
30
             <li><a href="/{{ root_url }}/admin/classes_admin">Edit</a></li>
30
             <li><a href="/{{ root_url }}/admin/classes_admin">Edit</a></li>
31
+            <li><a href="/{{ root_url }}/admin/object_delete">Delete</a></li>
31
           </ul>
32
           </ul>
32
           <ul class="nav navbar-nav navbar-right">
33
           <ul class="nav navbar-nav navbar-right">
33
             <li><a href="/{{ root_url }}/">Front-End</a></li>
34
             <li><a href="/{{ root_url }}/">Front-End</a></li>

Loading…
Cancel
Save