Browse Source

refactoring new_rev of copy

Guénaël Muller 6 years ago
parent
commit
07c1facc41
3 changed files with 17 additions and 13 deletions
  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 View File

894
 
894
 
895
         content = item.copy(parent)
895
         content = item.copy(parent)
896
         # INFO - GM - 15-03-2018 - add "copy" revision
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
         if do_save:
906
         if do_save:
907
             self.save(content, ActionDescription.COPY, do_notify=do_notify)
907
             self.save(content, ActionDescription.COPY, do_notify=do_notify)
908
         return content
908
         return content
909
 
909
 
910
     def copy_children(self, origin_content: Content, new_content: Content):
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
             self.copy(child, new_content)
912
             self.copy(child, new_content)
913
 
913
 
914
     def move_recursively(self, item: Content,
914
     def move_recursively(self, item: Content,

+ 6 - 2
tracim/tracim/model/__init__.py View File

120
 
120
 
121
 
121
 
122
 @contextmanager
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
     Prepare context to update a Content. It will add a new updatable revision to the content.
128
     Prepare context to update a Content. It will add a new updatable revision to the content.
126
     :param content: Content instance to update
129
     :param content: Content instance to update
128
     """
131
     """
129
     with DBSession.no_autoflush:
132
     with DBSession.no_autoflush:
130
         try:
133
         try:
131
-            if inspect(content.revision).has_identity:
134
+            if force_create_new_revision \
135
+                    or inspect(content.revision).has_identity:
132
                 content.new_revision()
136
                 content.new_revision()
133
             RevisionsIntegrity.add_to_updatable(content.revision)
137
             RevisionsIntegrity.add_to_updatable(content.revision)
134
             yield content
138
             yield content

+ 1 - 1
tracim/tracim/model/data.py View File

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