瀏覽代碼

fix fiename option in content creation

Guénaël Muller 6 年之前
父節點
當前提交
929234f6fd
共有 2 個文件被更改,包括 16 次插入8 次删除
  1. 14 7
      tracim/lib/core/content.py
  2. 2 1
      tracim/lib/webdav/utils.py

+ 14 - 7
tracim/lib/core/content.py 查看文件

@@ -393,21 +393,28 @@ class ContentApi(object):
393 393
 
394 394
         return result
395 395
 
396
-    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:
396
+    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 397
         assert content_type in ContentType.allowed_types()
398 398
 
399 399
         if content_type == ContentType.Folder and not label:
400 400
             label = self.generate_folder_label(workspace, parent)
401 401
 
402 402
         content = Content()
403
-        if label:
404
-            content.label = label
405
-        elif filename:
406
-            # TODO - G.M - 2018-07-04 - File_name setting automatically
403
+
404
+        if label_is_filename:
405
+            # INFO - G.M - 2018-07-04 - File_name setting automatically
407 406
             # set label and file_extension
408 407
             content.file_name = label
409
-        else:
410
-            raise EmptyLabelNotAllowed()
408
+        elif label:
409
+            content.label = label
410
+
411
+        if not content.label:
412
+            if content_type == ContentType.Comment:
413
+                # INFO - G.M - 2018-07-16 - Default label for comments is
414
+                # empty string.
415
+                content.label = ''
416
+            else:
417
+                raise EmptyLabelNotAllowed('Content of this type should have a valid label')  # nopep8
411 418
 
412 419
         content.owner = self._user
413 420
         content.parent = parent

+ 2 - 1
tracim/lib/webdav/utils.py 查看文件

@@ -176,10 +176,11 @@ 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
-            filename=self._file_name,
179
+            label=self._file_name,
180 180
             content_type=ContentType.File,
181 181
             workspace=self._workspace,
182 182
             parent=self._parent,
183
+            label_is_filename=True,
183 184
             is_temporary=is_temporary
184 185
         )
185 186