Преглед на файлове

refactoring new_rev of copy

Guénaël Muller преди 6 години
родител
ревизия
07c1facc41
променени са 3 файла, в които са добавени 17 реда и са изтрити 13 реда
  1. 10 10
      tracim/tracim/lib/content.py
  2. 6 2
      tracim/tracim/model/__init__.py
  3. 1 1
      tracim/tracim/model/data.py

+ 10 - 10
tracim/tracim/lib/content.py Целия файл

@@ -894,21 +894,21 @@ class ContentApi(object):
894 894
 
895 895
         content = item.copy(parent)
896 896
         # INFO - GM - 15-03-2018 - add "copy" revision
897
-        content.new_revision()
898
-        content.parent = parent
899
-        content.workspace = workspace
900
-        content.label = label
901
-        content.revision_type = ActionDescription.COPY
902
-        content.properties['origin'] = {
903
-            'content': item.id,
904
-            'revision': item.last_revision.revision_id,
905
-        }
897
+        with new_revision(content, force_create_new_revision=True) as rev:
898
+            rev.parent = parent
899
+            rev.workspace = workspace
900
+            rev.label = label
901
+            rev.revision_type = ActionDescription.COPY
902
+            rev.properties['origin'] = {
903
+                'content': item.id,
904
+                'revision': item.last_revision.revision_id,
905
+            }
906 906
         if do_save:
907 907
             self.save(content, ActionDescription.COPY, do_notify=do_notify)
908 908
         return content
909 909
 
910 910
     def copy_children(self, origin_content: Content, new_content: Content):
911
-        for child in origin_content.children:
911
+       for child in origin_content.children:
912 912
             self.copy(child, new_content)
913 913
 
914 914
     def move_recursively(self, item: Content,

+ 6 - 2
tracim/tracim/model/__init__.py Целия файл

@@ -120,7 +120,10 @@ def prevent_content_revision_delete(session: Session, flush_context: UOWTransact
120 120
 
121 121
 
122 122
 @contextmanager
123
-def new_revision(content: Content) -> Content:
123
+def new_revision(
124
+        content: Content,
125
+        force_create_new_revision: bool=False,
126
+) -> Content:
124 127
     """
125 128
     Prepare context to update a Content. It will add a new updatable revision to the content.
126 129
     :param content: Content instance to update
@@ -128,7 +131,8 @@ def new_revision(content: Content) -> Content:
128 131
     """
129 132
     with DBSession.no_autoflush:
130 133
         try:
131
-            if inspect(content.revision).has_identity:
134
+            if force_create_new_revision \
135
+                    or inspect(content.revision).has_identity:
132 136
                 content.new_revision()
133 137
             RevisionsIntegrity.add_to_updatable(content.revision)
134 138
             yield content

+ 1 - 1
tracim/tracim/model/data.py Целия файл

@@ -1117,7 +1117,7 @@ class Content(DeclarativeBase):
1117 1117
         revisions = sorted(self.revisions, key=lambda revision: revision.revision_id)
1118 1118
         return revisions[-1]
1119 1119
 
1120
-    def new_revision(self) -> None:
1120
+    def new_revision(self) -> ContentRevisionRO:
1121 1121
         """
1122 1122
         Return and assign to this content a new revision.
1123 1123
         If it's a new content, revision is totally new.