소스 검색

Disables fully the feature of files in database

Adrien Panay 7 년 전
부모
커밋
410562bb3b

+ 12 - 2
tracim/tracim/fixtures/content.py 파일 보기

@@ -1,4 +1,6 @@
1 1
 # -*- coding: utf-8 -*-
2
+from depot.io.utils import FileIntent
3
+
2 4
 from tracim import model
3 5
 from tracim.fixtures import Fixture
4 6
 from tracim.fixtures.users_and_groups import Test
@@ -96,7 +98,11 @@ class Content(Fixture):
96 98
             do_save=False,
97 99
         )
98 100
         w1f1d1_txt.file_extension = '.txt'
99
-        w1f1d1_txt.file_content = b'w1f1d1 content'
101
+        w1f1d1_txt.depot_file = FileIntent(
102
+            b'w1f1d1 content',
103
+            'w1f1d1.txt',
104
+            'text/plain',
105
+        )
100 106
         self._session.add(w1f1d1_txt)
101 107
         w1f1d2_html = content_api.create(
102 108
             content_type=ContentType.File,
@@ -106,7 +112,11 @@ class Content(Fixture):
106 112
             do_save=False,
107 113
         )
108 114
         w1f1d2_html.file_extension = '.html'
109
-        w1f1d2_html.file_content = b'<p>w1f1d2 content</p>'
115
+        w1f1d2_html.depot_file = FileIntent(
116
+            b'<p>w1f1d2 content</p>',
117
+            'w1f1d2.html',
118
+            'text/html',
119
+        )
110 120
         self._session.add(w1f1d2_html)
111 121
         w1f1f1 = content_api.create(
112 122
             content_type=ContentType.Folder,

+ 7 - 3
tracim/tracim/lib/content.py 파일 보기

@@ -16,6 +16,7 @@ import tg
16 16
 from tg.i18n import ugettext as _
17 17
 
18 18
 from depot.manager import DepotManager
19
+from depot.io.utils import FileIntent
19 20
 
20 21
 import sqlalchemy
21 22
 from sqlalchemy.orm import aliased
@@ -873,12 +874,15 @@ class ContentApi(object):
873 874
         item.revision_type = ActionDescription.EDITION
874 875
         return item
875 876
 
876
-    def update_file_data(self, item: Content, new_filename: str, new_mimetype: str, new_file_content) -> Content:
877
+    def update_file_data(self, item: Content, new_filename: str, new_mimetype: str, new_content) -> Content:
877 878
         item.owner = self._user
878 879
         item.file_name = new_filename
879 880
         item.file_mimetype = new_mimetype
880
-        item.file_content = new_file_content
881
-        item.depot_file = new_file_content
881
+        item.depot_file = FileIntent(
882
+            new_content,
883
+            new_filename,
884
+            new_mimetype,
885
+        )
882 886
         item.revision_type = ActionDescription.REVISION
883 887
         return item
884 888
 

+ 4 - 4
tracim/tracim/lib/webdav/sql_resources.py 파일 보기

@@ -883,7 +883,7 @@ class File(DAVNonCollection):
883 883
         return "<DAVNonCollection: File (%d)>" % self.content.revision_id
884 884
 
885 885
     def getContentLength(self) -> int:
886
-        return len(self.content.file_content)
886
+        return self.content.depot_file.file.content_length
887 887
 
888 888
     def getContentType(self) -> str:
889 889
         return self.content.file_mimetype
@@ -899,7 +899,7 @@ class File(DAVNonCollection):
899 899
 
900 900
     def getContent(self):
901 901
         filestream = compat.BytesIO()
902
-        filestream.write(self.content.file_content)
902
+        filestream.write(self.content.depot_file.file.read())
903 903
         filestream.seek(0)
904 904
 
905 905
         return filestream
@@ -1028,13 +1028,13 @@ class HistoryFile(File):
1028 1028
 
1029 1029
     def getContent(self):
1030 1030
         filestream = compat.BytesIO()
1031
-        filestream.write(self.content_revision.file_content)
1031
+        filestream.write(self.content_revision.depot_file.file.read())
1032 1032
         filestream.seek(0)
1033 1033
 
1034 1034
         return filestream
1035 1035
 
1036 1036
     def getContentLength(self):
1037
-        return len(self.content_revision.file_content)
1037
+        return self.content_revision.depot_file.file.content_length
1038 1038
 
1039 1039
     def getContentType(self) -> str:
1040 1040
         return self.content_revision.file_mimetype

+ 7 - 34
tracim/tracim/model/data.py 파일 보기

@@ -26,6 +26,7 @@ from sqlalchemy.types import Text
26 26
 from sqlalchemy.types import Unicode
27 27
 from depot.fields.sqlalchemy import UploadedFileField
28 28
 from depot.fields.upload import UploadedFile
29
+from depot.io.utils import FileIntent
29 30
 
30 31
 from tracim.lib.utils import lazy_ugettext as l_
31 32
 from tracim.lib.exception import ContentRevisionUpdateError
@@ -545,23 +546,6 @@ class ContentRevisionRO(DeclarativeBase):
545 546
         server_default='',
546 547
     )
