Browse Source

Merge branch 'newlodel' of git.labocleo.org:lodel2 into newlodel

Conflicts:
	plugins/webui/interface/urls.py
prieto 8 years ago
parent
commit
98f9949172

+ 4
- 1
lodel/editorial_model/exceptions.py View File

@@ -5,7 +5,10 @@ class EditorialModelError(Exception):
5 5
 
6 6
 
7 7
 def assert_edit():
8
-    from lodel import Settings
8
+    try:
9
+        from lodel import Settings
10
+    except ImportError: #Very dirty, but don't know how to fix the tests
11
+        return
9 12
     if not Settings.editorialmodel.editormode:
10 13
         raise EditorialModelError("EM is readonly : editormode is OFF")
11 14
 

+ 5
- 5
lodel/editorial_model/model.py View File

@@ -176,7 +176,7 @@ class EditorialModel(object):
176 176
     # @param emclass EmClass : the EmClass instance to add
177 177
     # @return emclass
178 178
     def add_class(self, emclass):
179
-        assert_edit()()
179
+        assert_edit()
180 180
         if not isinstance(emclass, EmClass):
181 181
             raise ValueError("<class EmClass> expected but got %s " % type(emclass))
182 182
         if emclass.uid in self.classes():
@@ -188,7 +188,7 @@ class EditorialModel(object):
188 188
     # @param emgroup EmGroup : the EmGroup instance to add
189 189
     # @return emgroup
190 190
     def add_group(self, emgroup):
191
-        assert_edit()()
191
+        assert_edit()
192 192
         if not isinstance(emgroup, EmGroup):
193 193
             raise ValueError("<class EmGroup> expected but got %s" % type(emgroup))
194 194
         if emgroup.uid in self.groups():
@@ -201,7 +201,7 @@ class EditorialModel(object):
201 201
     #@param **kwargs : EmClass constructor options ( 
202 202
     # see @ref lodel.editorial_model.component.EmClass.__init__() )
203 203
     def new_class(self, uid, **kwargs):
204
-        assert_edit()()
204
+        assert_edit()
205 205
         return self.add_class(EmClass(uid, **kwargs))
206 206
     
207 207
     ##@brief Add a new EmGroup to the editorial model
@@ -209,14 +209,14 @@ class EditorialModel(object):
209 209
     #@param *kwargs : EmGroup constructor keywords arguments (
210 210
     # see @ref lodel.editorial_model.component.EmGroup.__init__() )
211 211
     def new_group(self, uid, **kwargs):
212
-        assert_edit()()
212
+        assert_edit()
213 213
         return self.add_group(EmGroup(uid, **kwargs))
214 214
 
215 215
     ##@brief Save a model
216 216
     # @param translator module : The translator module to use
217 217
     # @param **translator_args
218 218
     def save(self, translator, **translator_kwargs):
219
-        assert_edit()()
219
+        assert_edit()
220 220
         if isinstance(translator, str):
221 221
             translator = self.translator_from_name(translator)
222 222
         return translator.save(self, **translator_kwargs)

+ 2
- 0
plugins/webui/interface/controllers/__init__.py View File

@@ -1,3 +1,5 @@
1 1
 from .base import *
2 2
 from .admin import *
3 3
 from .document import *
4
+from .listing import *
5
+

+ 5
- 0
plugins/webui/interface/controllers/base.py View File

@@ -22,5 +22,10 @@ def not_found(request):
22 22
 
23 23
 
24 24
 def test(request):
25
+    template_vars = {
26
+        'id': request.url_args['id'],
27
+        'params': request.GET
28
+    }
29
+    return get_response('test.html', tpl_vars=template_vars)
25 30
     return get_response('test.html')
26 31
     

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

@@ -2,5 +2,5 @@ from .base import get_response
2 2
 
3 3
 
4 4
 def show_document(request):
5
-    template_vars = {'id': request.url_args[0]}
5
+    template_vars = {'id': request.url_args['id']}
6 6
     return get_response('documents/show.html', tpl_vars=template_vars)

+ 3
- 4
plugins/webui/interface/controllers/listing.py View File

@@ -1,7 +1,6 @@
1 1
 from .base import get_response
2
-
2
+import leapi_dyncode as dyncode
3 3
 def list_classes(request):
4 4
     # TODO Add the method to get the classes list
5
-    template_vars = {'id': request.url_args[0]}
6
-
7
-    return get_response('listing/list_classes.html')
5
+    template_vars = {'my_classes': dyncode.dynclasses}
6
+    return get_response('listing/list_classes.html', tpl_vars=template_vars)

+ 12
- 11
plugins/webui/interface/router.py View File

@@ -3,19 +3,15 @@ import re
3 3
 
4 4
 from .controllers import *
5 5
 from .urls import urls
