Просмотр исходного кода

Page for Metadata added

master
Dirk Alders 3 месяцев назад
Родитель
Сommit
4b231c0b39
4 измененных файлов: 55 добавлений и 4 удалений
  1. 5
    2
      pages/__init__.py
  2. 23
    0
      pages/context.py
  3. 21
    1
      pages/page.py
  4. 6
    1
      pages/views.py

+ 5
- 2
pages/__init__.py Просмотреть файл

@@ -1,8 +1,11 @@
1 1
 from django.urls.base import reverse
2 2
 
3 3
 
4
-def url_page(request, rel_path):
5
-    return reverse('page-page', kwargs={'rel_path': rel_path})
4
+def url_page(request, rel_path, **kwargs):
5
+    params = "&".join([f"{key}" + ("" if kwargs[key] is None else f"={kwargs[key]}") for key in kwargs])
6
+    if len(params) > 0:
7
+        params = "?" + params
8
+    return reverse('page-page', kwargs={'rel_path': rel_path}) + params
6 9
 
7 10
 
8 11
 def url_helpview(request, page):

+ 23
- 0
pages/context.py Просмотреть файл

@@ -113,6 +113,8 @@ def actionbar(context, request, caller_name, **kwargs):
113 113
             add_edit_menu(request, bar, kwargs["rel_path"])
114 114
         if access.modify_attachment(request, kwargs["rel_path"]):
115 115
             add_manageupload_menu(request, bar, kwargs['upload_path'])
116
+        if access.read_page(request, kwargs["rel_path"]):
117
+            add_meta_menu(request, bar, kwargs["rel_path"])
116 118
     elif caller_name == 'helpview':
117 119
         actionbar_add_help(context, request, **kwargs)
118 120
     finalise_bar(request, bar)
@@ -140,6 +142,27 @@ def add_manageupload_menu(request, bar, upload_path):
140 142
     )
141 143
 
142 144
 
145
+def add_meta_menu(request, bar, rel_path):
146
+    if "meta" in request.GET:
147
+        bar.append_entry(
148
+            EDIT_UID,                                       # uid
149
+            _('Page'),                                      # name
150
+            color_icon_url(request, 'display.png'),         # icon
151
+            pages.url_page(request, rel_path),              # url
152
+            True,                                           # left
153
+            False                                           # active
154
+        )
155
+    else:
156
+        bar.append_entry(
157
+            EDIT_UID,                                       # uid
158
+            _('Meta'),                                      # name
159
+            color_icon_url(request, 'info.png'),            # icon
160
+            pages.url_page(request, rel_path, meta=None),   # url
161
+            True,                                           # left
162
+            False                                           # active
163
+        )
164
+
165
+
143 166
 def finalise_bar(request, bar):
144 167
     if len(bar) == 0:
145 168
         bar.append_entry(*empty_entry_parameters(request))

+ 21
- 1
pages/page.py Просмотреть файл

@@ -1,5 +1,6 @@
1
+from datetime import datetime
1 2
 from django.conf import settings
2
-
3
+from django.utils.translation import gettext as _
3 4
 import fstools
4 5
 import json
5 6
 import logging
@@ -7,6 +8,8 @@ from pages import messages, url_page
7 8
 import mycreole
8 9
 import os
9 10
 import time
11
+from users.models import get_userprofile
12
+import zoneinfo
10 13
 
11 14
 logger = logging.getLogger(settings.ROOT_LOGGER_NAME).getChild(__name__)
12 15
 
@@ -141,6 +144,23 @@ class creole_page(base_page):
141 144
             messages.unavailable_msg_page(self._request, self.rel_path)
142 145
             return ""
143 146
 
147
+    def render_meta(self):
148
+        def str_date(tm):
149
+            up = get_userprofile(self._request.user)
150
+            tz = zoneinfo.ZoneInfo(up.timezone)
151
+            #
152
+            return datetime.fromtimestamp(tm, tz).strftime('%Y-%m-%d %H:%M')
153
+        #
154
+        ctime = str_date(self._meta_data.get(self._meta_data.KEY_CREATION_TIME))
155
+        mtime = str_date(self._meta_data.get(self._meta_data.KEY_MODIFIED_TIME))
156
+        user = self._meta_data.get(self._meta_data.KEY_MODIFIED_USER)
157
+        #
158
+        meta = f'|{_("Created")}:|{ctime}|\n'
159
+        meta += f'|{_("Modified")}:|{mtime}|\n'
160
+        meta += f'|{_("Editor")}|{user}|\n\n'
161
+        #
162
+        return mycreole.render_simple(meta)
163
+
144 164
     def render_text(self, request, txt):
145 165
         macros = {
146 166
             "subpages": self.macro_subpages,

+ 6
- 1
pages/views.py Просмотреть файл

@@ -28,9 +28,14 @@ def root(request):
28 28
 def page(request, rel_path):
29 29
     context = Context(request)      # needs to be executed first because of time mesurement
30 30
     #
31
+    meta = "meta" in request.GET
32
+    #
31 33
     p = creole_page(request, rel_path)
32 34
     if access.read_page(request, rel_path):
33
-        page_content = p.render_to_html()
35
+        if meta:
36
+            page_content = p.render_meta()
37
+        else:
38
+            page_content = p.render_to_html()
34 39
     else:
35 40
         messages.permission_denied_msg_page(request, rel_path)
36 41
         page_content = ""

Загрузка…
Отмена
Сохранить