소스 검색

refactor filename or label in create_content and others small things

Guénaël Muller 6 년 전
부모
커밋
5741da68ce
3개의 변경된 파일23개의 추가작업 그리고 13개의 파일을 삭제
  1. 11 5
      tracim/lib/core/content.py
  2. 1 2
      tracim/lib/webdav/utils.py
  3. 11 6
      tracim/tests/library/test_content_api.py

+ 11 - 5
tracim/lib/core/content.py 파일 보기

394
 
394
 
395
         return result
395
         return result
396
 
396
 
397
-    def create(self, content_type: str, workspace: Workspace, parent: Content=None, label: str ='', label_is_filename: bool = False, do_save=False, is_temporary: bool=False, do_notify=True) -> Content:
397
+    def create(self, content_type: str, workspace: Workspace, parent: Content=None, label: str ='', filename: str = '', do_save=False, is_temporary: bool=False, do_notify=True) -> Content:
398
+        # TODO - G.M - 2018-07-16 - raise Exception instead of assert
398
         assert content_type in ContentType.allowed_types()
399
         assert content_type in ContentType.allowed_types()
400
+        assert not (label and filename)
399
 
401
 
400
         if content_type == ContentType.Folder and not label:
402
         if content_type == ContentType.Folder and not label:
401
             label = self.generate_folder_label(workspace, parent)
403
             label = self.generate_folder_label(workspace, parent)
402
 
404
 
403
         content = Content()
405
         content = Content()
404
 
406
 
405
-        if label_is_filename:
407
+        if filename:
406
             # INFO - G.M - 2018-07-04 - File_name setting automatically
408
             # INFO - G.M - 2018-07-04 - File_name setting automatically
407
             # set label and file_extension
409
             # set label and file_extension
408
             content.file_name = label
410
             content.file_name = label
409
         elif label:
411
         elif label:
410
             content.label = label
412
             content.label = label
411
-
412
-        if not content.label:
413
+        else:
413
             if content_type == ContentType.Comment:
414
             if content_type == ContentType.Comment:
414
                 # INFO - G.M - 2018-07-16 - Default label for comments is
415
                 # INFO - G.M - 2018-07-16 - Default label for comments is
415
                 # empty string.
416
                 # empty string.
442
         item = Content()
443
         item = Content()
443
         item.owner = self._user
444
         item.owner = self._user
444
         item.parent = parent
445
         item.parent = parent
445
-        if parent and not workspace:
446
+        if not workspace:
446
             workspace = item.parent.workspace
447
             workspace = item.parent.workspace
447
         item.workspace = workspace
448
         item.workspace = workspace
448
         item.type = ContentType.Comment
449
         item.type = ContentType.Comment
490
         try:
491
         try:
491
             content = base_request.one()
492
             content = base_request.one()
492
         except NoResultFound as exc:
493
         except NoResultFound as exc:
494
+            # TODO - G.M - 2018-07-16 - Add better support for all different
495
+            # error case who can happened here
496
+            # like content doesn't exist, wrong parent, wrong content_type, wrong workspace,
497
+            # wrong access to this workspace, wrong base filter according
498
+            # to content_status.
493
             raise ContentNotFound('Content "{}" not found in database'.format(content_id)) from exc  # nopep8
499
             raise ContentNotFound('Content "{}" not found in database'.format(content_id)) from exc  # nopep8
494
         return content
500
         return content
495
 
501
 

+ 1 - 2
tracim/lib/webdav/utils.py 파일 보기

176
         is_temporary = self._file_name.startswith('.~') or self._file_name.startswith('~')
176
         is_temporary = self._file_name.startswith('.~') or self._file_name.startswith('~')
177
 
177
 
