浏览代码

doc,typing,cleaning

Guénaël Muller 6 年前
父节点
当前提交
b84e5c091c
共有 3 个文件被更改,包括 51 次插入36 次删除
  1. 5 1
      tracim/lib/utils/request.py
  2. 6 2
      tracim/models/contents.py
  3. 40 33
      tracim/models/context_models.py

+ 5 - 1
tracim/lib/utils/request.py 查看文件

16
 from tracim.lib.utils.authorization import JSONDecodeError
16
 from tracim.lib.utils.authorization import JSONDecodeError
17
 
17
 
18
 from tracim.models import User
18
 from tracim.models import User
19
-from tracim.models.data import Workspace, Content
19
+from tracim.models.data import Workspace
20
+from tracim.models.data import Content
20
 
21
 
21
 
22
 
22
 class TracimRequest(Request):
23
 class TracimRequest(Request):
205
         """
206
         """
206
         Get current content from request
207
         Get current content from request
207
         :param user: User who want to check the workspace
208
         :param user: User who want to check the workspace
209
+        :param workspace: Workspace of the content
210
+        :param content: comment is related to this content
208
         :param request: pyramid request
211
         :param request: pyramid request
209
         :return: current content
212
         :return: current content
210
         """
213
         """
243
         """
246
         """
244
         Get current content from request
247
         Get current content from request
245
         :param user: User who want to check the workspace
248
         :param user: User who want to check the workspace
249
+        :param workspace: Workspace of the content
246
         :param request: pyramid request
250
         :param request: pyramid request
247
         :return: current content
251
         :return: current content
248
         """
252
         """

+ 6 - 2
tracim/models/contents.py 查看文件

2
 import typing
2
 import typing
3
 from enum import Enum
3
 from enum import Enum
4
 
4
 
5
-from tracim.exceptions import ContentStatusNotExist, ContentTypeNotExist
6
-from tracim.models.applications import html_documents, _file, thread, markdownpluspage
5
+from tracim.exceptions import ContentTypeNotExist
6
+from tracim.exceptions import ContentStatusNotExist
7
+from tracim.models.applications import html_documents
8
+from tracim.models.applications import _file
9
+from tracim.models.applications import thread
10
+from tracim.models.applications import markdownpluspage
7
 
11
 
8
 
12
 
9
 ####
13
 ####

+ 40 - 33
tracim/models/context_models.py 查看文件

17
 
17
 
18
 class MoveParams(object):
18
 class MoveParams(object):
19
     """
19
     """
20
-    Json body params for move action
20
+    Json body params for move action model
21
     """
21
     """
22
-    def __init__(self, new_parent_id: str, new_workspace_id: str = None):
22
+    def __init__(self, new_parent_id: str, new_workspace_id: str = None) -> None:  # nopep8
23
         self.new_parent_id = new_parent_id
23
         self.new_parent_id = new_parent_id
24
         self.new_workspace_id = new_workspace_id
24
         self.new_workspace_id = new_workspace_id
25
 
25
 
26
 
26
 
27
 class LoginCredentials(object):
27
 class LoginCredentials(object):
28
     """
28
     """
29
-    Login credentials model for login
29
+    Login credentials model for login model
30
     """
30
     """
31
 
31
 
32
-    def __init__(self, email: str, password: str):
32
+    def __init__(self, email: str, password: str) -> None:
33
         self.email = email
33
         self.email = email
34
         self.password = password
34
         self.password = password
35
 
35
 
36
 
36
 
37
 class WorkspaceAndContentPath(object):
37
 class WorkspaceAndContentPath(object):
38
     """
38
     """
39
-    Paths params with workspace id and content_id
39
+    Paths params with workspace id and content_id model
40
     """
40
     """
41
-    def __init__(self, workspace_id: int, content_id: int):
41
+    def __init__(self, workspace_id: int, content_id: int) -> None:
42
         self.content_id = content_id
