Problem understanding how to build navigation

162 views
Skip to first unread message

etienned

unread,
Mar 25, 2013, 11:21:37 PM3/25/13
to django-...@googlegroups.com
Hi,

In my site, I want to have on all pages 2 menus (navigation) that will never change from page to page (one in the header and the other in the footer).

My site is multilingual (en, fr). My structure is basically like this:
- Root Redirector / (automatically redirect to the home page in proper language)
- - Home /en/
- - - Accessibility /en/accessibility/
- - - Site Map /en/sitemap/
- - - Credits /en/credits/
- - - Informations /en/informations/
- - - Contact /en/informations/#contact
- - - Hours /en/informations/#hours

- - Accueil /fr/
- - - Accessibilité /fr/accessibilite/
- - - etc. (same as english but in french)

The header navigation should be like this:
Informations | Contacts | Hours

The footer navigation should be like this:
Accessibility | Site Map | Credits

Is it possible to do that with feincms_nav templatetag? How I'm supposed to do this (with or without feincms_nav)?

I don't want to hardcode theses navigations directly in the templates because I want that my client will be able to change the navigation (page name, adding a new item, etc.).

Thanks

Martin J. Laubach

unread,
Mar 26, 2013, 6:24:40 AM3/26/13
to django-...@googlegroups.com
Yes, it's absolutely possible to build that without hardcoding things. What we usually do for something like this is mark the pages with a tag (we're using django-tagging) and just display all pages with that specific tag (eg. "navigation_top" and "navigation_bottom"). Easy.


etienned

unread,
Mar 26, 2013, 10:37:51 AM3/26/13
to django-...@googlegroups.com
Thanks for the answer.

I managed to hook django-taggit to the Page model and it works pretty well. I can add tags to each page in the admin, filter by tags, etc.

Now where do you filter the pages? Do you use a custom NavigationExtension? How you use the templatetag to get the filtered results?

I'm also investigating django-sitetree because I have a lot of pages not managed by FeinCMS and I was wondering if I could populate partly a tree from FeinCMS (maybe by using mptt directly?).

Regards

Martin J. Laubach

unread,
Mar 26, 2013, 10:45:46 AM3/26/13
to django-...@googlegroups.com
   No, nothing that fancy. We're just doing a

    {% tagged_objects 'meta_navigation' in page.page as metanav_items %}
   {% for navpage in metanav_items %}
        {{ navpage.title }} ...
   {% endfor %}

  (that's with django-tagging, I'm sure django-taggit has a similar template tag).

etienned

unread,
Mar 26, 2013, 11:23:19 AM3/26/13
to django-...@googlegroups.com

I see. But this way you will not get a hierarchy, no items will have children. So it's OK for simple nav like I have shown in my first post but not for more complicated scenarios (which I definitely have, but I didn't mention it).

And just for the info, django-taggit doesn't have any templatetags! There's an other project that add templatetags to taggit (django-taggit-templatetags) but there's no templatetags that can filter objects by tags. Strange?

Thanks again

Martin J. Laubach

unread,
Mar 26, 2013, 11:28:36 AM3/26/13
to django-...@googlegroups.com

I see. But this way you will not get a hierarchy, no items will have children. So it's OK for simple nav like I have shown in my first post but not for more complicated scenarios (which I definitely have, but I didn't mention it).

  That simple version will not do anything but a flat list, yes. But there's nothing that prevents you from feeding the result of such a search into mptt's tree_info to generate something hierarchical. You could also go the other way and filter the output from feincms_nav so it only contains your tagged items, but that means you'll have to write a filter yourself.


etienned

unread,
Apr 3, 2013, 11:24:01 AM4/3/13
to django-...@googlegroups.com
I finally write an extension to synchronize FeinCMS Page with django-sitetree. This way, when you create, update or delete a Page in Fein, menu entries will be created, updated or deleted in each sitetree tree selected in my Page extension.

With this system I can reorganize my navigation with a lot more flexibility:
  • Menus do not have to match exactly the same hierarchies as Pages, but match it by default.
  • I can rename menu items.
  • Menu items can have anchor link.
  • It's easy to add my non-FeinCMS pages to the navigation.
  • Breadcrumbs and Navigation can treated separately.
  • All that from the admin interface.
Unfortunately I add to extend the PageAdminForm to add a custom widget and populate is choices attribute on __init__.

Etienne

Martin J. Laubach

unread,
Apr 3, 2013, 11:30:58 AM4/3/13
to django-...@googlegroups.com

I finally write an extension to synchronize FeinCMS Page with django-sitetree. This way, when you create, update or delete a Page in Fein, menu entries will be created, updated or deleted in each sitetree tree selected in my Page extension.

  Oh, this sounds nice. Will you be making it available?

  Cheers,

    mjl
 

etienned

unread,
Apr 4, 2013, 9:02:43 PM4/4/13
to django-...@googlegroups.com

I finally write an extension to synchronize FeinCMS Page with django-sitetree. This way, when you create, update or delete a Page in Fein, menu entries will be created, updated or deleted in each sitetree tree selected in my Page extension.

  Oh, this sounds nice. Will you be making it available?

I would like but I have a few problems not properly solved. I have some hackish solutions in my code right now but I can't definitely not publish the extension this way. Here's the current problems, maybe you could have some ideas to how to solve them:
  1.  I'm not able to import sitetree classes (Tree and TreeItem) directly in the extension module. I'm getting 'No module named sitetree' error and I definitely don't know why? My current workaround is to do the import in the module where I register the extensions and then import from there in the extension module.
  2. For the moment I'm using the JSONField class from django-extensions. I don't know if I should avoid this for public diffusion?
  3. I'm overriding PageAdminForm to customize a widget and to populate the widget choices on __init__ because the choices come from the DB (Tree model). I didn't find a way to monkey patch the PageAdmin class from the extension so FEINCMS_USE_PAGE_ADMIN need to be set to False and then PageAdmin should be register by hand.
Etienne
Reply all
Reply to author
Forward
0 new messages