Browse Source

refactor filename or label in create_content and others small things

Guénaël Muller 6 years ago
parent
commit
5741da68ce
3 changed files with 23 additions and 13 deletions
  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 View File

@@ -394,22 +394,23 @@ class ContentApi(object):
394 394
 
395 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 399
         assert content_type in ContentType.allowed_types()
400
+        assert not (label and filename)
399 401
 
400 402
         if content_type == ContentType.Folder and not label:
401 403
             label = self.generate_folder_label(workspace, parent)
402 404
 
403 405
         content = Content()
404 406
 
405
-        if label_is_filename:
407
+        if filename:
406 408
             # INFO - G.M - 2018-07-04 - File_name setting automatically
407 409
             # set label and file_extension
408 410
             content.file_name = label
409 411
         elif label:
410 412
             content.label = label
411
-
412
-        if not content.label:
413
+        else:
413 414
             if content_type == ContentType.Comment:
414 415
                 # INFO - G.M - 2018-07-16 - Default label for comments is
415 416
                 # empty string.
@@ -442,7 +443,7 @@ class ContentApi(object):
442 443
         item = Content()
443 444
         item.owner = self._user
444 445
         item.parent = parent
445
-        if parent and not workspace:
446
+        if not workspace:
446 447
             workspace = item.parent.workspace
447 448
         item.workspace = workspace
448 449
         item.type = ContentType.Comment
@@ -490,6 +491,11 @@ class ContentApi(object):
490 491
         try:
491 492
             content = base_request.one()
492 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 499
             raise ContentNotFound('Content "{}" not found in database'.format(content_id)) from exc  # nopep8
494 500
         return content
495 501
 

+ 1 - 2
tracim/lib/webdav/utils.py View File

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

+ 11 - 6
tracim/tests/library/test_content_api.py View File

@@ -506,7 +506,7 @@ class TestContentApi(DefaultTest):
506 506
             session=self.session,
507 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 510
         with new_revision(
511 511
             session=self.session,
512 512
             tm=transaction.manager,
@@ -546,7 +546,7 @@ class TestContentApi(DefaultTest):
546 546
             session=self.session,
547 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 550
         with new_revision(
551 551
             session=self.session,
552 552
             tm=transaction.manager,
@@ -656,6 +656,7 @@ class TestContentApi(DefaultTest):
656 656
             workspace,
657 657
             None,
658 658
             'folder a',
659
+            '',
659 660
             True
660 661
         )
661 662
         with self.session.no_autoflush:
@@ -692,6 +693,7 @@ class TestContentApi(DefaultTest):
692 693
             workspace2,
693 694
             None,
694 695
             'folder b',
696
+            '',
695 697
             True
696 698
         )
697 699
 
@@ -775,6 +777,7 @@ class TestContentApi(DefaultTest):
775 777
             workspace,
776 778
             None,
777 779
             'folder a',
780
+            '',
778 781
             True
779 782
         )
780 783
         with self.session.no_autoflush:
@@ -811,6 +814,7 @@ class TestContentApi(DefaultTest):
811 814
             workspace2,
812 815
             None,
813 816
             'folder b',
817
+            '',
814 818
             True
815 819
         )
816 820
         api2.copy(
@@ -891,6 +895,7 @@ class TestContentApi(DefaultTest):
891 895
             workspace,
892 896
             None,
893 897
             'folder a',
898
+            '',
894 899
             True
895 900
         )
896 901
         with self.session.no_autoflush:
@@ -2008,9 +2013,9 @@ class TestContentApi(DefaultTest):
2008 2013
             config=self.app_config,
2009 2014
         )
2010 2015
         a = api.create(ContentType.Folder, workspace, None,
2011
-                       'this is randomized folder', True)
2016
+                       'this is randomized folder', '', True)
2012 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 2020
         with new_revision(
2016 2021
             session=self.session,
@@ -2064,9 +2069,9 @@ class TestContentApi(DefaultTest):
2064 2069
             config=self.app_config,
2065 2070
         )
2066 2071
         a = api.create(ContentType.Folder, workspace, None,
2067
-                       'this is randomized folder', True)
2072
+                       'this is randomized folder', '', True)
2068 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 2076
         with new_revision(
2072 2077
             tm=transaction.manager,