42
         self.content_id = content_id
43
         self.workspace_id = workspace_id
43
         self.workspace_id = workspace_id
44
 
44
 
45
 
45
 
46
 class CommentPath(object):
46
 class CommentPath(object):
47
     """
47
     """
48
-    Paths params with workspace id and content_id
48
+    Paths params with workspace id and content_id and comment_id model
49
     """
49
     """
50
-    def __init__(self, workspace_id: int, content_id: int, comment_id: int):
50
+    def __init__(
51
+        self,
52
+        workspace_id: int,
53
+        content_id: int,
54
+        comment_id: int
55
+    ) -> None:
51
         self.content_id = content_id
56
         self.content_id = content_id
52
         self.workspace_id = workspace_id
57
         self.workspace_id = workspace_id
53
         self.comment_id = comment_id
58
         self.comment_id = comment_id
63
             show_archived: int = 0,
68
             show_archived: int = 0,
64
             show_deleted: int = 0,
69
             show_deleted: int = 0,
65
             show_active: int = 1,
70
             show_active: int = 1,
66
-    ):
71
+    ) -> None:
67
         self.parent_id = parent_id
72
         self.parent_id = parent_id
68
         self.show_archived = bool(show_archived)
73
         self.show_archived = bool(show_archived)
69
         self.show_deleted = bool(show_deleted)
74
         self.show_deleted = bool(show_deleted)
78
             self,
83
             self,
79
             label: str,
84
             label: str,
80
             content_type: str,
85
             content_type: str,
81
-    ):
86
+    ) -> None:
82
         self.label = label
87
         self.label = label
83
         self.content_type = content_type
88
         self.content_type = content_type
84
 
89
 
90
     def __init__(
95
     def __init__(
91
             self,
96
             self,
92
             raw_content: str,
97
             raw_content: str,
93
-    ):
98
+    ) -> None:
94
         self.raw_content = raw_content
99
         self.raw_content = raw_content
95
 
100
 
96
 
101
 
101
     def __init__(
106
     def __init__(
102
             self,
107
             self,
103
             status: str,
108
             status: str,
104
-    ):
109
+    ) -> None:
105
         self.status = status
110
         self.status = status
106
 
111
 
107
 
112
 
113
             self,
118
             self,
114
             label: str,
119
             label: str,
115
             raw_content: str,
120
             raw_content: str,
116
-    ):
121
+    ) -> None:
117
         self.label = label
122
         self.label = label
118
         self.raw_content = raw_content
123
         self.raw_content = raw_content
119
 
124
 
126
             self,
131
             self,
127
             label: str,
132
             label: str,
128
             raw_content: str,
133
             raw_content: str,
129
-    ):
134
+    ) -> None:
130
         self.label = label
135
         self.label = label
131
         self.raw_content = raw_content
136
         self.raw_content = raw_content
132
 
137
 
367
     @property
372
     @property
368
     def content_type(self) -> str:
373
     def content_type(self) -> str:
369
         content_type = ContentType(self.content.type)
374
         content_type = ContentType(self.content.type)
370
-        if content_type:
371
-            return content_type.slug
372
-        else:
373
-            return None
375
+        return content_type.slug
374
 
376
 
375
     @property
377
     @property
376
     def sub_content_types(self) -> typing.List[str]:
378
     def sub_content_types(self) -> typing.List[str]:
377
-        return [_type.slug for _type in self.content.get_allowed_content_types()]
379
+        return [_type.slug for _type in self.content.get_allowed_content_types()]  # nopep8
378
 
380
 
379
     @property
381
     @property
380
     def status(self) -> str:
382
     def status(self) -> str:
444
     Interface to get Content data and Content data related to context.
446
     Interface to get Content data and Content data related to context.
445
     """
447
     """
446
 
448
 
