Skip to content

WIP: Feature Header & Footer #571

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed

Conversation

ondrej-111
Copy link
Contributor

@ondrej-111 ondrej-111 commented Nov 12, 2018

implemented header and footer by spec but without actions in: https://github.com/python-openxml/python-docx/blob/master/docs/dev/analysis/features/header.rst

linked to issue: #104

in progress: implement add/remove_header/footer

@Benjamin-T
Copy link

Benjamin-T commented Nov 18, 2018

@ondrej-111 first of all: Nice work!

I've looked briefly at your code and I've noticed that you chose to create two complex types: one for the header and one for the footer. When I was investigating the parts - complex types for the Bookmarks (PR #445 ) I found that the header and footer share the same comlex type: CT_HdrFtr. This make sense as you expect identical behavior for the header and the footer.

see wml.xsd:

python-docx/ref/xsd/wml.xsd

Lines 3441 to 3442 in 94623ff

<xsd:element name="hdr" type="CT_HdrFtr"/>
<xsd:element name="ftr" type="CT_HdrFtr"/>

which would mean that:

register_element_cls('w:hdr', CT_Header)
register_element_cls('w:ftr', CT_Footer)

should refer to CT_HdrFtr

And I think it's required that in order to get a PR merged, It should start with the analysis document based on this document, create an acceptance test.

When this acceptance test is run using behave --stop it will fail at some missing code; this code should be added as next commit.

However, I would first try and create some working version a spike and based on this continue towards the TDD stage where each separate method appears in a separate commit together with its unit tests.

regards,

Ben

edit:
Not sure where these should go; but my guess is that they are somehow related?

python-docx/ref/xsd/wml.xsd

Lines 1591 to 1602 in 94623ff

<xsd:complexType name="CT_HdrFtrRef">
<xsd:complexContent>
<xsd:extension base="CT_Rel">
<xsd:attribute name="type" type="ST_HdrFtr" use="required"/>
</xsd:extension>
</xsd:complexContent>
</xsd:complexType>
<xsd:group name="EG_HdrFtrReferences">
<xsd:choice>
<xsd:element name="headerReference" type="CT_HdrFtrRef" minOccurs="0"/>
<xsd:element name="footerReference" type="CT_HdrFtrRef" minOccurs="0"/>
</xsd:choice>

my guess is:
w:headerReference should be linked to the CT_HdrFtrRef, and the different relation types belong to the specific 'simpletype' ST_HdrFtr which enumerates default, even and first :

python-docx/ref/xsd/wml.xsd

Lines 1576 to 1582 in 94623ff

<xsd:simpleType name="ST_HdrFtr">
<xsd:restriction base="xsd:string">
<xsd:enumeration value="even"/>
<xsd:enumeration value="default"/>
<xsd:enumeration value="first"/>
</xsd:restriction>
</xsd:simpleType>

@ondrej-111
Copy link
Contributor Author

@Benjamin-T Thank You for your help.

Analysis document already exist here:
/dev/analysis/features/header.rst.

I think I can close this PR and create new branch like feature/header_footer with right work flow where I will start with acceptance tests and then implement code and unit tests step by step...

@ondrej-111 ondrej-111 closed this Nov 24, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants