0
votes

django-cms 2.2, django 1.3.1

I'm creating an app called gallery. Gallery has photos inside. (there are many galleries)

I have the following structure:

  • cms_app.py - apphook for gallery (needed for gallery details (photos inside gallery) view)
  • cms_plugins.py - plugin for galleries list
  • menu.py - each gallery has its own page (photos inside galery), we generate menu here
  • views.py - a view for gallery details (photos inside)
  • urls.py - // url for apphook to attach for photos inside view, name=gallery_details

URL structure:

  • /gallery-list/ - Page for list of galleries
  • /gallery-list/1/ - Photos of pk=1 gallery
  • /another-gallery-list/ - Another page for list of galleries
  • /another-gallery-list/1/ - Photos of pk=1 gallery (the same as /gallery-list/1/ but different url)

django-cms page structure:

  • Page /gallery-list/ with apphook = gallery app hook + plugin for list of galleries
  • Page /another-gallery-list/ with apphook = gallery app hook + plugin for list of galleries (same but different instances)

Menu:

  • Galleries
    • Gallery 1
  • Another galleries
    • Gallery 1

Problem: How do I generate menu for such galleries?

Currently I'm creating CMSAttachMenu and generating nodes (from model). How do I make urls? I'm trying to use reverse('gallery_details', args=[self.pk]) (get_absolute_url method) but it gives me url: /galleries/<id>/. What I want to get is /gallery-list/1/ and /another-gallery-list/1/ depending on page which has apphook attached.

Here is documentation that I'm using: http://docs.django-cms.org/en/2.2/extending_cms/app_integration.html#app-hooks

Help is much appreciated.

1

1 Answers

0
votes

Something like the following should work. I did something similar for a Project app when there was a list of projects and also a project detail page.

class GalleryMenu(CMSAttachMenu):
    name = _("Gallery Menu")
    def get_nodes(self, request):
        c=itertools.count()
            nav = [
                NavigationNode(
                  _(g.title),
                  reverse("gallery_detail", kwargs={ 'slug' : g.slug }),
                  next(c), parent_id=0
                )
            for i,g in enumerate(Gallery.objects.all()) ]
    return nav