|
@@ -17,6 +17,7 @@ class meta_data(dict):
|
17
|
17
|
KEY_CREATION_TIME = "creation_time"
|
18
|
18
|
KEY_MODIFIED_TIME = "modified_time"
|
19
|
19
|
KEY_MODIFIED_USER = "modified_user"
|
|
20
|
+ KEY_TAGS = "tags"
|
20
|
21
|
|
21
|
22
|
def __init__(self, meta_filename, page_exists):
|
22
|
23
|
self._meta_filename = meta_filename
|
|
@@ -38,11 +39,15 @@ class meta_data(dict):
|
38
|
39
|
if missing_keys and page_exists:
|
39
|
40
|
self.save()
|
40
|
41
|
|
41
|
|
- def update(self, username):
|
42
|
|
- self[self.KEY_MODIFIED_TIME] = int(time.time())
|
43
|
|
- self[self.KEY_MODIFIED_USER] = username
|
|
42
|
+ def update(self, username, tags):
|
|
43
|
+ if username:
|
|
44
|
+ self[self.KEY_MODIFIED_TIME] = int(time.time())
|
|
45
|
+ self[self.KEY_MODIFIED_USER] = username
|
|
46
|
+ if tags:
|
|
47
|
+ self[self.KEY_TAGS] = tags
|
44
|
48
|
#
|
45
|
|
- self.save()
|
|
49
|
+ if username or tags:
|
|
50
|
+ self.save()
|
46
|
51
|
|
47
|
52
|
def save(self):
|
48
|
53
|
with open(self._meta_filename, 'w') as fh:
|
|
@@ -87,7 +92,7 @@ class base_page(object):
|
87
|
92
|
shutil.copy(self.filename, os.path.join(history_folder, "%05d_%s" % (hist_number, self.PAGE_FILE_NAME)))
|
88
|
93
|
shutil.copy(self._meta_filename, os.path.join(history_folder, "%05d_%s" % (hist_number, self.META_FILE_NAME)))
|
89
|
94
|
|
90
|
|
- def update_page(self, page_txt):
|
|
95
|
+ def update_page(self, page_txt, tags):
|
91
|
96
|
from .search import update_item
|
92
|
97
|
if page_txt.replace("\r\n", "\n") != self.raw_page_src:
|
93
|
98
|
# Store page history
|
|
@@ -97,12 +102,14 @@ class base_page(object):
|
97
|
102
|
fstools.mkdir(os.path.dirname(self.filename))
|
98
|
103
|
with open(self.filename, 'w') as fh:
|
99
|
104
|
fh.write(page_txt)
|
100
|
|
- # update search index
|
101
|
|
- update_item(self)
|
102
|
105
|
# update metadata
|
103
|
|
- self._update_metadata()
|
104
|
|
- return True
|
105
|
|
- return False
|
|
106
|
+ page_changed = True
|
|
107
|
+ else:
|
|
108
|
+ page_changed = False
|
|
109
|
+ self._update_metadata(tags)
|
|
110
|
+ # update search index
|
|
111
|
+ update_item(self)
|
|
112
|
+ return page_changed
|
106
|
113
|
|
107
|
114
|
@property
|
108
|
115
|
def filename(self):
|
|
@@ -134,7 +141,7 @@ class base_page(object):
|
134
|
141
|
self._load_page_src()
|
135
|
142
|
return self._raw_page_src
|
136
|
143
|
|
137
|
|
- def _update_metadata(self):
|
|
144
|
+ def _update_metadata(self, tags):
|
138
|
145
|
username = None
|
139
|
146
|
try:
|
140
|
147
|
if self._request.user.is_authenticated:
|
|
@@ -143,7 +150,11 @@ class base_page(object):
|
143
|
150
|
logger.warning("Page edit without having a logged in user. This is not recommended. Check your access definitions!")
|
144
|
151
|
except AttributeError:
|
145
|
152
|
logger.exception("Page edit without having a request object. Check programming!")
|
146
|
|
- self._meta_data.update(username)
|
|
153
|
+ self._meta_data.update(username, tags)
|
|
154
|
+
|
|
155
|
+ @property
|
|
156
|
+ def page_tags(self):
|
|
157
|
+ return self._meta_data.get(self._meta_data.KEY_TAGS)
|
147
|
158
|
|
148
|
159
|
|
149
|
160
|
class creole_page(base_page):
|
|
@@ -168,10 +179,12 @@ class creole_page(base_page):
|
168
|
179
|
ctime = timestamp_to_datetime(self._request, self._meta_data.get(self._meta_data.KEY_CREATION_TIME)).strftime('%Y-%m-%d %H:%M')
|
169
|
180
|
mtime = timestamp_to_datetime(self._request, self._meta_data.get(self._meta_data.KEY_MODIFIED_TIME)).strftime('%Y-%m-%d %H:%M')
|
170
|
181
|
user = self._meta_data.get(self._meta_data.KEY_MODIFIED_USER)
|
|
182
|
+ tags = self._meta_data.get(self._meta_data.KEY_TAGS, "-")
|
171
|
183
|
#
|
172
|
184
|
meta = f'|{_("Created")}:|{ctime}|\n'
|
173
|
185
|
meta += f'|{_("Modified")}:|{mtime}|\n'
|
174
|
186
|
meta += f'|{_("Editor")}|{user}|\n'
|
|
187
|
+ meta += f'|{_("Tags")}|{tags}|\n'
|
175
|
188
|
meta += f'=== {_("Page content")}\n'
|
176
|
189
|
meta += '{{{\n%s\n}}}\n' % self.raw_page_src
|
177
|
190
|
#
|