浏览代码

Changes the field name of on disk file

Adrien Panay 7 年前
父节点
当前提交
719a59c3a6

+ 8 - 6
tracim/migration/versions/69fb10c3d6f0_files_on_disk.py 查看文件

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
 # revision identifiers, used by Alembic.
13
 # revision identifiers, used by Alembic.
10
 revision = '69fb10c3d6f0'
14
 revision = '69fb10c3d6f0'
11
 down_revision = 'c1cea4bbae16'
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
 def upgrade():
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
 def downgrade():
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 查看文件

251
         file_name = get_valid_header_file_name(revision_to_send.file_name)
251
         file_name = get_valid_header_file_name(revision_to_send.file_name)
252
         tg.response.headers['Content-Disposition'] = \
252
         tg.response.headers['Content-Disposition'] = \
253
             str('attachment; filename="{}"'.format(file_name))
253
             str('attachment; filename="{}"'.format(file_name))
254
-        return DepotManager.get().get(revision_to_send.depot_file_uid)
254
+        return DepotManager.get().get(revision_to_send.depot_file)
255
 
255
 
256
 
256
 
257
     def get_all_fake(self, context_workspace: Workspace, context_folder: Content):
257
     def get_all_fake(self, context_workspace: Workspace, context_folder: Content):

+ 4 - 4
tracim/tracim/lib/content.py 查看文件

460
     #     :return: The corresponding Python file object
460
     #     :return: The corresponding Python file object
461
     #     """
461
     #     """
462
     #     revision = self.get_one_revision(revision_id)
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
     def get_one_revision_filepath(self, revision_id: int = None) -> str:
465
     def get_one_revision_filepath(self, revision_id: int = None) -> str:
466
         """
466
         """
475
         # python 3.6 PEP 526 -- Syntax for Variable Annotations
475
         # python 3.6 PEP 526 -- Syntax for Variable Annotations
476
         # https://www.python.org/dev/peps/pep-0526/
476
         # https://www.python.org/dev/peps/pep-0526/
477
         # dpt_path: str = dpt.storage_path
477
         # dpt_path: str = dpt.storage_path
478
-        # dpt_file_dir: str = item.revision.depot_file_uid.file_id
478
+        # dpt_file_dir: str = item.revision.depot_file.file_id
479
         # dpt_file_path: str = dpt_path + dpt_file_dir + dpt_file_name
479
         # dpt_file_path: str = dpt_path + dpt_file_dir + dpt_file_name
480
         dpt_path = dpt.storage_path
480
         dpt_path = dpt.storage_path
481
-        dpt_file_dir = revision.depot_file_uid.file_id
481
+        dpt_file_dir = revision.depot_file.file_id
482
         dpt_file_path = '{0}{1}/file'.format(dpt_path, dpt_file_dir)
482
         dpt_file_path = '{0}{1}/file'.format(dpt_path, dpt_file_dir)
483
 
483
 
484
         return file_from_depot.name
484
         return file_from_depot.name
883
         item.file_name = new_filename
883
         item.file_name = new_filename
884
         item.file_mimetype = new_mimetype
884
         item.file_mimetype = new_mimetype
885
         item.file_content = new_file_content
885
         item.file_content = new_file_content
886
-        item.revision.depot_file_uid = new_file_content
886
+        item.depot_file = new_file_content
887
         item.revision_type = ActionDescription.REVISION
887
         item.revision_type = ActionDescription.REVISION
888
         return item
888
         return item
889
 
889
 

+ 9 - 9
tracim/tracim/model/data.py 查看文件

546
     )
546
     )
547
     file_mimetype = Column(Unicode(255),  unique=False, nullable=False, default='')
547
     file_mimetype = Column(Unicode(255),  unique=False, nullable=False, default='')
548
     file_content = deferred(Column(LargeBinary(), unique=False, nullable=True))
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
     properties = Column('properties', Text(), unique=False, nullable=False, default='')
550
     properties = Column('properties', Text(), unique=False, nullable=False, default='')
551
 
551
 
552
     type = Column(Unicode(32), unique=False, nullable=False)
552
     type = Column(Unicode(32), unique=False, nullable=False)
629
             setattr(new_rev, column_name, column_value)
629
             setattr(new_rev, column_name, column_value)
630
 
630
 
631
         new_rev.updated = datetime.utcnow()
631
         new_rev.updated = datetime.utcnow()
632
-        # TODO APY tweaks here depot_file_uid
632
+        # TODO APY tweaks here depot_file
633
         # import pudb; pu.db
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
         return new_rev
637
         return new_rev
638
 
638
 
1058
         return not self.is_archived and not self.is_deleted
1058
         return not self.is_archived and not self.is_deleted
1059
 
1059
 
1060
     @property
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
     def get_current_revision(self) -> ContentRevisionRO:
1068
     def get_current_revision(self) -> ContentRevisionRO:
1069
         if not self.revisions:
1069
         if not self.revisions:

+ 1 - 1
tracim/tracim/model/serializers.py 查看文件

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

+ 6 - 6
tracim/tracim/tests/models/test_content.py 查看文件

198
         )
198
         )
199
         return content
199
         return content
200
 
200
 
201
-    def test_unit__content_depot_file_uid(self):
201
+    def test_unit__content_depot_file(self):
202
         """ Depot file access thought content property methods. """
202
         """ Depot file access thought content property methods. """
203
         content = self._create_content_from_nothing()
203
         content = self._create_content_from_nothing()
204
         # tests uninitialized depot file
204
         # tests uninitialized depot file
205
-        eq_(content.depot_file_uid, None)
205
+        eq_(content.depot_file, None)
206
         # initializes depot file
206
         # initializes depot file
207
-        content.depot_file_uid = b'test'
207
+        content.depot_file = b'test'
208
         # tests initialized depot file
208
         # tests initialized depot file
209
-        ok_(content.depot_file_uid)
209
+        ok_(content.depot_file)
210
         # tests type of initialized depot file
210
         # tests type of initialized depot file
211
-        eq_(type(content.depot_file_uid), UploadedFile)
211
+        eq_(type(content.depot_file), UploadedFile)
212
         # tests content of initialized depot file
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')