-
Notifications
You must be signed in to change notification settings - Fork 130
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
Deep tree handler customization support #265
Merged
Merged
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 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 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,52 @@ | ||
Tree handler customization | ||
========================== | ||
|
||
What to do if a time comes and you need some fancy stuff done to tree items that | ||
*django-sitetree* does not support? | ||
|
||
.. _tree-custom: | ||
|
||
It might be that you need some special tree items ordering in a menu, or you want to render | ||
in a huge site tree with all articles titles that are described by one tree item in Django admin, | ||
or god knows what else. | ||
|
||
*django-sitetree* can facilitate on that as it allows tree handler customization | ||
with the help of `SITETREE_CLS` setting. | ||
|
||
1. Subclass `sitetreeapp.SiteTree` and place that class into a separate module for convenience. | ||
2. Override methods you need for customization (usually `.apply_hook()`). | ||
3. Define `SITETREE_CLS` in `settings.py` of your project, showing it a dotted path to subclass. | ||
|
||
|
||
Example: | ||
|
||
.. code-block:: python | ||
|
||
# myapp/mysitetree.py | ||
from sitetree.sitetreeapp import SiteTree | ||
|
||
|
||
class MySiteTree(SiteTree): | ||
"""Custom tree handler to test deep customization abilities.""" | ||
|
||
def apply_hook(self, items, sender): | ||
# Suppose we want to process only menu child items. | ||
if tree_sender == 'menu.children': | ||
# Lets add 'Hooked: ' to resolved titles of every item. | ||
for item in tree_items: | ||
item.title_resolved = 'Hooked: %s' % item.title_resolved | ||
# Return items list mutated or not. | ||
return tree_items | ||
|
||
# pyproject/settings.py | ||
... | ||
|
||
SITETREE_CLS = 'myapp.mysitetree.MySiteTree' | ||
|
||
... | ||
|
||
|
||
|
||
.. note:: | ||
|
||
You might also be interested in the notes on :ref:`Overriding SiteTree Admin representation <admin-ext>`. |
This file was deleted.
Oops, something went wrong.
This file contains 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 |
---|---|---|
|
@@ -56,7 +56,7 @@ Table of Contents | |
management | ||
templatesmod | ||
tagsadv | ||
hooks | ||
customization | ||
admin | ||
forms | ||
models | ||
|
This file contains 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 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 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 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 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 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,7 @@ | ||
from sitetree.sitetreeapp import SiteTree | ||
|
||
|
||
class MySiteTree(SiteTree): | ||
"""Custom tree handler to test deep customization abilities.""" | ||
|
||
customized = True |
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.
From that description I don't really understand how .apply_hook() comes into play.
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.
.appy_hook()
is most generic — this description doesn't necessarily cover your very case from #263Rather you override
.get_permissions()
.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.
Yeah, thats right. I just wanted to point out, that somebody who reads this sentence might not understand if he has to overwrite .apply_hook() or if this is just one option to deal with a usecase.
But I guess if people are doing such things they must have a look at the code and then everything is pretty self-explanatory anyways.
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.
I see. If you can propose a better wording, I'd be glad.
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.
I'd be a little bit more explicit, like this:
You can now overwrite
.apply_hook()
to manipulate values at pre-defined hooks. You can also overwrite any other methods to customize to your exact needs.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.
Done. Thank you.