File tree Expand file tree Collapse file tree 4 files changed +19
-2
lines changed Expand file tree Collapse file tree 4 files changed +19
-2
lines changed Original file line number Diff line number Diff line change @@ -14,7 +14,6 @@ Feature: Get comment properties
14
14
Then comment.author is the author of the comment
15
15
16
16
17
- @wip
18
17
Scenario : Comment.initials
19
18
Given a Comment object
20
19
Then comment.initials is the initials of the comment author
Original file line number Diff line number Diff line change @@ -62,3 +62,12 @@ def author(self) -> str:
62
62
def comment_id (self ) -> int :
63
63
"""The unique identifier of this comment."""
64
64
return self ._comment_elm .id
65
+
66
+ @property
67
+ def initials (self ) -> str | None :
68
+ """Read/write. The recorded initials of the comment author.
69
+
70
+ This attribute is optional in the XML, returns |None| if not set. Assigning |None| removes
71
+ any existing initials from the XML.
72
+ """
73
+ return self ._comment_elm .initials
Original file line number Diff line number Diff line change 3
3
from __future__ import annotations
4
4
5
5
from docx .oxml .simpletypes import ST_DecimalNumber , ST_String
6
- from docx .oxml .xmlchemy import BaseOxmlElement , RequiredAttribute , ZeroOrMore
6
+ from docx .oxml .xmlchemy import BaseOxmlElement , OptionalAttribute , RequiredAttribute , ZeroOrMore
7
7
8
8
9
9
class CT_Comments (BaseOxmlElement ):
@@ -36,3 +36,6 @@ class CT_Comment(BaseOxmlElement):
36
36
37
37
id : int = RequiredAttribute ("w:id" , ST_DecimalNumber ) # pyright: ignore[reportAssignmentType]
38
38
author : str = RequiredAttribute ("w:author" , ST_String ) # pyright: ignore[reportAssignmentType]
39
+ initials : str | None = OptionalAttribute ( # pyright: ignore[reportAssignmentType]
40
+ "w:initials" , ST_String
41
+ )
Original file line number Diff line number Diff line change @@ -107,6 +107,12 @@ def it_knows_its_author(self, comments_part_: Mock):
107
107
108
108
assert comment .author == "Steve Canny"
109
109
110
+ def it_knows_the_initials_of_its_author (self , comments_part_ : Mock ):
111
+ comment_elm = cast (CT_Comment , element ("w:comment{w:id=42,w:initials=SJC}" ))
112
+ comment = Comment (comment_elm , comments_part_ )
113
+
114
+ assert comment .initials == "SJC"
115
+
110
116
# -- fixtures --------------------------------------------------------------------------------
111
117
112
118
@pytest .fixture
You can’t perform that action at this time.
0 commit comments