Browse Source

Fix: storage and index update, if page or meta data changed

master
Dirk Alders 2 months ago
parent
commit
7b8a5d0305
1 changed files with 32 additions and 22 deletions
  1. 32
    22
      pages/page.py

+ 32
- 22
pages/page.py View File

54
     def history_filename(self, history_version):
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))
55
         return os.path.join(self._path, HISTORY_FOLDER_NAME, "%05d_%s" % (history_version, self.META_FILE_NAME))
56
 
56
 
57
+    def update_required(self, tags):
58
+        return tags != self.get(self.KEY_TAGS)
59
+
57
     def update(self, username, tags):
60
     def update(self, username, tags):
58
-        if username:
59
-            self[self.KEY_MODIFIED_TIME] = int(time.time())
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]
63
-        if tags:
64
-            self[self.KEY_TAGS] = tags
65
-        #
66
-        if username or tags:
67
-            self.save()
61
+        if self._history_version:
62
+            logger.error("A history version %05d can not be updated!", self._history_version)
63
+            return False
64
+        else:
65
+            if username:
66
+                self[self.KEY_MODIFIED_TIME] = int(time.time())
67
+                self[self.KEY_MODIFIED_USER] = username
68
+                if self.KEY_CREATION_TIME not in self:
69
+                    self[self.KEY_CREATION_TIME] = self[self.KEY_MODIFIED_TIME]
70
+            if tags:
71
+                self[self.KEY_TAGS] = tags
72
+            #
73
+            if username or tags:
74
+                self.save()
75
+            return True
68
 
76
 
69
     def save(self):
77
     def save(self):
70
         if self._history_version:
78
         if self._history_version:
421
         return rv
429
         return rv
422
 
430
 
423
     def update_page(self, txt, tags):
431
     def update_page(self, txt, tags):
424
-        if self._page.update_required(txt):
432
+        if self._page.update_required(txt) or self._page_meta.update_required(tags):
433
+            rv = False
425
             # Store history
434
             # Store history
426
             self.__store_history__()
435
             self.__store_history__()
427
-            # Update page
428
-            rv = self._page.update_page(txt)
429
-            # Update meta data
430
             username = None
436
             username = None
431
-            try:
432
-                if self._request.user.is_authenticated:
433
-                    username = self._request.user.username
434
-                else:
435
-                    logger.warning("Page edit without having a logged in user. This is not recommended. Check your access definitions!")
436
-            except AttributeError:
437
-                logger.exception("Page edit without having a request object. Check programming!")
438
-            self._page_meta.update(username, tags)
437
+            if self._page.update_required(txt):
438
+                # Update page
439
+                rv |= self._page.update_page(txt)
440
+                # Identify username, to update meta
441
+                try:
442
+                    if self._request.user.is_authenticated:
443
+                        username = self._request.user.username
444
+                    else:
445
+                        logger.warning("Page edit without having a logged in user. This is not recommended. Check your access definitions!")
446
+                except AttributeError:
447
+                    logger.exception("Page edit without having a request object. Check programming!")
448
+            rv |= self._page_meta.update(username, tags)
439
             # Update search index
449
             # Update search index
440
             from pages.search import update_item
450
             from pages.search import update_item
441
             update_item(self)
451
             update_item(self)

Loading…
Cancel
Save