447
-    def __init__(self, content: ContentRevisionRO, dbsession: Session, config: CFG):
448
-        self.revision = content
449
+    def __init__(self, content_revision: ContentRevisionRO, dbsession: Session, config: CFG):
450
+        assert content_revision is not None
451
+        self.revision = content_revision
449
         self.dbsession = dbsession
452
         self.dbsession = dbsession
450
         self.config = config
453
         self.config = config
451
 
454
 
491
         return self.revision.status
494
         return self.revision.status
492
 
495
 
493
     @property
496
     @property
494
-    def is_archived(self):
497
+    def is_archived(self) -> bool:
495
         return self.revision.is_archived
498
         return self.revision.is_archived
496
 
499
 
497
     @property
500
     @property
498
-    def is_deleted(self):
501
+    def is_deleted(self) -> bool:
499
         return self.revision.is_deleted
502
         return self.revision.is_deleted
500
 
503
 
501
     @property
504
     @property
502
-    def raw_content(self):
505
+    def raw_content(self) -> str:
503
         return self.revision.description
506
         return self.revision.description
504
 
507
 
505
     @property
508
     @property
506
-    def author(self):
509
+    def author(self) -> UserInContext:
507
         return UserInContext(
510
         return UserInContext(
508
             dbsession=self.dbsession,
511
             dbsession=self.dbsession,
509
             config=self.config,
512
             config=self.config,
511
         )
514
         )
512
 
515
 
513
     @property
516
     @property
514
-    def revision_id(self):
517
+    def revision_id(self) -> int:
515
         return self.revision.revision_id
518
         return self.revision.revision_id
516
 
519
 
517
     @property
520
     @property
518
-    def created(self):
521
+    def created(self) -> datetime:
519
         return self.updated
522
         return self.updated
520
 
523
 
521
     @property
524
     @property
522
-    def modified(self):
525
+    def modified(self) -> datetime:
523
         return self.updated
526
         return self.updated
524
 
527
 
525
     @property
528
     @property
526
-    def updated(self):
529
+    def updated(self) -> datetime:
527
         return self.revision.updated
530
         return self.revision.updated
528
 
531
 
529
     @property
532
     @property
530
-    def next_revision(self):
533
+    def next_revision(self) -> typing.Optional[ContentRevisionRO]:
534
+        """
535
+        Get next revision (later revision)
536
+        :return: next_revision
537
+        """
531
         next_revision = None
538
         next_revision = None
532
         revisions = self.revision.node.revisions
539
         revisions = self.revision.node.revisions
533
         # INFO - G.M - 2018-06-177 - Get revisions more recent that
540
         # INFO - G.M - 2018-06-177 - Get revisions more recent that
548
             return None
555
             return None
549
 
556
 
550
     @property
557
     @property
551
-    def comments_ids(self):
558
+    def comments_ids(self) -> typing.List[int]:
552
         comments = self.revision.node.get_comments()
559
         comments = self.revision.node.get_comments()
553
         # INFO - G.M - 2018-06-177 - Get comments more recent than revision.
560
         # INFO - G.M - 2018-06-177 - Get comments more recent than revision.
554
         revisions_comments = [
561
         revisions_comments = [
575
 
582
 
576
     # Context-related
583
     # Context-related
577
     @property
584
     @property
578
-    def show_in_ui(self):
585
+    def show_in_ui(self) -> bool:
579
         # TODO - G.M - 31-05-2018 - Enable Show_in_ui params
586
         # TODO - G.M - 31-05-2018 - Enable Show_in_ui params
580
         # if false, then do not show content in the treeview.
587
         # if false, then do not show content in the treeview.
581
         # This may his maybe used for specific contents or for sub-contents.
588
         # This may his maybe used for specific contents or for sub-contents.
584
         return True
591
         return True
585
 
592
 
586
     @property
593
     @property
587
-    def slug(self):
594
+    def slug(self) -> str:
588
         return slugify(self.revision.label)
595
         return slugify(self.revision.label)