Browse Source

Started implementation of admin controllers & templates

Yann Weber 8 years ago
parent
commit
576ae97d0f

+ 43
- 0
plugins/webui/interface/controllers/admin.py View File

1
+from ...exceptions import *
1
 from .base import get_response
2
 from .base import get_response
2
 
3
 
4
+from lodel.leapi.exceptions import *
5
+from lodel import logger
6
+
7
+import leapi_dyncode as dyncode
8
+
3
 def index_admin(request):
9
 def index_admin(request):
4
     return get_response('admin/admin.html')
10
     return get_response('admin/admin.html')
5
 
11
 
12
+def admin_update(request):
13
+    test_valid = 'lodel_id' in request.GET \
14
+        and len(request.GET['lodel_id']) == 1
15
+
16
+    if test_valid:
17
+        try:
18
+            lodel_id = int(request.GET['lodel_id'][0])
19
+        except (ValueError, TypeError):
20
+            test_valid = False
21
+
22
+    if not test_valid:
23
+        raise HttpException(400)
24
+    else:
25
+        obj = dyncode.Object.get(['lodel_id = %d' % lodel_id])
26
+        if len(obj) == 0:
27
+            raise HttpException(404)
28
+    print("WHAT WE GOT AS RESPONSE : ")
29
+    for n,o in enumerate(obj):
30
+        print("\t",n,o.datas(True))
31
+    return get_response('admin/admin_edit.html', obj = obj)
32
+
33
+def admin_create(request):
34
+    classname = None
35
+    if 'classname' in request.GET:
36
+        classname = request.GET['classname']
37
+        if len(classname) > 1:
38
+            raise HttpException(400)
39
+        classname = classname[0]
40
+        try:
41
+            target_leo = dyncode.Object.name2class(classname)
42
+        except LeApiError:
43
+            classname = None
44
+    if classname is None or target_leo.is_abstract():
45
+        raise HttpException(400)
46
+    
47
+    return get_response('admin/admin_create.html', target=target_leo)
48
+
6
 def admin(request):
49
 def admin(request):
7
     return get_response('admin/admin.html')
50
     return get_response('admin/admin.html')
8
 
51
 

+ 9
- 1
plugins/webui/interface/controllers/base.py View File

5
 
5
 
6
 # This module contains the web UI controllers that will be called from the web ui class
6
 # This module contains the web UI controllers that will be called from the web ui class
7
 
7
 
8
-def get_response(tpl='empty.html', tpl_vars={}, mimetype='text/html', status_code=200):
8
+##@brief Render a template and return a respone
9
+#@param tpl str : template relativ path
10
+#@param tpl_vars : templates variables (obsolete)
11
+#@param mimetype
12
+#@param status_code
13
+#@param **kwargs : new version of tpl_vars
14
+#@return a response...
15
+def get_response(tpl='empty.html', tpl_vars={}, mimetype='text/html', status_code=200, **kwargs):
16
+    tpl_vars.update(kwargs)
9
     loader = TemplateLoader()
17
     loader = TemplateLoader()
10
     response = Response(loader.render_to_response(tpl, template_vars=tpl_vars), mimetype=mimetype)
18
     response = Response(loader.render_to_response(tpl, template_vars=tpl_vars), mimetype=mimetype)
11
     response.status_code = status_code
19
     response.status_code = status_code

+ 2
- 1
plugins/webui/interface/urls.py View File

4
 urls = (
4
 urls = (
5
     (r'^/?$', index),
5
     (r'^/?$', index),
6
     (r'^/admin/?$', admin),
6
     (r'^/admin/?$', admin),
7
-    (r'^/admin/(.+)$', admin),
7
+    (r'^/admin/create$', admin_create),
8
+    (r'^/admin/update$', admin_update),
8
     (r'/test/(?P<id>.*)$', test),
9
     (r'/test/(?P<id>.*)$', test),
9
     (r'^/test/?$', test),
10
     (r'^/test/?$', test),
10
     #(r'/show/(?P<id>.*)$', show_document),
11
     #(r'/show/(?P<id>.*)$', show_document),

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

1
 {% extends "base_backend.html" %}
1
 {% extends "base_backend.html" %}
2
-{% block title %}Lodel 2 - ADMIN{% endblock %}
3
-{% block content %}ADMIN{% endblock %}
2
+{% block title %}- Index{% endblock %}
3
+{% block body %}
4
+<h1>{{settings.sitename}} administration</h1>
5
+{{url('admin')}}
6
+<ul>
7
+	<li></li>
8
+</ul>
9
+
10
+{% endblock %}

+ 4
- 0
plugins/webui/templates/admin/admin_create.html View File

1
+{% extends "base_backend.html" %}
2
+{% block title %}- Creating a new {{target.__name__}}{% endblock %}
3
+{% block body %}
4
+{% endblock %}

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

1
+{% extends "base_backend.html" %}

+ 3
- 5
plugins/webui/templates/base_backend.html View File

2
 <html lang="en">
2
 <html lang="en">
3
 <head>
3
 <head>
4
     <meta charset="UTF-8" />
4
     <meta charset="UTF-8" />
5
-    <title>{% block title %}{% endblock %}</title>
5
+    <title>{{ settings.sitename }} Admin{% block title %}{% endblock %}</title>
6
     {% block style %}{% endblock %}
6
     {% block style %}{% endblock %}
7
     {% block scripts %}{% endblock %}
7
     {% block scripts %}{% endblock %}
8
 </head>
8
 </head>
9
 <body>
9
 <body>
10
-    <div id="content">
11
-        {% block content %}{% endblock %}
12
-    </div>
10
+    {% block body %}{% endblock %}
13
     <script type="text/javascript">{% block javascript %}{% endblock %}</script>
11
     <script type="text/javascript">{% block javascript %}{% endblock %}</script>
14
 </body>
12
 </body>
15
-</html>
13
+</html>

Loading…
Cancel
Save