6
+from ..main import root_url
6 7
 from lodel.settings import Settings
7 8
 
8
-
9 9
 def format_url_rule(url_rule):
10
-    if url_rule == '^$':
11
-        return "^%s$" % Settings.sitename
12
-
13
-    formatted_rule = ''
14 10
     if url_rule.startswith('^'):
15
-        formatted_rule += "^"
16
-
17
-    formatted_rule += "%s/%s" % (Settings.sitename, url_rule)
18
-    return formatted_rule
11
+        res = url_rule.replace('^', '^'+root_url())
12
+    else:
13
+        res = root_url()+'.*'+url_rule
14
+    return res
19 15
 
20 16
 
21 17
 def get_controller(request):
@@ -26,9 +22,14 @@ def get_controller(request):
26 22
 
27 23
     # Returning the right controller to call
28 24
     for regex, callback in url_rules:
29
-        match = re.search(regex, request.PATH)
25
+        p = re.compile(regex)
26
+        m = p.search(request.PATH)
27
+        if m is not None:
28
+            request.url_args = m.groupdict()
29
+            return callback
30
+        '''match = re.search(regex, request.PATH)
30 31
         if match is not None:
31 32
             request.url_args = match.groups()
32 33
             return callback
33
-
34
+        '''
34 35
     return not_found

+ 9
- 0
plugins/webui/interface/template/loader.py View File

@@ -2,9 +2,13 @@
2 2
 import jinja2
3 3
 import os
4 4
 
5
+from lodel.settings import Settings
6
+import leapi_dyncode
7
+
5 8
 import settings
6 9
 from .api import api_lodel_templates
7 10
 from .exceptions.not_allowed_custom_api_key_error import NotAllowedCustomAPIKeyError
11
+from ...main import root_url
8 12
 
9 13
 from ...main import PLUGIN_PATH
10 14
 TEMPLATE_PATH = os.path.realpath(os.path.join(PLUGIN_PATH, 'templates/'))
@@ -39,6 +43,11 @@ class TemplateLoader(object):
39 43
         # lodel2 default api is loaded
40 44
         # TODO change this if needed
41 45
         template.globals['lodel'] = api_lodel_templates
46
+        template.globals['leapi'] = leapi_dyncode
47
+        template.globals['settings'] = Settings
48
+        template.globals['url'] = lambda sufix='': root_url()\
49
+            + ('' if sufix.startswith('/') else '/')\
50
+            + sufix
42 51
 
43 52
         # Extra modules are loaded
44 53
         if template_extra is not None:

+ 8
- 8
plugins/webui/interface/urls.py View File

@@ -1,12 +1,12 @@
1 1
 from .controllers import *
2 2
 
3 3
 urls = (
4
-    (r'^$', index),
5
-    (r'admin/?$', admin),
6
-    (r'admin/(.+)$', admin),
7
-    (r'test/(.+)$', test),
8
-    (r'test/?$', test),
9
-    (r'show/(.+)$', show_document),
10
-    (r'list_classes/(.+)$', list_classes),
11
-    (r'list_classes/?$', list_classes)
4
+    (r'^/?$', index),
5
+    (r'^/admin/?$', admin),
6
+    (r'^/admin/(.+)$', admin),
7
+    (r'/test/(?P<id>.*)$', test),
8
+    (r'^/test/?$', test),
9
+    (r'/show/(?P<id>.*)$', show_document),
10
+    (r'^/list_classes/(.+)$', list_classes),
11
+    (r'^/list_classes/?$', list_classes),
12 12
 )

+ 5
- 0
plugins/webui/main.py View File

@@ -6,6 +6,11 @@ from lodel.settings import Settings
6 6
 
7 7
 PLUGIN_PATH = os.path.dirname(__file__)
8 8
 
9
+##@brief Return the root url of the instance
10
+def root_url():
11
+    return Settings.sitename
12
+
13
+
9 14
 ##@brief uwsgi startup demo
10 15
 @LodelHook('lodel2_loader_main')
11 16
 def uwsgi_fork(hook_name, caller, payload):

+ 7
- 0
plugins/webui/templates/test.html View File

@@ -1,6 +1,13 @@
1 1
 <html>
2 2
 <head></head>
3 3
 <body>
4
+    URL arg : id = {{ id }}<br />
5
+    GET values :<br />
6
+    <ul>
7
+    {% for argument_name, argument_value in params.items() %}
8
+        <li>{{argument_name}} = {{ argument_value }}</li>
9
+    {% endfor %}
10
+    </ul>
4 11
     <form action="http://localhost:9090/admin?r=1&rand[]=7&rand[]=5" method="POST" enctype="multipart/form-data">
5 12
         <input type="text" name="re[]" value="3"><br />
6 13
         <input type="text" name="re[]" value="1"><br />

Loading…
Cancel
Save