Browse Source

Merge branch 'dev/233/files_on_disk' into dev/232/preview_generator

Adrien Panay 7 years ago
parent
commit
c9be711358

+ 8 - 6
tracim/migration/versions/69fb10c3d6f0_files_on_disk.py View File

@@ -6,18 +6,20 @@ Create Date: 2017-06-07 17:25:47.306472
6 6
 
7 7
 """
8 8
 
9
+from alembic import op
10
+from depot.fields.sqlalchemy import UploadedFileField
11
+import sqlalchemy as sa
12
+
9 13
 # revision identifiers, used by Alembic.
10 14
 revision = '69fb10c3d6f0'
11 15
 down_revision = 'c1cea4bbae16'
12 16
 
13
-from alembic import op
14
-import sqlalchemy as sa
15
-from depot.fields.sqlalchemy import UploadedFileField
16
-
17 17
 
18 18
 def upgrade():
19
-    op.add_column('content_revisions', sa.Column('depot_file_uid', UploadedFileField))
19
+    op.add_column('content_revisions',
20
+                  sa.Column('depot_file',
21
+                            UploadedFileField))
20 22
 
21 23
 
22 24
 def downgrade():
23
-    op.drop_column('content_revisions', 'depot_file_uid')
25
+    op.drop_column('content_revisions', 'depot_file')

+ 1 - 1
tracim/tracim/controllers/content.py View File

@@ -282,7 +282,7 @@ class UserWorkspaceFolderFileRestController(TIMWorkspaceContentRestController):
282 282
         file_name = get_valid_header_file_name(revision_to_send.file_name)
283 283
         tg.response.headers['Content-Disposition'] = \
284 284
             str('attachment; filename="{}"'.format(file_name))
285
-        return DepotManager.get().get(revision_to_send.depot_file_uid)
285
+        return DepotManager.get().get(revision_to_send.depot_file)
286 286
 
287 287
     def get_all_fake(self,
288 288
                      context_workspace: Workspace,

+ 3 - 3
tracim/tracim/lib/content.py View File

@@ -460,7 +460,7 @@ class ContentApi(object):
460 460
     #     :return: The corresponding Python file object
461 461
     #     """
462 462
     #     revision = self.get_one_revision(revision_id)
463
-    #     return DepotManager.get().get(revision.depot_file_uid)
463
+    #     return DepotManager.get().get(revision.depot_file)
464 464
 
465 465
     def get_one_revision_filepath(self, revision_id: int = None) -> str:
466 466
         """
@@ -475,7 +475,7 @@ class ContentApi(object):
475 475
         # python 3.6 PEP 526 -- Syntax for Variable Annotations
476 476
         # https://www.python.org/dev/peps/pep-0526/
477 477
         # dpt_file_path: str = dpt.get(dpt_stored_file)._file_path
478
-        dpt_stored_file = dpt.get(revision.depot_file_uid)
478
+        dpt_stored_file = dpt.get(revision.depot_file)
479 479
         dpt_file_path = dpt.get(dpt_stored_file)._file_path
480 480
 
481 481
         return dpt_file_path
@@ -880,7 +880,7 @@ class ContentApi(object):
880 880
         item.file_name = new_filename
881 881
         item.file_mimetype = new_mimetype
882 882
         item.file_content = new_file_content
883
-        item.revision.depot_file_uid = new_file_content
883
+        item.depot_file = new_file_content
884 884
         item.revision_type = ActionDescription.REVISION
885 885
         return item
886 886
 

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

@@ -546,7 +546,7 @@ class ContentRevisionRO(DeclarativeBase):
546 546
     )
547 547
     file_mimetype = Column(Unicode(255),  unique=False, nullable=False, default='')
548 548
     file_content = deferred(Column(LargeBinary(), unique=False, nullable=True))
549
-    depot_file_uid = Column(UploadedFileField, unique=False, nullable=True)
549
+    depot_file = Column(UploadedFileField, unique=False, nullable=True)
550 550
     properties = Column('properties', Text(), unique=False, nullable=False, default='')
551 551
 
552 552
     type = Column(Unicode(32), unique=False, nullable=False)
@@ -629,10 +629,10 @@ class ContentRevisionRO(DeclarativeBase):
629 629
             setattr(new_rev, column_name, column_value)
630 630
 
631 631
         new_rev.updated = datetime.utcnow()
632
-        # TODO APY tweaks here depot_file_uid
632
+        # TODO APY tweaks here depot_file
633 633
         # import pudb; pu.db
634
-        # new_rev.depot_file_uid = DepotManager.get().get(revision.depot_file_uid)
635
-        new_rev.depot_file_uid = revision.file_content
634
+        # new_rev.depot_file = DepotManager.get().get(revision.depot_file)
635
+        new_rev.depot_file = revision.file_content
636 636
 
637 637
         return new_rev
638 638
 
@@ -1058,12 +1058,12 @@ class Content(DeclarativeBase):
1058 1058
         return not self.is_archived and not self.is_deleted
1059 1059
 
1060 1060
     @property
1061
-    def depot_file_uid(self) -> UploadedFile:
1062
-        return self.revision.depot_file_uid
1061
+    def depot_file(self) -> UploadedFile:
1062
+        return self.revision.depot_file
1063 1063
 
1064
-    @depot_file_uid.setter
1065
-    def depot_file_uid(self, value):
1066
-        self.revision.depot_file_uid = value
1064
+    @depot_file.setter
1065
+    def depot_file(self, value):
1066
+        self.revision.depot_file = value
1067 1067
 
1068 1068
     def get_current_revision(self) -> ContentRevisionRO:
1069 1069
         if not self.revisions:

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

@@ -410,7 +410,7 @@ def serialize_node_for_page(content: Content, context: Context):
410 410
 
411 411
         if content.type == ContentType.File:
412 412
             dpt = DepotManager.get()
413
-            dpt_file = dpt.get(data_container.depot_file_uid)
413
+            dpt_file = dpt.get(data_container.depot_file)
414 414
             result.label = content.label
415 415
             result['file'] = DictLikeClass(
416 416
                 name=data_container.file_name,

+ 6 - 6
tracim/tracim/tests/models/test_content.py View File

@@ -198,16 +198,16 @@ class TestContent(TestStandard):
198 198
         )
199 199
         return content
200 200
 
201
-    def test_unit__content_depot_file_uid(self):
201
+    def test_unit__content_depot_file(self):
202 202
         """ Depot file access thought content property methods. """
203 203
         content = self._create_content_from_nothing()
204 204
         # tests uninitialized depot file
205
-        eq_(content.depot_file_uid, None)
205
+        eq_(content.depot_file, None)
206 206
         # initializes depot file
207
-        content.depot_file_uid = b'test'
207
+        content.depot_file = b'test'
208 208
         # tests initialized depot file
209
-        ok_(content.depot_file_uid)
209
+        ok_(content.depot_file)
210 210
         # tests type of initialized depot file
211
-        eq_(type(content.depot_file_uid), UploadedFile)
211
+        eq_(type(content.depot_file), UploadedFile)
212 212
         # tests content of initialized depot file
213
-        eq_(content.depot_file_uid.file.read(), b'test')
213
+        eq_(content.depot_file.file.read(), b'test')