Преглед изворни кода

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

master
Dirk Alders пре 2 месеци
родитељ
комит
7b8a5d0305
1 измењених фајлова са 32 додато и 22 уклоњено
  1. 32
    22
      pages/page.py

+ 32
- 22
pages/page.py Прегледај датотеку

@@ -54,17 +54,25 @@ class meta_data(dict):
54 54
     def history_filename(self, history_version):
55 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 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 77
     def save(self):
70 78
         if self._history_version:
@@ -421,21 +429,23 @@ class page_wrapped(object):
421 429
         return rv
422 430
 
423 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 434
             # Store history
426 435
             self.__store_history__()
427
-            # Update page
428
-            rv = self._page.update_page(txt)
429
-            # Update meta data
430 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 449
             # Update search index
440 450
             from pages.search import update_item
441 451
             update_item(self)

Loading…
Откажи
Сачувај