Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use django-sitetree?

I am trying to use django-sitetree but I don't understand how to do step 3 which is:

"Go to Django Admin site and add some trees and tree items."

How to make a sitetree in the admin panel? I believe the first step is to choose an alias for the "Site Tree" you are about to add.

The next step is to add "Site Tree Item". On this page you have to choose parent, title, url. Considering my app is dynamic with url structure like this localhost:8000/categoryname/entryname how do I choose urls?

By the way I am trying to add breadcrumbs in my templates.

like image 550
Sushi Avatar asked Jan 22 '11 08:01

Sushi


1 Answers

To create a tree:

  1. Goto site administration panel;
  2. Click +Add near 'Site Trees';
  3. Enter alias for your sitetree, e.g. 'maintree'.
    You'll address your tree by this alias in template tags;
  4. Push 'Add Site Tree Item';
  5. Create first item:

    Parent: As it is root item that would have no parent.
    Title: Let it be 'My site'.
    URL: This URL is static, so put here '/'.

  6. Create second item (that one would handle 'categoryname' from your 'categoryname/entryname'):

    Parent: Choose 'My site' item from step 5.
    Title: Put here 'Category #{{ category.id }}'.
    URL: Put named URL 'category-detailed category.name'.
    In 'Additional settings': check 'URL as Pattern' checkbox.

  7. Create third item (that one would handle 'entryname' from your 'categoryname/entryname'):

    Parent: Choose 'Category #{{ category.id }}' item from step 6.
    Title: Put here 'Entry #{{ entry.id }}'.
    URL: Put named URL 'entry-detailed category.name entry.name'.
    In 'Additional settings': check 'URL as Pattern' checkbox.

  8. Put '{% load sitetree %}' into yor template to have access to sitetree tags.
  9. Put '{% sitetree_menu from "maintree" %}' into your template to render menu.
  10. Put '{% sitetree_breadcrumbs from "maintree" %}' into your template to render breadcrumbs.

Steps 6 and 7 need some clarifications:

  • In titles we use Django template variables, which would be resolved just like they do in your templates.

    E.g.: You made your view for 'categoryname' (let's call it 'detailed_category') to pass category object into template as 'category' variable. Suppose that category object has 'id' property. In your template you use '{{ category.id }}' to render id. And we do just the same for site tree item in step 6.

  • In URLs we use Django's named URL patterns (documentation). That is almost idential to usage of Django 'url' tag in templates.

    Your urls configuration for steps 6, 7 supposed to include:

    url(r'^(?P<category_name>\S+)/(?P<entry_name>\S+)/$', 'detailed_entry', name='entry-detailed'),
    url(r'^(?P<category_name>\S+)/$', 'detailed_category', name='category-detailed'),

    So, putting 'entry-detailed category.name entry.name' in step 7 into URL field we tell sitetree to associate that sitetree item with URL named 'entry-detailed', passing to it category_name and entry_name parameters.

I hope this description should fill the documentation gap %)

like image 99
idle sign Avatar answered Oct 11 '22 01:10

idle sign