Browse Source

Make mycreole independent from patt

make_mycreole_indenpendent_from_patt
Dirk Alders 3 weeks ago
parent
commit
8a2da2b843
2 changed files with 27 additions and 6 deletions
  1. 23
    4
      context.py
  2. 4
    2
      help.py

+ 23
- 4
context.py View File

1
+from django.conf import settings
1
 from django.utils.translation import gettext as _
2
 from django.utils.translation import gettext as _
3
+
2
 import logging
4
 import logging
5
+import importlib
6
+
3
 from mycreole import url_upload
7
 from mycreole import url_upload
4
-from users.context import menubar as user_menubar
5
-from patt.context import navigationbar
6
 from themes import color_icon_url
8
 from themes import color_icon_url
7
 
9
 
8
 try:
10
 try:
15
 
17
 
16
 
18
 
17
 def context_adaption(context, request, title, rel_path, **kwargs):
19
 def context_adaption(context, request, title, rel_path, **kwargs):
20
+    def get_method(import_string):
21
+        class_data = import_string.split(".")
22
+        module_path = ".".join(class_data[:-1])
23
+        class_str = class_data[-1]
24
+        #
25
+        module = importlib.import_module(module_path)
26
+        return getattr(module, class_str)
27
+
28
+    def log_warning(method_name, e):
29
+        logger.warning('Could not import %s method for extending bars: %s - %s', method_name, type(e).__name__, e)
30
+
18
     context.set_additional_title(title)
31
     context.set_additional_title(title)
19
-    user_menubar(context[context.MENUBAR], request)
20
-    navigationbar(context, request)
32
+    for key in ["menubar", "navibar"]:
33
+        try:
34
+            method_name = settings.MYCREOLE_BAR[key]
35
+        except (AttributeError, KeyError) as e:
36
+            log_warning(key, e)
37
+        else:
38
+            method = get_method(method_name)
39
+            method(context, request, caller_name="attachments")
21
     add_new(request, context[context.ACTIONBAR], rel_path, kwargs.get('next'))
40
     add_new(request, context[context.ACTIONBAR], rel_path, kwargs.get('next'))
22
     for key in kwargs:
41
     for key in kwargs:
23
         context[key] = kwargs[key]
42
         context[key] = kwargs[key]

+ 4
- 2
help.py View File

1
 MYCREOLE_HELP = """\
1
 MYCREOLE_HELP = """\
2
 = Creole Markup
2
 = Creole Markup
3
 
3
 
4
-The Fields //"Description"// and //"Name"// of Tasks and Projects are interpreted as creole. \
4
+Some Fields are interpreted as creole. \
5
 See http://www.wikicreole.org for more details.
5
 See http://www.wikicreole.org for more details.
6
 
6
 
7
 == Text Markup
7
 == Text Markup
12
 | Underline | {{{__text__}}} | __text__ |
12
 | Underline | {{{__text__}}} | __text__ |
13
 | Raw Link | {{{https://python.org}}} | https://python.org |
13
 | Raw Link | {{{https://python.org}}} | https://python.org |
14
 | Text Link | {{{[[https://python.org|Python]]}}} | [[https://python.org|Python]] |
14
 | Text Link | {{{[[https://python.org|Python]]}}} | [[https://python.org|Python]] |
15
+
16
+== Additional syntax
15
 | Image | {{{ {{/media/theme/logo.png|logo}}     }}} | {{/media/theme/logo.png|logo}} |
17
 | Image | {{{ {{/media/theme/logo.png|logo}}     }}} | {{/media/theme/logo.png|logo}} |
16
 | Attachment Text Link | {{{[[attachment:file.ext|Python]]}}} |  |
18
 | Attachment Text Link | {{{[[attachment:file.ext|Python]]}}} |  |
17
 | Attachment Image | {{{ {{attachment:logo.png|logo}}     }}} |  |
19
 | Attachment Image | {{{ {{attachment:logo.png|logo}}     }}} |  |
115
 {{{
117
 {{{
116
 unprocessde data! <div>
118
 unprocessde data! <div>
117
 }}}
119
 }}}
118
-"""
120
+"""

Loading…
Cancel
Save