178
         file = self._api.create(
178
         file = self._api.create(
179
-            label=self._file_name,
179
+            filename=self._file_name,
180
             content_type=ContentType.File,
180
             content_type=ContentType.File,
181
             workspace=self._workspace,
181
             workspace=self._workspace,
182
             parent=self._parent,
182
             parent=self._parent,
183
-            label_is_filename=True,
184
             is_temporary=is_temporary
183
             is_temporary=is_temporary
185
         )
184
         )
186
 
185
 

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

506
             session=self.session,
506
             session=self.session,
507
             config=self.app_config,
507
             config=self.app_config,
508
         )
508
         )
509
-        c = api.create(ContentType.Folder, workspace, None, 'parent', True)
509
+        c = api.create(ContentType.Folder, workspace, None, 'parent', '', True)
510
         with new_revision(
510
         with new_revision(
511
             session=self.session,
511
             session=self.session,
512
             tm=transaction.manager,
512
             tm=transaction.manager,
546
             session=self.session,
546
             session=self.session,
547
             config=self.app_config,
547
             config=self.app_config,
548
         )
548
         )
549
-        c = api.create(ContentType.Folder, workspace, None, 'parent', True)
549
+        c = api.create(ContentType.Folder, workspace, None, 'parent', '', True)
550
         with new_revision(
550
         with new_revision(
551
             session=self.session,
551
             session=self.session,
552
             tm=transaction.manager,
552
             tm=transaction.manager,
656
             workspace,
656
             workspace,
657
             None,
657
             None,
658
             'folder a',
658
             'folder a',
659
+            '',
659
             True
660
             True
660
         )
661
         )
661
         with self.session.no_autoflush:
662
         with self.session.no_autoflush:
692
             workspace2,
693
             workspace2,
693
             None,
694
             None,
694
             'folder b',
695
             'folder b',
696
+            '',
695
             True
697
             True
696
         )
698
         )
697
 
699
 
775
             workspace,
777
             workspace,
776
             None,
778
             None,
777
             'folder a',
779
             'folder a',
780
+            '',
778
             True
781
             True
779
         )
782
         )
780
         with self.session.no_autoflush:
783
         with self.session.no_autoflush:
811
             workspace2,
814
             workspace2,
812
             None,
815
             None,
813
             'folder b',
816
             'folder b',
817
+            '',
814
             True
818
             True
815
         )
819
         )
816
         api2.copy(
820
         api2.copy(
891
             workspace,
895
             workspace,
892
             None,
896
             None,
893
             'folder a',
897
             'folder a',
898
+            '',
894
             True
899
             True
895
         )
900
         )
896
         with self.session.no_autoflush:
901
         with self.session.no_autoflush:
2008
             config=self.app_config,
2013
             config=self.app_config,
2009
         )
2014
         )
2010
         a = api.create(ContentType.Folder, workspace, None,
2015
         a = api.create(ContentType.Folder, workspace, None,
2011
-                       'this is randomized folder', True)
2016
+                       'this is randomized folder', '', True)
2012
         p = api.create(ContentType.Page, workspace, a,
2017
         p = api.create(ContentType.Page, workspace, a,
2013
-                       'this is randomized label content', True)
2018
+                       'this is randomized label content', '', True)
2014
 
2019
 
2015
         with new_revision(
2020
         with new_revision(
2016
             session=self.session,
2021
             session=self.session,
2064
             config=self.app_config,
2069
             config=self.app_config,
2065
         )
2070
         )
2066
         a = api.create(ContentType.Folder, workspace, None,
2071
         a = api.create(ContentType.Folder, workspace, None,
2067
-                       'this is randomized folder', True)
2072
+                       'this is randomized folder', '', True)
2068
         p = api.create(ContentType.Page, workspace, a,
2073
         p = api.create(ContentType.Page, workspace, a,
2069
-                       'this is dummy label content', True)
2074
+                       'this is dummy label content', '', True)
2070
 
2075
 
2071
         with new_revision(
2076
         with new_revision(
2072
             tm=transaction.manager,
2077
             tm=transaction.manager,