-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Add custom properties support + unit-tests, feature-tests #580
Conversation
I haven't reviewed the PR but wanted to say thanks, @michael-koeller! |
@scanny any chance of this ever making it into a release? It would save me a lot of time. |
Merging this pull-request would we fantastic :) Thanks to all you guys for your job ! |
This would basically be the one and only reason for me to use python-docx (a lot). I consider this a killer feature :P Please merge (or give someone write access to merge :P). |
applied custom properties pr python-openxml#580 for storing private metadata within custom xml part.
I'm so excited for this to be merged to master. Thank you for the work. |
Seconded. I intend to use the stink out of this feature. THANK YOU!!! |
Can this be merged? |
Would be nice to have this feature merged in :) |
Can we get this merged please ? this has been open for a very long time now. |
Yes, I need it too, please merge. |
I need it as well. |
It's been four years. Merge, please. |
Add custom properties support + unit-tests, feature-tests #580
Hi, and thanks for this work! It looks rather complete, with the acceptance tests and unit tests already in! I've taken the freedom to rebase it and get rid of the merge commits; I believe I've preserved the correct authors and the tests still passes; @michael-koeller could you hard reset your branch to https://github.com/Apteryks/python-docx/tree/add-support-for-custom-properties, after verifying that it looks alright? After which we can look into some details. |
Hi, there is still a fix to do in the docstring that refers to pptx package instead of docx. See my review above. I'm glad you're taking the time and effort to keep the ball rolling! |
@Apteryks: Nice to hear, that things might get some traction after laying sleeping for so long. 👍 I just did a rebase on my pull request branch and I also added a separate feature branch in my repo wich I didn't do originally (don't know any more why). |
Hi @michael-koeller; for tidiness, could you please split the acceptance tests in a first commit, and everything else into a 2nd commit? Basically the way I did it here: https://github.com/Apteryks/python-docx/commits/add-support-for-custom-properties. |
Yes, sure. Done. |
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.
Hi! This looks good; I added a few minor comments.
Testing it though, I seem to trigger a hang this way:
from docx import Document
doc = Document('./features/steps/test_files/doc-customprops.docx')
list(doc.custom_properties)
Is this expected?
Thanks.
@michael-koeller One last thing: it'd be nice to add documentation for the new feature; it seems it'd go here: https://github.com/python-openxml/python-docx/blob/master/docs/api/document.rst, next to the CoreProperties section. A usage example would also be neat in https://raw.githubusercontent.com/python-openxml/python-docx/master/docs/index.rst, demonstrating how to access or set custom properties on a document. Thanks again! |
Almost there team can we push this through 👍 . Thanks for everyone's effort .. |
@celkas, what is this feature's estimated merge date? |
Could someone volunteer to test this branch? Especially w.r.t. #580 (review). |
@Apteryks I tested it on Windows. TL;DR same result that You have in #580 (review)
results in
|
|
@michael-koeller, easiest way I see is adding this code to
This would make it possible to iterate all custom props in a file. One needs to be aware, though, that the access to a custom-prop is (then) still not straight forward:
|
I just added the iteration support on custom properties, and added the relevant test cases for this feature. @celkas : Thanks for your input. My version is slightly different from yours. The iteration just returns the names of existing custom properties. To obtain the values, any client code may then explicitely access the getter method. |
@Apteryks, looks good to me. Tested the branch, everything OK. |
I might be a little out of my depth here, but I'm hoping someone can clear this up. With this, I was successfully able to get and update my custom property, which in my case was used for updating the existing header, but I noticed inside the actual word document nothing changed. The old header stayed the same. Then I checked, and it looks like I need to update the field even after I've updated the custom property itself. Does this functionality also handle updating the fields associated with the custom properties? |
I believe you have to refresh it manually in MSWord and save it to keep it displayed or set MSWord to update fields before printing Click FILE > Options > Display, and under Printing options, select the check box for Update fields before printing. see here Edit: Your header footers won't update unless you print the document with the option ↑. Maybe there is an option to refresh all programmatically; who knows? |
@michael-koeller, how do we remove or delete custom properties from <class 'docx.opc.customprops.CustomProperties'> object? |
Good question. That's not covered yet, as it seems. |
OK, should be working now. 😉 I also added corresponding test cases. |
@michael-koeller do we delete by setting the value (that does not work, as properties stay with empty values) to None or is there a way to access the delete function and get rid of the property altogether? |
Ah, sorry. I forgot to explain: custom_properties = document.custom_properties
# delete custom property "Foo"
del custom_properties["Foo"] The implementation is defensive. So if there's no custom property to the given key, nothing happens. |
What can be done to make this happen? |
I'm wondering, is there a reason the properties can't be kept in a true Python |
That's already part of the original implementation by @renejsum. The util class actually operates directly on the XML document tree. So while it might as well be possible to keep the custom properties in a plain dictionary, you would still need code to couple this dictionary instance to the XML elements in the tree. |
Hi everyone, and happy New Year! I've tested this again, and the test suite passes ( My preference would be to have a better emulated dict-like interface (where you could call .values() or .items()), but that can always be added later. @scanny in case you haven't followed this discussion, this is about adding support for custom properties; the change includes tests and has been reviewed and manually tested by myself and others. |
Lads, what is the roadmap for merging it into the repo? |
@scanny as the owner of the project has the last word; it seems they haven't had the time to catch up with this thread yet; I hope they do, as it seems to be a much wanted feature :-). |
@michael-koeller and @Apteryks I appreciate all the hard work on this. I've just implemented this new functionality at work and it's a huge time saver. Very well done! |
Any news about it ? |
@michael-koeller @scanny, any updates? |
@michael-koeller it seems there are conflicts to be resolved? At least that is a new message appearing in my feed... |
Hi All, apologies for the long hiatus. This PR looks potentially viable. @michael-koeller are you still interested in driving this? I have a few comments but no sense getting into that if it's gone stale. It would need a rebase given all the changes in getting from Let me know if you're still interested and we can see where to go next. |
Hi Steve,
great to hear from you. And yes, I’m still interested in having this feature merged into the project.
I hope that I find the time today to make a rebase on my MR.
If you have any further comments, please don’t hesitate to hand them to me.
… Am 20.10.2023 um 20:10 schrieb Steve Canny ***@***.***>:
Hi All, apologies for the long hiatus. This PR looks potentially viable. @michael-koeller <https://github.com/michael-koeller> are you still interested in driving this?
I have a few comments but no sense getting into that if it's gone stale. I would need a rebase given all the changes in getting from 0.8 to 1.0 and dropping the Python 2 support.
Let me know if you're still interested and we can see where to go next.
—
Reply to this email directly, view it on GitHub <#580 (comment)>, or unsubscribe <https://github.com/notifications/unsubscribe-auth/AALKVDLURDK276XLZAA5RJTYAK5ATAVCNFSM4GGBZMT2U5DIOJSWCZC7NNSXTN2JONZXKZKDN5WW2ZLOOQ5TCNZXGMYTQMRWGEZQ>.
You are receiving this because you were mentioned.
|
515f8ef
to
8e05650
Compare
Oops. While working on a rebase for this MR, I accidentally closed this MR. Sorry for any inconveniences. 😞 As a possible followup, I created a new MR on my recent branch: #1273 |
Hi @scanny,
I patched the implementation of @renejsum into a new fork and added the missing test cases.
Along the way I also added proper type handling for string/int/bool properties.
Regards,
Michael