Ver código fonte

CMS-Mode implemented

master
Dirk Alders 2 meses atrás
pai
commit
17f051bbf5
3 arquivos alterados com 58 adições e 12 exclusões
  1. 20
    12
      pages/context.py
  2. 36
    0
      pages/parameter.py
  3. 2
    0
      piki/urls.py

+ 20
- 12
pages/context.py Ver arquivo

@@ -6,6 +6,7 @@ from django.conf import settings
6 6
 from django.utils.translation import gettext as _
7 7
 
8 8
 from pages import access
9
+import pages.parameter
9 10
 from .help import actionbar as actionbar_add_help
10 11
 import mycreole
11 12
 import pages
@@ -22,6 +23,11 @@ INDEX_UID = 'index'
22 23
 NAVIGATION_ENTRY_UID = 'navigation-%s'
23 24
 
24 25
 
26
+def cms_mode_active(request):
27
+    user_logged_in = request.user.is_authenticated
28
+    return pages.parameter.get(pages.parameter.CMS_MODE) and not user_logged_in
29
+
30
+
25 31
 def context_adaption(context, request, **kwargs):
26 32
     caller_name = inspect.currentframe().f_back.f_code.co_name
27 33
     try:
@@ -56,24 +62,26 @@ def navigationbar(context, request, caller_name, **kwargs):
56 62
 
57 63
 def menubar(context, request, caller_name, **kwargs):
58 64
     bar = context[context.MENUBAR]
59
-    menubar_users(bar, request)
60
-    add_help_menu(request, bar, "current_help_page" in kwargs)
65
+    if not cms_mode_active(request):
66
+        menubar_users(bar, request)
67
+        add_help_menu(request, bar, "current_help_page" in kwargs)
61 68
     add_index_menu(request, bar, kwargs.get("rel_path", ''))
62 69
     finalise_bar(request, bar)
63 70
 
64 71
 
65 72
 def actionbar(context, request, caller_name, **kwargs):
66 73
     bar = context[context.ACTIONBAR]
67
-    if caller_name == 'page':
68
-        if access.write_page(request, kwargs["rel_path"]):
69
-            add_edit_menu(request, bar, kwargs["rel_path"])
70
-        if access.modify_attachment(request, kwargs["rel_path"]):
71
-            add_manageupload_menu(request, bar, kwargs['upload_path'])
72
-        if access.read_page(request, kwargs["rel_path"]):
73
-            add_meta_menu(request, bar, kwargs["rel_path"])
74
-    elif caller_name == 'helpview':
75
-        actionbar_add_help(context, request, **kwargs)
76
-    finalise_bar(request, bar)
74
+    if not cms_mode_active(request):
75
+        if caller_name == 'page':
76
+            if access.write_page(request, kwargs["rel_path"]):
77
+                add_edit_menu(request, bar, kwargs["rel_path"])
78
+            if access.modify_attachment(request, kwargs["rel_path"]):
79
+                add_manageupload_menu(request, bar, kwargs['upload_path'])
80
+            if access.read_page(request, kwargs["rel_path"]):
81
+                add_meta_menu(request, bar, kwargs["rel_path"])
82
+        elif caller_name == 'helpview':
83
+            actionbar_add_help(context, request, **kwargs)
84
+        finalise_bar(request, bar)
77 85
 
78 86
 
79 87
 def add_back_menu(request, bar):

+ 36
- 0
pages/parameter.py Ver arquivo

@@ -0,0 +1,36 @@
1
+import config
2
+from django.conf import settings
3
+import importlib
4
+import os
5
+
6
+CMS_MODE = "CMS_MODE"
7
+
8
+
9
+def no_access(*args, **kwargs):
10
+    return False
11
+
12
+
13
+DEFAULTS = {
14
+    CMS_MODE: True,
15
+}
16
+
17
+
18
+def __get_object_by_name__(object_name):
19
+    class_data = object_name.split(".")
20
+    module_path = ".".join(class_data[:-1])
21
+    class_str = class_data[-1]
22
+    #
23
+    module = importlib.import_module(module_path)
24
+    return getattr(module, class_str)
25
+
26
+
27
+def get(key):
28
+    # take data from config, settings or defaults
29
+    try:
30
+        data = getattr(config, key)
31
+    except AttributeError:
32
+        try:
33
+            data = getattr(settings, key)
34
+        except AttributeError:
35
+            data = DEFAULTS.get(key)
36
+    return data

+ 2
- 0
piki/urls.py Ver arquivo

@@ -20,6 +20,7 @@ from django.contrib import admin
20 20
 from django.urls import path, include
21 21
 
22 22
 import pages.views
23
+import users
23 24
 
24 25
 urlpatterns = [
25 26
     path('admin/', admin.site.urls),
@@ -37,6 +38,7 @@ urlpatterns = [
37 38
     path('mycreole/', include('mycreole.urls')),
38 39
     # users
39 40
     path('users/', include('users.urls')),
41
+    path('login/', users.views.login, name='users-login-root'),
40 42
 ]
41 43
 
42 44
 if settings.DEBUG:

Carregando…
Cancelar
Salvar