Skip to content

Commit 1e9c244

Browse files
author
Steve Canny
committed
oxml: convert CT_NumPr to xmlchemy
1 parent 3af80a4 commit 1e9c244

2 files changed

Lines changed: 22 additions & 76 deletions

File tree

‎docx/oxml/parts/numbering.py‎

Lines changed: 21 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -67,80 +67,27 @@ class CT_NumPr(BaseOxmlElement):
6767
A ``<w:numPr>`` element, a container for numbering properties applied to
6868
a paragraph.
6969
"""
70-
def get_or_add_ilvl(self):
71-
"""
72-
Return the ilvl child element, newly added if not present.
73-
"""
74-
ilvl = self.ilvl
75-
if ilvl is None:
76-
ilvl = self._add_ilvl()
77-
return ilvl
78-
79-
def get_or_add_numId(self):
80-
"""
81-
Return the numId child element, newly added if not present.
82-
"""
83-
numId = self.numId
84-
if numId is None:
85-
numId = self._add_numId()
86-
return numId
87-
88-
@property
89-
def ilvl(self):
90-
return self.find(qn('w:ilvl'))
91-
92-
@ilvl.setter
93-
def ilvl(self, val):
94-
"""
95-
Get or add a <w:ilvl> child and set its ``w:val`` attribute to *val*.
96-
"""
97-
ilvl = self.get_or_add_ilvl()
98-
ilvl.val = val
99-
100-
@classmethod
101-
def new(cls):
102-
"""
103-
Return a new ``<w:numPr>`` element
104-
"""
105-
return OxmlElement('w:numPr')
106-
107-
@property
108-
def numId(self):
109-
return self.find(qn('w:numId'))
110-
111-
@numId.setter
112-
def numId(self, val):
113-
"""
114-
Get or add a <w:numId> child and set its ``w:val`` attribute to *val*.
115-
"""
116-
numId = self.get_or_add_numId()
117-
numId.val = val
118-
119-
def _add_ilvl(self, val=0):
120-
"""
121-
Return a newly added CT_DecimalNumber element having tagname 'w:ilvl'
122-
and ``val`` attribute set to *val*.
123-
"""
124-
ilvl = CT_DecimalNumber.new('w:ilvl', val)
125-
return self._insert_ilvl(ilvl)
126-
127-
def _add_numId(self, val=0):
128-
"""
129-
Return a newly added CT_DecimalNumber element having tagname
130-
'w:numId' and ``val`` attribute set to *val*.
131-
"""
132-
numId = CT_DecimalNumber.new('w:numId', val)
133-
return self._insert_numId(numId)
134-
135-
def _insert_ilvl(self, ilvl):
136-
return self.insert_element_before(
137-
ilvl, 'w:numId', 'w:numberingChange', 'w:ins'
138-
)
139-
140-
def _insert_numId(self, numId):
141-
return self.insert_element_before(
142-
numId, 'w:numberingChange', 'w:ins'
143-
)
70+
ilvl = ZeroOrOne('w:ilvl', successors=(
71+
'w:numId', 'w:numberingChange', 'w:ins'
72+
))
73+
numId = ZeroOrOne('w:numId', successors=('w:numberingChange', 'w:ins'))
74+
75+
# @ilvl.setter
76+
# def _set_ilvl(self, val):
77+
# """
78+
# Get or add a <w:ilvl> child and set its ``w:val`` attribute to *val*.
79+
# """
80+
# ilvl = self.get_or_add_ilvl()
81+
# ilvl.val = val
82+
83+
# @numId.setter
84+
# def numId(self, val):
85+
# """
86+
# Get or add a <w:numId> child and set its ``w:val`` attribute to
87+
# *val*.
88+
# """
89+
# numId = self.get_or_add_numId()
90+
# numId.val = val
14491

14592

14693
class CT_Numbering(BaseOxmlElement):

‎docx/oxml/text.py‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
from . import parse_xml, OxmlElement
99
from ..enum.text import WD_UNDERLINE
1010
from .ns import nsdecls, qn
11-
from .parts.numbering import CT_NumPr
1211
from .shared import CT_String
1312
from .xmlchemy import BaseOxmlElement
1413

@@ -190,7 +189,7 @@ def style(self, style):
190189
self.pStyle.val = style
191190

192191
def _add_numPr(self):
193-
numPr = CT_NumPr.new()
192+
numPr = OxmlElement('w:numPr')
194193
return self._insert_numPr(numPr)
195194

196195
def _add_pStyle(self, style):

0 commit comments

Comments
 (0)