-
Notifications
You must be signed in to change notification settings - Fork 134
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #265 from idlesign/feat/deep_customization
Deep tree handler customization support
- Loading branch information
Showing
10 changed files
with
112 additions
and
65 deletions.
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 |