|
@@ -7,6 +7,7 @@ import logging
|
7
|
7
|
from pages import messages, url_page
|
8
|
8
|
import mycreole
|
9
|
9
|
import os
|
|
10
|
+import shutil
|
10
|
11
|
import time
|
11
|
12
|
from users.models import get_userprofile
|
12
|
13
|
import zoneinfo
|
|
@@ -53,6 +54,7 @@ class meta_data(dict):
|
53
|
54
|
class base_page(object):
|
54
|
55
|
PAGE_FILE_NAME = 'page'
|
55
|
56
|
META_FILE_NAME = 'meta.json'
|
|
57
|
+ HISTORY_FOLDER_NAME = 'history'
|
56
|
58
|
SPLITCHAR = ":"
|
57
|
59
|
|
58
|
60
|
def __init__(self, path):
|
|
@@ -72,17 +74,37 @@ class base_page(object):
|
72
|
74
|
except FileNotFoundError:
|
73
|
75
|
self._raw_page_src = ""
|
74
|
76
|
|
|
77
|
+ def _store_history(self):
|
|
78
|
+ history_folder = os.path.join(self._path, self.HISTORY_FOLDER_NAME)
|
|
79
|
+ # create folder if needed
|
|
80
|
+ fstools.mkdir(history_folder)
|
|
81
|
+ # identify last_history number
|
|
82
|
+ flist = fstools.filelist(history_folder)
|
|
83
|
+ flist.sort()
|
|
84
|
+ if flist:
|
|
85
|
+ hist_number = int(os.path.basename(flist[-1])[:5]) + 1
|
|
86
|
+ else:
|
|
87
|
+ hist_number = 1
|
|
88
|
+ # copy file to history folder
|
|
89
|
+ shutil.copy(self.filename, os.path.join(history_folder, "%05d_%s" % (hist_number, self.PAGE_FILE_NAME)))
|
|
90
|
+ shutil.copy(self._meta_filename, os.path.join(history_folder, "%05d_%s" % (hist_number, self.META_FILE_NAME)))
|
|
91
|
+
|
75
|
92
|
def update_page(self, page_txt):
|
76
|
93
|
from .search import update_item
|
77
|
|
- #
|
78
|
|
- folder = os.path.dirname(self.filename)
|
79
|
|
- if not os.path.exists(folder):
|
80
|
|
- fstools.mkdir(folder)
|
81
|
|
- with open(self.filename, 'w') as fh:
|
82
|
|
- fh.write(page_txt)
|
83
|
|
- update_item(self)
|
84
|
|
- #
|
85
|
|
- self._update_metadata()
|
|
94
|
+ if page_txt.replace("\r\n", "\n") != self.raw_page_src:
|
|
95
|
+ # Store page history
|
|
96
|
+ if self.raw_page_src:
|
|
97
|
+ self._store_history()
|
|
98
|
+ # save the new page content
|
|
99
|
+ fstools.mkdir(os.path.dirname(self.filename))
|
|
100
|
+ with open(self.filename, 'w') as fh:
|
|
101
|
+ fh.write(page_txt)
|
|
102
|
+ # update search index
|
|
103
|
+ update_item(self)
|
|
104
|
+ # update metadata
|
|
105
|
+ self._update_metadata()
|
|
106
|
+ return True
|
|
107
|
+ return False
|
86
|
108
|
|
87
|
109
|
@property
|
88
|
110
|
def filename(self):
|