|
@@ -1,3 +1,4 @@
|
|
1
|
+import difflib
|
1
|
2
|
from django.conf import settings
|
2
|
3
|
from django.utils.translation import gettext as _
|
3
|
4
|
import fstools
|
|
@@ -13,36 +14,52 @@ from . import timestamp_to_datetime
|
13
|
14
|
logger = logging.getLogger(settings.ROOT_LOGGER_NAME).getChild(__name__)
|
14
|
15
|
|
15
|
16
|
|
|
17
|
+SPLITCHAR = ":"
|
|
18
|
+HISTORY_FOLDER_NAME = 'history'
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+def full_path_all_pages(expression="*"):
|
|
22
|
+ system_pages = fstools.dirlist(settings.SYSTEM_PAGES_ROOT, expression=expression, rekursive=False)
|
|
23
|
+ system_pages = [os.path.join(settings.PAGES_ROOT, os.path.basename(path)) for path in system_pages]
|
|
24
|
+ pages = fstools.dirlist(settings.PAGES_ROOT, expression=expression, rekursive=False)
|
|
25
|
+ return list(set(system_pages + pages))
|
|
26
|
+
|
|
27
|
+
|
16
|
28
|
class meta_data(dict):
|
|
29
|
+ META_FILE_NAME = 'meta.json'
|
|
30
|
+ #
|
17
|
31
|
KEY_CREATION_TIME = "creation_time"
|
18
|
32
|
KEY_MODIFIED_TIME = "modified_time"
|
19
|
33
|
KEY_MODIFIED_USER = "modified_user"
|
20
|
34
|
KEY_TAGS = "tags"
|
21
|
35
|
|
22
|
|
- def __init__(self, meta_filename, page_exists):
|
23
|
|
- self._meta_filename = meta_filename
|
24
|
|
-
|
|
36
|
+ def __init__(self, path, history_version=None):
|
|
37
|
+ self._path = path
|
|
38
|
+ self._history_version = history_version
|
|
39
|
+ #
|
25
|
40
|
# Load data from disk
|
26
|
41
|
try:
|
27
|
|
- with open(meta_filename, 'r') as fh:
|
|
42
|
+ with open(self.filename, 'r') as fh:
|
28
|
43
|
super().__init__(json.load(fh))
|
29
|
44
|
except (FileNotFoundError, json.decoder.JSONDecodeError) as e:
|
30
|
45
|
super().__init__()
|
31
|
46
|
|
32
|
|
- # Add missing information to meta_data
|
33
|
|
- missing_keys = False
|
34
|
|
- if self.KEY_CREATION_TIME not in self:
|
35
|
|
- missing_keys = True
|
36
|
|
- self[self.KEY_CREATION_TIME] = int(time.time())
|
37
|
|
- if self.KEY_MODIFIED_TIME not in self:
|
38
|
|
- self[self.KEY_MODIFIED_TIME] = self[self.KEY_CREATION_TIME]
|
39
|
|
- if missing_keys and page_exists:
|
40
|
|
- self.save()
|
|
47
|
+ @property
|
|
48
|
+ def filename(self):
|
|
49
|
+ if not self._history_version:
|
|
50
|
+ return os.path.join(self._path, self.META_FILE_NAME)
|
|
51
|
+ else:
|
|
52
|
+ return self.history_filename(self._history_version)
|
|
53
|
+
|
|
54
|
+ def history_filename(self, history_version):
|
|
55
|
+ return os.path.join(self._path, HISTORY_FOLDER_NAME, "%05d_%s" % (history_version, self.META_FILE_NAME))
|
41
|
56
|
|
42
|
57
|
def update(self, username, tags):
|
43
|
58
|
if username:
|
44
|
59
|
self[self.KEY_MODIFIED_TIME] = int(time.time())
|
45
|
60
|
self[self.KEY_MODIFIED_USER] = username
|
|
61
|
+ if self.KEY_CREATION_TIME not in self:
|
|
62
|
+ self[self.KEY_CREATION_TIME] = self[self.KEY_MODIFIED_TIME]
|
46
|
63
|
if tags:
|
47
|
64
|
self[self.KEY_TAGS] = tags
|
48
|
65
|
#
|
|
@@ -50,30 +67,27 @@ class meta_data(dict):
|
50
|
67
|
self.save()
|
51
|
68
|
|
52
|
69
|
def save(self):
|
53
|
|
- with open(self._meta_filename, 'w') as fh:
|
54
|
|
- json.dump(self, fh, indent=4)
|
|
70
|
+ if self._history_version:
|
|
71
|
+ logger.error("A history version %05d can not be updated!", self._history_version)
|
|
72
|
+ return False
|
|
73
|
+ else:
|
|
74
|
+ with open(self.filename, 'w') as fh:
|
|
75
|
+ json.dump(self, fh, indent=4)
|
|
76
|
+ return True
|
55
|
77
|
|
|
78
|
+ def store_to_history(self, history_number):
|
|
79
|
+ history_filename = self.history_filename(history_number)
|
|
80
|
+ fstools.mkdir(os.path.dirname(history_filename))
|
|
81
|
+ shutil.copy(self.filename, history_filename)
|
56
|
82
|
|
57
|
|
-class base_page(object):
|
|
83
|
+
|
|
84
|
+class page_data(object):
|
58
|
85
|
PAGE_FILE_NAME = 'page'
|
59
|
|
- META_FILE_NAME = 'meta.json'
|
60
|
|
- HISTORY_FOLDER_NAME = 'history'
|
61
|
|
- SPLITCHAR = ":"
|
62
|
86
|
|
63
|
87
|
def __init__(self, path, history_version=None):
|
64
|
88
|
self._history_version = history_version
|
65
|
|
- #
|
66
|
|
- if path.startswith(settings.PAGES_ROOT):
|
67
|
|
- self._path = path
|
68
|
|
- else:
|
69
|
|
- self._path = os.path.join(settings.PAGES_ROOT, path.replace("/", 2*self.SPLITCHAR))
|
|
89
|
+ self._path = path
|
70
|
90
|
self._raw_page_src = None
|
71
|
|
- #
|
72
|
|
- self._meta_data = meta_data(self._meta_filename, self.is_available())
|
73
|
|
-
|
74
|
|
- @property
|
75
|
|
- def modified_time(self):
|
76
|
|
- return self._meta_data.get(self._meta_data.KEY_MODIFIED_TIME)
|
77
|
91
|
|
78
|
92
|
def _load_page_src(self):
|
79
|
93
|
if self._raw_page_src is None:
|
|
@@ -83,43 +97,20 @@ class base_page(object):
|
83
|
97
|
except FileNotFoundError:
|
84
|
98
|
self._raw_page_src = ""
|
85
|
99
|
|
86
|
|
- def history_numbers_list(self):
|
87
|
|
- history_folder = os.path.join(self._path, self.HISTORY_FOLDER_NAME)
|
88
|
|
- fstools.mkdir(history_folder)
|
89
|
|
- # identify last_history number
|
90
|
|
- return list(set([int(os.path.basename(filename)[:5]) for filename in fstools.filelist(history_folder)]))
|
|
100
|
+ def update_required(self, page_txt):
|
|
101
|
+ return page_txt.replace("\r\n", "\n") != self.raw_page_src
|
91
|
102
|
|
92
|
|
- def _store_history(self):
|
93
|
|
- try:
|
94
|
|
- hist_number = max(self.history_numbers_list()) + 1
|
95
|
|
- except ValueError:
|
96
|
|
- hist_number = 1 # no history yet
|
97
|
|
- # copy file to history folder
|
98
|
|
- shutil.copy(self.filename, self.history_filename(hist_number))
|
99
|
|
- shutil.copy(self._meta_filename, self._history_meta_filename(hist_number))
|
100
|
|
-
|
101
|
|
- def update_page(self, page_txt, tags):
|
|
103
|
+ def update_page(self, page_txt):
|
102
|
104
|
if self._history_version:
|
103
|
105
|
logger.error("A history version %05d can not be updated!", self._history_version)
|
104
|
106
|
return False
|
105
|
107
|
else:
|
106
|
|
- from .search import update_item
|
107
|
|
- if page_txt.replace("\r\n", "\n") != self.raw_page_src:
|
108
|
|
- # Store page history
|
109
|
|
- if self.raw_page_src:
|
110
|
|
- self._store_history()
|
111
|
|
- # save the new page content
|
112
|
|
- fstools.mkdir(os.path.dirname(self.filename))
|
113
|
|
- with open(self.filename, 'w') as fh:
|
114
|
|
- fh.write(page_txt)
|
115
|
|
- # update metadata
|
116
|
|
- page_changed = True
|
117
|
|
- else:
|
118
|
|
- page_changed = False
|
119
|
|
- self._update_metadata(tags)
|
120
|
|
- # update search index
|
121
|
|
- update_item(self)
|
122
|
|
- return page_changed
|
|
108
|
+ # save the new page content
|
|
109
|
+ fstools.mkdir(os.path.dirname(self.filename))
|
|
110
|
+ with open(self.filename, 'w') as fh:
|
|
111
|
+ fh.write(page_txt)
|
|
112
|
+ self._raw_page_src = page_txt
|
|
113
|
+ return True
|
123
|
114
|
|
124
|
115
|
@property
|
125
|
116
|
def filename(self):
|
|
@@ -129,24 +120,11 @@ class base_page(object):
|
129
|
120
|
return self.history_filename(self._history_version)
|
130
|
121
|
|
131
|
122
|
def history_filename(self, history_version):
|
132
|
|
- return os.path.join(self._path, self.HISTORY_FOLDER_NAME, "%05d_%s" % (history_version, self.PAGE_FILE_NAME))
|
133
|
|
-
|
134
|
|
- @property
|
135
|
|
- def _meta_filename(self):
|
136
|
|
- if not self._history_version:
|
137
|
|
- return os.path.join(self._path, self.META_FILE_NAME)
|
138
|
|
- else:
|
139
|
|
- return self._history_meta_filename(self._history_version)
|
140
|
|
-
|
141
|
|
- def _history_meta_filename(self, history_version):
|
142
|
|
- return os.path.join(self._path, self.HISTORY_FOLDER_NAME, "%05d_%s" % (history_version, self.META_FILE_NAME))
|
|
123
|
+ return os.path.join(self._path, HISTORY_FOLDER_NAME, "%05d_%s" % (history_version, self.PAGE_FILE_NAME))
|
143
|
124
|
|
144
|
125
|
@property
|
145
|
126
|
def rel_path(self):
|
146
|
|
- return os.path.basename(self._path).replace(2*self.SPLITCHAR, "/")
|
147
|
|
-
|
148
|
|
- def rel_path_is_valid(self):
|
149
|
|
- return not self.SPLITCHAR in self.rel_path
|
|
127
|
+ return os.path.basename(self._path).replace(2*SPLITCHAR, "/")
|
150
|
128
|
|
151
|
129
|
def is_available(self):
|
152
|
130
|
is_a = os.path.isfile(self.filename)
|
|
@@ -163,23 +141,13 @@ class base_page(object):
|
163
|
141
|
self._load_page_src()
|
164
|
142
|
return self._raw_page_src
|
165
|
143
|
|
166
|
|
- def _update_metadata(self, tags):
|
167
|
|
- username = None
|
168
|
|
- try:
|
169
|
|
- if self._request.user.is_authenticated:
|
170
|
|
- username = self._request.user.username
|
171
|
|
- else:
|
172
|
|
- logger.warning("Page edit without having a logged in user. This is not recommended. Check your access definitions!")
|
173
|
|
- except AttributeError:
|
174
|
|
- logger.exception("Page edit without having a request object. Check programming!")
|
175
|
|
- self._meta_data.update(username, tags)
|
|
144
|
+ def store_to_history(self, history_number):
|
|
145
|
+ history_filename = self.history_filename(history_number)
|
|
146
|
+ fstools.mkdir(os.path.dirname(history_filename))
|
|
147
|
+ shutil.copy(self.filename, history_filename)
|
176
|
148
|
|
177
|
|
- @property
|
178
|
|
- def page_tags(self):
|
179
|
|
- return self._meta_data.get(self._meta_data.KEY_TAGS)
|
180
|
149
|
|
181
|
|
-
|
182
|
|
-class creole_page(base_page):
|
|
150
|
+class page_django(page_data):
|
183
|
151
|
FOLDER_ATTACHMENTS = "attachments"
|
184
|
152
|
|
185
|
153
|
def __init__(self, request, path, history_version=None) -> None:
|
|
@@ -197,18 +165,22 @@ class creole_page(base_page):
|
197
|
165
|
messages.unavailable_msg_page(self._request, self.rel_path)
|
198
|
166
|
return ""
|
199
|
167
|
|
200
|
|
- def render_meta(self):
|
201
|
|
- ctime = timestamp_to_datetime(self._request, self._meta_data.get(self._meta_data.KEY_CREATION_TIME)).strftime('%Y-%m-%d %H:%M')
|
202
|
|
- mtime = timestamp_to_datetime(self._request, self._meta_data.get(self._meta_data.KEY_MODIFIED_TIME)).strftime('%Y-%m-%d %H:%M')
|
203
|
|
- user = self._meta_data.get(self._meta_data.KEY_MODIFIED_USER)
|
204
|
|
- tags = self._meta_data.get(self._meta_data.KEY_TAGS, "-")
|
|
168
|
+ def history_numbers_list(self):
|
|
169
|
+ history_folder = os.path.join(self._path, HISTORY_FOLDER_NAME)
|
|
170
|
+ return list(set([int(os.path.basename(filename)[:5]) for filename in fstools.filelist(history_folder)]))
|
|
171
|
+
|
|
172
|
+ def render_meta(self, ctime, mtime, user, tags):
|
|
173
|
+ #
|
|
174
|
+ # Page meta data
|
205
|
175
|
#
|
206
|
176
|
meta = f'=== {_("Meta data")}\n'
|
207
|
|
- meta += f'|{_("Created")}:|{ctime}|\n'
|
208
|
|
- meta += f'|{_("Modified")}:|{mtime}|\n'
|
|
177
|
+ meta += f'|{_("Created")}:|{timestamp_to_datetime(self._request, ctime)}|\n'
|
|
178
|
+ meta += f'|{_("Modified")}:|{timestamp_to_datetime(self._request, mtime)}|\n'
|
209
|
179
|
meta += f'|{_("Editor")}|{user}|\n'
|
210
|
180
|
meta += f'|{_("Tags")}|{tags}|\n'
|
211
|
181
|
#
|
|
182
|
+ # List of hostory page versions
|
|
183
|
+ #
|
212
|
184
|
hnl = self.history_numbers_list()
|
213
|
185
|
if hnl:
|
214
|
186
|
meta += f'=== {_("History")}\n'
|
|
@@ -216,40 +188,27 @@ class creole_page(base_page):
|
216
|
188
|
# Current
|
217
|
189
|
name = _("Current")
|
218
|
190
|
meta += f"| {name} \
|
219
|
|
- | {timestamp_to_datetime(self._request, self.modified_time)} \
|
|
191
|
+ | {timestamp_to_datetime(self._request, mtime)} \
|
220
|
192
|
| [[{url_page(self._request, self.rel_path)} | Page]] \
|
221
|
193
|
| [[{url_page(self._request, self.rel_path, meta=None)} | Meta]]\n"
|
222
|
194
|
# History
|
223
|
195
|
for num in reversed(hnl):
|
224
|
|
- p = creole_page(self._request, self._path, history_version=num)
|
|
196
|
+ p = page_wrapped(self._request, self._path, history_version=num)
|
225
|
197
|
meta += f"| {num} \
|
226
|
198
|
| {timestamp_to_datetime(self._request, p.modified_time)} \
|
227
|
199
|
| [[{url_page(self._request, p.rel_path, history=num)} | Page]] \
|
228
|
|
- | [[{url_page(self._request, p.rel_path, meta=None, history=num)} | Meta]]\n"
|
229
|
|
- #
|
230
|
|
- meta += f'=== {_("Page content")}\n'
|
231
|
|
- if not self._history_version:
|
232
|
|
- meta += '{{{\n%s\n}}}\n' % self.raw_page_src
|
233
|
|
- else:
|
234
|
|
- c = creole_page(self._request, self.rel_path)
|
235
|
|
- meta += "| =Current | =This |\n"
|
|
200
|
+ | [[{url_page(self._request, p.rel_path, meta=None, history=num)} | Meta]] (with page changes)\n"
|
|
201
|
+ # Diff
|
|
202
|
+ html_diff = ""
|
|
203
|
+ if self._history_version:
|
|
204
|
+ meta += f'=== {_("Page differences")}\n'
|
|
205
|
+ #
|
|
206
|
+ c = page_django(self._request, self._path)
|
236
|
207
|
left_lines = c.raw_page_src.splitlines()
|
237
|
208
|
right_lines = self.raw_page_src.splitlines()
|
238
|
|
- while len(left_lines) + len(right_lines) > 0:
|
239
|
|
- try:
|
240
|
|
- left = left_lines.pop(0)
|
241
|
|
- except IndexError:
|
242
|
|
- left = ""
|
243
|
|
- try:
|
244
|
|
- right = right_lines.pop(0)
|
245
|
|
- except IndexError:
|
246
|
|
- right = ""
|
247
|
|
- if left == right:
|
248
|
|
- meta += "| {{{ %s }}} | {{{ %s }}} |\n" % (left, right)
|
249
|
|
- else:
|
250
|
|
- meta += "| **{{{ %s }}}** | **{{{ %s }}}** |\n" % (left, right)
|
|
209
|
+ html_diff = difflib.HtmlDiff(wrapcolumn=80).make_table(left_lines, right_lines)
|
251
|
210
|
#
|
252
|
|
- return mycreole.render_simple(meta)
|
|
211
|
+ return mycreole.render_simple(meta) + html_diff
|
253
|
212
|
|
254
|
213
|
def render_text(self, request, txt):
|
255
|
214
|
macros = {
|
|
@@ -289,11 +248,12 @@ class creole_page(base_page):
|
289
|
248
|
expression = "*"
|
290
|
249
|
parent_rel_path = ""
|
291
|
250
|
else:
|
292
|
|
- expression = os.path.basename(self._path) + 2 * self.SPLITCHAR + "*"
|
|
251
|
+ expression = os.path.basename(self._path) + 2 * SPLITCHAR + "*"
|
293
|
252
|
parent_rel_path = self.rel_path
|
|
253
|
+ #
|
294
|
254
|
pl = page_list(
|
295
|
255
|
self._request,
|
296
|
|
- [creole_page(self._request, path) for path in fstools.dirlist(settings.PAGES_ROOT, expression=expression, rekursive=False)]
|
|
256
|
+ [page_django(self._request, path) for path in full_path_all_pages(expression)]
|
297
|
257
|
)
|
298
|
258
|
return pl.html_list(depth=depth, filter_str=filter_str, parent_rel_path=parent_rel_path)
|
299
|
259
|
|
|
@@ -327,3 +287,151 @@ class page_list(list):
|
327
|
287
|
|
328
|
288
|
def html_list(self, depth=9999, filter_str='', parent_rel_path=''):
|
329
|
289
|
return mycreole.render_simple(self.creole_list(depth, filter_str, parent_rel_path))
|
|
290
|
+
|
|
291
|
+
|
|
292
|
+class page_wrapped(object):
|
|
293
|
+ """
|
|
294
|
+ This class holds different page and meta instances and decides which will be used in which case.
|
|
295
|
+ """
|
|
296
|
+
|
|
297
|
+ def __init__(self, request, path, history_version=None):
|
|
298
|
+ """_summary_
|
|
299
|
+
|
|
300
|
+ Args:
|
|
301
|
+ request (_type_): The django request or None (if None, the page functionality is limited)
|
|
302
|
+ path (_type_): A rel_path of the django page or the filesystem path to the page
|
|
303
|
+ history_version (_type_, optional): The history version of the page to be created
|
|
304
|
+ """
|
|
305
|
+ self._request = request
|
|
306
|
+ #
|
|
307
|
+ page_path = self.__page_path__(path)
|
|
308
|
+ system_page_path = self.__system_page_path__(path)
|
|
309
|
+ # Page
|
|
310
|
+ if request:
|
|
311
|
+ self._page = page_django(request, page_path, history_version=history_version)
|
|
312
|
+ else:
|
|
313
|
+ self._page = page_data(page_path, history_version=history_version)
|
|
314
|
+ self._page_meta = meta_data(page_path, history_version=history_version)
|
|
315
|
+ # System page
|
|
316
|
+ if request:
|
|
317
|
+ self._system_page = page_django(request, system_page_path)
|
|
318
|
+ else:
|
|
319
|
+ self._system_page = page_data(system_page_path)
|
|
320
|
+ self._system_meta_data = meta_data(system_page_path)
|
|
321
|
+
|
|
322
|
+ def __page_path__(self, path):
|
|
323
|
+ if path.startswith(settings.PAGES_ROOT):
|
|
324
|
+ # must be a filesystem path
|
|
325
|
+ return path
|
|
326
|
+ else:
|
|
327
|
+ # must be a relative url
|
|
328
|
+ return os.path.join(settings.PAGES_ROOT, path.replace("/", 2*SPLITCHAR))
|
|
329
|
+
|
|
330
|
+ def __system_page_path__(self, path):
|
|
331
|
+ return os.path.join(settings.SYSTEM_PAGES_ROOT, os.path.basename(path))
|
|
332
|
+
|
|
333
|
+ def __page_choose__(self):
|
|
334
|
+ if not self._page.is_available():
|
|
335
|
+ return self._system_page
|
|
336
|
+ else:
|
|
337
|
+ return self._page
|
|
338
|
+
|
|
339
|
+ def __meta_choose__(self):
|
|
340
|
+ if not self._page.is_available():
|
|
341
|
+ return self._system_meta_data
|
|
342
|
+ else:
|
|
343
|
+ return self._page_meta
|
|
344
|
+
|
|
345
|
+ def __store_history__(self):
|
|
346
|
+ if self._page.is_available():
|
|
347
|
+ try:
|
|
348
|
+ history_number = max(self._page.history_numbers_list()) + 1
|
|
349
|
+ except ValueError:
|
|
350
|
+ history_number = 1 # no history yet
|
|
351
|
+ self._page.store_to_history(history_number)
|
|
352
|
+ self._page_meta.store_to_history(history_number)
|
|
353
|
+
|
|
354
|
+ #
|
|
355
|
+ # meta_data
|
|
356
|
+ #
|
|
357
|
+ @property
|
|
358
|
+ def creation_time(self):
|
|
359
|
+ meta = self.__meta_choose__()
|
|
360
|
+ rv = meta.get(meta.KEY_CREATION_TIME)
|
|
361
|
+ return rv
|
|
362
|
+
|
|
363
|
+ @property
|
|
364
|
+ def modified_time(self):
|
|
365
|
+ meta = self.__meta_choose__()
|
|
366
|
+ rv = meta.get(meta.KEY_MODIFIED_TIME)
|
|
367
|
+ return rv
|
|
368
|
+
|
|
369
|
+ @property
|
|
370
|
+ def modified_user(self):
|
|
371
|
+ meta = self.__meta_choose__()
|
|
372
|
+ rv = meta.get(meta.KEY_MODIFIED_USER)
|
|
373
|
+ return rv
|
|
374
|
+
|
|
375
|
+ @property
|
|
376
|
+ def tags(self):
|
|
377
|
+ meta = self.__meta_choose__()
|
|
378
|
+ rv = meta.get(meta.KEY_TAGS)
|
|
379
|
+ return rv
|
|
380
|
+
|
|
381
|
+ #
|
|
382
|
+ # page
|
|
383
|
+ #
|
|
384
|
+ @property
|
|
385
|
+ def attachment_path(self):
|
|
386
|
+ page = self.__page_choose__()
|
|
387
|
+ rv = page.attachment_path
|
|
388
|
+ return rv
|
|
389
|
+
|
|
390
|
+ @property
|
|
391
|
+ def raw_page_src(self):
|
|
392
|
+ page = self.__page_choose__()
|
|
393
|
+ rv = page.raw_page_src
|
|
394
|
+ return rv
|
|
395
|
+
|
|
396
|
+ @property
|
|
397
|
+ def rel_path(self):
|
|
398
|
+ page = self.__page_choose__()
|
|
399
|
+ rv = page.rel_path
|
|
400
|
+ return rv
|
|
401
|
+
|
|
402
|
+ def render_meta(self):
|
|
403
|
+ page = self.__page_choose__()
|
|
404
|
+ rv = page.render_meta(self.creation_time, self.modified_time, self.modified_user, self.tags)
|
|
405
|
+ return rv
|
|
406
|
+
|
|
407
|
+ def render_to_html(self):
|
|
408
|
+ page = self.__page_choose__()
|
|
409
|
+ rv = page.render_to_html()
|
|
410
|
+ return rv
|
|
411
|
+
|
|
412
|
+ @property
|
|
413
|
+ def title(self):
|
|
414
|
+ page = self.__page_choose__()
|
|
415
|
+ rv = page.title
|
|
416
|
+ return rv
|
|
417
|
+
|
|
418
|
+ def update_page(self, txt, tags):
|
|
419
|
+ if self._page.update_required(txt):
|
|
420
|
+ # Store history
|
|
421
|
+ self.__store_history__()
|
|
422
|
+ # Update page
|
|
423
|
+ rv = self._page.update_page(txt)
|
|
424
|
+ # Update meta data
|
|
425
|
+ username = None
|
|
426
|
+ try:
|
|
427
|
+ if self._request.user.is_authenticated:
|
|
428
|
+ username = self._request.user.username
|
|
429
|
+ else:
|
|
430
|
+ logger.warning("Page edit without having a logged in user. This is not recommended. Check your access definitions!")
|
|
431
|
+ except AttributeError:
|
|
432
|
+ logger.exception("Page edit without having a request object. Check programming!")
|
|
433
|
+ self._page_meta.update(username, tags)
|
|
434
|
+ # Update search index
|
|
435
|
+ from pages.search import update_item
|
|
436
|
+ update_item(self)
|
|
437
|
+ return rv
|