Przeglądaj źródła

Make mycreole independent from patt

make_mycreole_indenpendent_from_patt
Dirk Alders 3 tygodni temu
rodzic
commit
8a2da2b843
2 zmienionych plików z 27 dodań i 6 usunięć
  1. 23
    4
      context.py
  2. 4
    2
      help.py

+ 23
- 4
context.py Wyświetl plik

@@ -1,8 +1,10 @@
1
+from django.conf import settings
1 2
 from django.utils.translation import gettext as _
3
+
2 4
 import logging
5
+import importlib
6
+
3 7
 from mycreole import url_upload
4
-from users.context import menubar as user_menubar
5
-from patt.context import navigationbar
6 8
 from themes import color_icon_url
7 9
 
8 10
 try:
@@ -15,9 +17,26 @@ NEW_ATTACHMENT_UID = 'new_attachment'
15 17
 
16 18
 
17 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 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 40
     add_new(request, context[context.ACTIONBAR], rel_path, kwargs.get('next'))
22 41
     for key in kwargs:
23 42
         context[key] = kwargs[key]

+ 4
- 2
help.py Wyświetl plik

@@ -1,7 +1,7 @@
1 1
 MYCREOLE_HELP = """\
2 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 5
 See http://www.wikicreole.org for more details.
6 6
 
7 7
 == Text Markup
@@ -12,6 +12,8 @@ See http://www.wikicreole.org for more details.
12 12
 | Underline | {{{__text__}}} | __text__ |
13 13
 | Raw Link | {{{https://python.org}}} | https://python.org |
14 14
 | Text Link | {{{[[https://python.org|Python]]}}} | [[https://python.org|Python]] |
15
+
16
+== Additional syntax
15 17
 | Image | {{{ {{/media/theme/logo.png|logo}}     }}} | {{/media/theme/logo.png|logo}} |
16 18
 | Attachment Text Link | {{{[[attachment:file.ext|Python]]}}} |  |
17 19
 | Attachment Image | {{{ {{attachment:logo.png|logo}}     }}} |  |
@@ -115,4 +117,4 @@ results in:
115 117
 {{{
116 118
 unprocessde data! <div>
117 119
 }}}
118
-"""
120
+"""

Ładowanie…
Anuluj
Zapisz