Selaa lähdekoodia

CMS-Mode implemented

master
Dirk Alders 2 kuukautta sitten
vanhempi
commit
17f051bbf5
3 muutettua tiedostoa jossa 58 lisäystä ja 12 poistoa
  1. 20
    12
      pages/context.py
  2. 36
    0
      pages/parameter.py
  3. 2
    0
      piki/urls.py

+ 20
- 12
pages/context.py Näytä tiedosto

6
 from django.utils.translation import gettext as _
6
 from django.utils.translation import gettext as _
7
 
7
 
8
 from pages import access
8
 from pages import access
9
+import pages.parameter
9
 from .help import actionbar as actionbar_add_help
10
 from .help import actionbar as actionbar_add_help
10
 import mycreole
11
 import mycreole
11
 import pages
12
 import pages
22
 NAVIGATION_ENTRY_UID = 'navigation-%s'
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
 def context_adaption(context, request, **kwargs):
31
 def context_adaption(context, request, **kwargs):
26
     caller_name = inspect.currentframe().f_back.f_code.co_name
32
     caller_name = inspect.currentframe().f_back.f_code.co_name
27
     try:
33
     try:
56
 
62
 
57
 def menubar(context, request, caller_name, **kwargs):
63
 def menubar(context, request, caller_name, **kwargs):
58
     bar = context[context.MENUBAR]
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
     add_index_menu(request, bar, kwargs.get("rel_path", ''))
68
     add_index_menu(request, bar, kwargs.get("rel_path", ''))
62
     finalise_bar(request, bar)
69
     finalise_bar(request, bar)
63
 
70
 
64
 
71
 
65
 def actionbar(context, request, caller_name, **kwargs):
72
 def actionbar(context, request, caller_name, **kwargs):
66
     bar = context[context.ACTIONBAR]
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
 def add_back_menu(request, bar):
87
 def add_back_menu(request, bar):

+ 36
- 0
pages/parameter.py Näytä tiedosto

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 Näytä tiedosto

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

Loading…
Peruuta
Tallenna