Browse Source

Disables fully the feature of files in database

Adrien Panay 7 years ago
parent
commit
410562bb3b

+ 12 - 2
tracim/tracim/fixtures/content.py View File

1
 # -*- coding: utf-8 -*-
1
 # -*- coding: utf-8 -*-
2
+from depot.io.utils import FileIntent
3
+
2
 from tracim import model
4
 from tracim import model
3
 from tracim.fixtures import Fixture
5
 from tracim.fixtures import Fixture
4
 from tracim.fixtures.users_and_groups import Test
6
 from tracim.fixtures.users_and_groups import Test
96
             do_save=False,
98
             do_save=False,
97
         )
99
         )
98
         w1f1d1_txt.file_extension = '.txt'
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
         self._session.add(w1f1d1_txt)
106
         self._session.add(w1f1d1_txt)
101
         w1f1d2_html = content_api.create(
107
         w1f1d2_html = content_api.create(
102
             content_type=ContentType.File,
108
             content_type=ContentType.File,
106
             do_save=False,
112
             do_save=False,
107
         )
113
         )
108
         w1f1d2_html.file_extension = '.html'
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
         self._session.add(w1f1d2_html)
120
         self._session.add(w1f1d2_html)
111
         w1f1f1 = content_api.create(
121
         w1f1f1 = content_api.create(
112
             content_type=ContentType.Folder,
122
             content_type=ContentType.Folder,

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

16
 from tg.i18n import ugettext as _
16
 from tg.i18n import ugettext as _
17
 
17
 
18
 from depot.manager import DepotManager
18
 from depot.manager import DepotManager
19
+from depot.io.utils import FileIntent
19
 
20
 
20
 import sqlalchemy
21
 import sqlalchemy
21
 from sqlalchemy.orm import aliased
22
 from sqlalchemy.orm import aliased
873
         item.revision_type = ActionDescription.EDITION
874
         item.revision_type = ActionDescription.EDITION
874
         return item
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
         item.owner = self._user
878
         item.owner = self._user
878
         item.file_name = new_filename
879
         item.file_name = new_filename
879
         item.file_mimetype = new_mimetype
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
         item.revision_type = ActionDescription.REVISION
886
         item.revision_type = ActionDescription.REVISION
883
         return item
887
         return item
884
 
888
 

+ 4 - 4
tracim/tracim/lib/webdav/sql_resources.py View File

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

+ 7 - 34
tracim/tracim/model/data.py View File

26
 from sqlalchemy.types import Unicode
26
 from sqlalchemy.types import Unicode
27
 from depot.fields.sqlalchemy import UploadedFileField
27
 from depot.fields.sqlalchemy import UploadedFileField
28
 from depot.fields.upload import UploadedFile
28
 from depot.fields.upload import UploadedFile
29
+from depot.io.utils import FileIntent
29
 
30
 
30
 from tracim.lib.utils import lazy_ugettext as l_
31
 from tracim.lib.utils import lazy_ugettext as l_
31
 from tracim.lib.exception import ContentRevisionUpdateError
32
 from tracim.lib.exception import ContentRevisionUpdateError
545
         server_default='',
546
         server_default='',
546
     )
547
     )
547
     file_mimetype = Column(Unicode(255),  unique=False, nullable=False, default='')
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
     file_content = deferred(Column(LargeBinary(), unique=False, nullable=True))
549
     file_content = deferred(Column(LargeBinary(), unique=False, nullable=True))
566
     # INFO - A.P - 2017-07-03 - Depot Doc
550
     # INFO - A.P - 2017-07-03 - Depot Doc
567
     # http://depot.readthedocs.io/en/latest/#attaching-files-to-models
551
     # http://depot.readthedocs.io/en/latest/#attaching-files-to-models
592
         'content_id',
576
         'content_id',
593
         'created',
577
         'created',
594
         'description',
578
         'description',
595
-        'file_content',
596
         'file_mimetype',
579
         'file_mimetype',
597
         'file_extension',
580
         'file_extension',
598
         'is_archived',
581
         'is_archived',
649
             setattr(new_rev, column_name, column_value)
632
             setattr(new_rev, column_name, column_value)
650
 
633
 
651
         new_rev.updated = datetime.utcnow()
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
         return new_rev
642
         return new_rev
658
 
643
 
861
         return ContentRevisionRO.file_mimetype
846
         return ContentRevisionRO.file_mimetype
862
 
847
 
863
     @hybrid_property
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
     def _properties(self) -> str:
849
     def _properties(self) -> str:
877
         return self.revision.properties
850
         return self.revision.properties
878
 
851
 

+ 1 - 1
tracim/tracim/tests/library/test_content_api.py View File

631
                                                           updated.owner_id))
631
                                                           updated.owner_id))
632
         eq_('this_is_a_page.html', updated.file_name)
632
         eq_('this_is_a_page.html', updated.file_name)
633
         eq_('text/html', updated.file_mimetype)
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
         eq_(ActionDescription.REVISION, updated.revision_type)
635
         eq_(ActionDescription.REVISION, updated.revision_type)
636
 
636
 
637
     def test_archive_unarchive(self):
637
     def test_archive_unarchive(self):

+ 4 - 4
tracim/tracim/tests/library/test_webdav.py View File

307
         ))
307
         ))
308
         eq_(
308
         eq_(
309
             b'hello\n',
309
             b'hello\n',
310
-            result.content.file_content,
310
+            result.content.depot_file.file.read(),
311
             msg='fiel content should be "hello\n" but it is {0}'.format(
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
         ))
550
         ))
551
         eq_(
551
         eq_(
552
             b'hello\n',
552
             b'hello\n',
553
-            result.content.file_content,
553
+            result.content.depot_file.file.read(),
554
             msg='fiel content should be "hello\n" but it is {0}'.format(
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