소스 검색

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

Conflicts:
	plugins/webui/interface/urls.py
prieto 8 년 전
부모
커밋
98f9949172

+ 4
- 1
lodel/editorial_model/exceptions.py 파일 보기

5
 
5
 
6
 
6
 
7
 def assert_edit():
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
     if not Settings.editorialmodel.editormode:
12
     if not Settings.editorialmodel.editormode:
10
         raise EditorialModelError("EM is readonly : editormode is OFF")
13
         raise EditorialModelError("EM is readonly : editormode is OFF")
11
 
14
 

+ 5
- 5
lodel/editorial_model/model.py 파일 보기

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

+ 2
- 0
plugins/webui/interface/controllers/__init__.py 파일 보기

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

+ 5
- 0
plugins/webui/interface/controllers/base.py 파일 보기

22
 
22
 
23
 
23
 
24
 def test(request):
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
     return get_response('test.html')
30
     return get_response('test.html')
26
     
31
     

+ 1
- 1
plugins/webui/interface/controllers/document.py 파일 보기

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

+ 3
- 4
plugins/webui/interface/controllers/listing.py 파일 보기

1
 from .base import get_response
1
 from .base import get_response
2
-
2
+import leapi_dyncode as dyncode
3
 def list_classes(request):
3
 def list_classes(request):
4
     # TODO Add the method to get the classes list
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 파일 보기

3
 
3
 
4
 from .controllers import *
4
 from .controllers import *
5
 from .urls import urls
5
 from .urls import urls
6
+from ..main import root_url
6
 from lodel.settings import Settings
7
 from lodel.settings import Settings
7
 
8
 
8
-
9
 def format_url_rule(url_rule):
9
 def format_url_rule(url_rule):
10
-    if url_rule == '^$':
11
-        return "^%s$" % Settings.sitename
12
-
13
-    formatted_rule = ''
14
     if url_rule.startswith('^'):
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
 def get_controller(request):
17
 def get_controller(request):
26
 
22
 
27
     # Returning the right controller to call
23
     # Returning the right controller to call
28
     for regex, callback in url_rules:
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
         if match is not None:
31
         if match is not None:
31
             request.url_args = match.groups()
32
             request.url_args = match.groups()
32
             return callback
33
             return callback
33
-
34
+        '''
34
     return not_found
35
     return not_found

+ 9
- 0
plugins/webui/interface/template/loader.py 파일 보기

2
 import jinja2
2
 import jinja2
3
 import os
3
 import os
4
 
4
 
5
+from lodel.settings import Settings
6
+import leapi_dyncode
7
+
5
 import settings
8
 import settings
6
 from .api import api_lodel_templates
9
 from .api import api_lodel_templates
7
 from .exceptions.not_allowed_custom_api_key_error import NotAllowedCustomAPIKeyError
10
 from .exceptions.not_allowed_custom_api_key_error import NotAllowedCustomAPIKeyError
11
+from ...main import root_url
8
 
12
 
9
 from ...main import PLUGIN_PATH
13
 from ...main import PLUGIN_PATH
10
 TEMPLATE_PATH = os.path.realpath(os.path.join(PLUGIN_PATH, 'templates/'))
14
 TEMPLATE_PATH = os.path.realpath(os.path.join(PLUGIN_PATH, 'templates/'))
39
         # lodel2 default api is loaded
43
         # lodel2 default api is loaded
40
         # TODO change this if needed
44
         # TODO change this if needed
41
         template.globals['lodel'] = api_lodel_templates
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
         # Extra modules are loaded
52
         # Extra modules are loaded
44
         if template_extra is not None:
53
         if template_extra is not None:

+ 8
- 8
plugins/webui/interface/urls.py 파일 보기

1
 from .controllers import *
1
 from .controllers import *
2
 
2
 
3
 urls = (
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 파일 보기

6
 
6
 
7
 PLUGIN_PATH = os.path.dirname(__file__)
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
 ##@brief uwsgi startup demo
14
 ##@brief uwsgi startup demo
10
 @LodelHook('lodel2_loader_main')
15
 @LodelHook('lodel2_loader_main')
11
 def uwsgi_fork(hook_name, caller, payload):
16
 def uwsgi_fork(hook_name, caller, payload):

+ 7
- 0
plugins/webui/templates/test.html 파일 보기

1
 <html>
1
 <html>
2
 <head></head>
2
 <head></head>
3
 <body>
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
     <form action="http://localhost:9090/admin?r=1&rand[]=7&rand[]=5" method="POST" enctype="multipart/form-data">
11
     <form action="http://localhost:9090/admin?r=1&rand[]=7&rand[]=5" method="POST" enctype="multipart/form-data">
5
         <input type="text" name="re[]" value="3"><br />
12
         <input type="text" name="re[]" value="3"><br />
6
         <input type="text" name="re[]" value="1"><br />
13
         <input type="text" name="re[]" value="1"><br />

Loading…
취소
저장