-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Header and Footer #291
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
Closed
Header and Footer #291
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -126,7 +126,15 @@ def related_hdrftr_body(self, rId): | |
Return the |HeaderFooterBody| object corresponding to the related | ||
part identified by *rId*. | ||
""" | ||
raise NotImplementedError | ||
part = self.get_related_part(rId) | ||
return part.body | ||
|
||
def get_related_part(self, rId): | ||
""" HACK this isn't strictly necessary | ||
just adding it because it seems much easier to mock than | ||
self.rels.related_parts | ||
""" | ||
return self.rels.related_parts[rId] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's keep this all in one piece. Here's an example of how I mocked # in pptx.parts.presentation ------
def related_slide(self, rId):
"""
Return the |Slide| object for the related |SlidePart| corresponding
to relationship key *rId*.
"""
return self.related_parts[rId].slide
# the rest of this is in tests.parts.test_presentation ------
def it_provides_access_to_a_related_slide(self, slide_fixture):
prs_part, rId, slide_ = slide_fixture
slide = prs_part.related_slide(rId)
prs_part.related_parts.__getitem__.assert_called_once_with(rId)
assert slide is slide_
@pytest.fixture
def slide_fixture(self, slide_, related_parts_prop_):
prs_part = PresentationPart(None, None, None, None)
rId = 'rId42'
related_parts_ = related_parts_prop_.return_value
related_parts_.__getitem__.return_value.slide = slide_
return prs_part, rId, slide_
@pytest.fixture
def related_parts_prop_(self, request):
return property_mock(request, PresentationPart, 'related_parts') |
||
|
||
def save(self, path_or_stream): | ||
""" | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
# encoding: utf-8 | ||
|
||
""" | ||
|HeaderPart| and closely related objects | ||
""" | ||
|
||
from __future__ import ( | ||
absolute_import, division, print_function, unicode_literals | ||
) | ||
|
||
from ..header import HeaderFooterBody | ||
from ..opc.part import XmlPart | ||
|
||
|
||
class HeaderPart(XmlPart): | ||
@property | ||
def body(self): | ||
""" | ||
A |HeaderFooterBody| proxy object for the `w:hdr` element in this part, | ||
""" | ||
# TODO write CT_HeaderFooter | ||
# element = CT_HeaderFooter(self.element) | ||
# how to access parent here? is it necessary? | ||
return HeaderFooterBody(self.element, None) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@scanny ok here's my first stab at a unit test. I modeled it after this commit:
bddd27a
The first acceptance test passes now, as does this unittest!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is great @eupharis :)
I'll have a look this evening and move this along :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@scanny ok i think this commit is good to go. unittest and acceptance test both pass.
I went with ElementProxy instead of object for Header's base class just so that I could pass sectPr without writing some custom init method.
Class methods should be in alphabetical order. I didn't worry about tests though. It seems like those aren't alphabetical currently.
lazyproperty
is cool! I have done that a bunch but I never thought to abstract it out like that. Super handy.What's next? The end goal right now is "Able to load a document with header text and access that text" right?
Lots of steps to get there.