547 548
     file_mimetype = Column(Unicode(255),  unique=False, nullable=False, default='')
548
-    # TODO - A.P - 2017-07-03 - future removal planned
549
-    # file_content is to be replaced by depot_file, for now both coexist as
550
-    # this:
551
-    # - file_content data is still setted
552
-    # - newly created revision also gets depot_file data setted
553
-    # - access to the file of a revision from depot_file exclusively
554
-    # Here is the tasks workflow of the DB to OnDisk Switch :
555
-    # - Add depot_file "prototype style"
556
-    #   https://github.com/tracim/tracim/issues/233 - DONE
557
-    # - Integrate preview generator feature "prototype style"
558
-    #   https://github.com/tracim/tracim/issues/232 - DONE
559
-    # - Write migrations
560
-    #   https://github.com/tracim/tracim/issues/245
561
-    #   https://github.com/tracim/tracim/issues/246
562
-    # - Stabilize preview generator integration
563
-    #   includes dropping DB file content
564
-    #   https://github.com/tracim/tracim/issues/249
565 549
     file_content = deferred(Column(LargeBinary(), unique=False, nullable=True))
566 550
     # INFO - A.P - 2017-07-03 - Depot Doc
567 551
     # http://depot.readthedocs.io/en/latest/#attaching-files-to-models
@@ -592,7 +576,6 @@ class ContentRevisionRO(DeclarativeBase):
592 576
         'content_id',
593 577
         'created',
594 578
         'description',
595
-        'file_content',
596 579
         'file_mimetype',
597 580
         'file_extension',
598 581
         'is_archived',
@@ -649,10 +632,12 @@ class ContentRevisionRO(DeclarativeBase):
649 632
             setattr(new_rev, column_name, column_value)
650 633
 
651 634
         new_rev.updated = datetime.utcnow()
652
-        # TODO APY tweaks here depot_file
653
-        # import pudb; pu.db
654
-        # new_rev.depot_file = DepotManager.get().get(revision.depot_file)
655
-        new_rev.depot_file = revision.file_content
635
+        if revision.depot_file:
636
+            new_rev.depot_file = FileIntent(
637
+                revision.depot_file.file.read(),
638
+                revision.file_name,
639
+                revision.file_mimetype,
640
+            )
656 641
 
657 642
         return new_rev
658 643
 
@@ -861,18 +846,6 @@ class Content(DeclarativeBase):
861 846
         return ContentRevisionRO.file_mimetype
862 847
 
863 848
     @hybrid_property
864
-    def file_content(self):
865
-        return self.revision.file_content
866
-
867
-    @file_content.setter
868
-    def file_content(self, value):
869
-        self.revision.file_content = value
870
-
871
-    @file_content.expression
872
-    def file_content(cls) -> InstrumentedAttribute:
873
-        return ContentRevisionRO.file_content
874
-
875
-    @hybrid_property
876 849
     def _properties(self) -> str:
877 850
         return self.revision.properties
878 851
 

+ 1 - 1
tracim/tracim/tests/library/test_content_api.py 파일 보기

@@ -631,7 +631,7 @@ class TestContentApi(BaseTest, TestStandard):
631 631
                                                           updated.owner_id))
632 632
         eq_('this_is_a_page.html', updated.file_name)
633 633
         eq_('text/html', updated.file_mimetype)
634
-        eq_(b'<html>hello world</html>', updated.file_content)
634
+        eq_(b'<html>hello world</html>', updated.depot_file.file.read())
635 635
         eq_(ActionDescription.REVISION, updated.revision_type)
636 636
 
637 637
     def test_archive_unarchive(self):

+ 4 - 4
tracim/tracim/tests/library/test_webdav.py 파일 보기

@@ -307,9 +307,9 @@ class TestWebDav(TestStandard):
307 307
         ))
308 308
         eq_(
309 309
             b'hello\n',
310
-            result.content.file_content,
310
+            result.content.depot_file.file.read(),
311 311
             msg='fiel content should be "hello\n" but it is {0}'.format(
312
-                result.content.file_content
312
+                result.content.depot_file.file.read()
313 313
             )
314 314
         )
315 315
 
@@ -550,9 +550,9 @@ class TestWebDav(TestStandard):
550 550
         ))
551 551
         eq_(
552 552
             b'hello\n',
553
-            result.content.file_content,
553
+            result.content.depot_file.file.read(),
554 554
             msg='fiel content should be "hello\n" but it is {0}'.format(
555
-                result.content.file_content
555
+                result.content.depot_file.file.read()
556 556
             )
557 557
         )
558 558