Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9015333
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T03:43:34+00:00 2026-06-16T03:43:34+00:00

I have a custom app inside django-cms and have the need to attach a

  • 0

I have a custom app inside django-cms and have the need to attach a submenu to my app.
I’ve followed the guides and examples I’ve found to do this (see the Portfolio example given by Brandon here: custom views within Djangocms?), and managed to get the submenu up and running.

By expanding on the example provided above; What if this Portfolio app presented here, consisted of a small number of different views (create view, detail view and perhaps a couple of other related views). What if I needed to build a submenu to hold the choices related to user navigation in this small app. And what if the navigation should present choices based on selected content in the views (“Edit” only if a portfolio is selected or similar).
The submenu would have to know what Portfolio was selected, right? Or at least that a Portfolio is in fact selected and in view.

How can I transfer to my implementation of CMSAttachMenu what my view allready knows? In my case, I’m implementing an app dealing with meetups or “Events”. The example below does not work, because the Event object is obviously not registered in the request, but it illustrates what I want:

# menu.py
from django.core.urlresolvers import reverse
from menus.base import NavigationNode
from menus.menu_pool import menu_pool
from cms.menu_bases import CMSAttachMenu
from App.apps.event.models import Event
from django.utils.translation import ugettext_lazy as _
import logging

logger = logging.getLogger('instant.event')


class EventMenu(CMSAttachMenu):

    name = _("Event Sub-Menu")

    def get_nodes(self, request):
        nodes = []
        nodes.append(NavigationNode(_('Create new events'), reverse("admin:event_event_add"), 1 + len(nodes), 0))

        if hasattr(request, 'event'):
            if request.event.is_registered_to_event(request.user):
                nodes.append(NavigationNode(_('Unregister from this event'), reverse("unregister_from_event"), 1 + len(nodes), 0))
            else:
                nodes.append(NavigationNode(_('Register to participate in this event'), reverse("unregister_from_event"), 1 + len(nodes), 0))

        if request.user.is_superuser():
            nodes.append(NavigationNode(_('Register other participant to this event'), reverse("register_admin", args=(request.event.id)), 1 + len(nodes), 0))

        nodes.append(NavigationNode(_('Back to list of events'), reverse("events"), 1 + len(nodes), 0))
    return nodes

menu_pool.register_menu(EventMenu)
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T03:43:35+00:00Added an answer on June 16, 2026 at 3:43 am

    This was a hard one, but the following would solve it (showing only relevant parts):

    cms_app.py

    from cms.app_base import CMSApp
    from cms.apphook_pool import apphook_pool
    from django.utils.translation import ugettext_lazy as _
    
    class EventsApphook(CMSApp):
        name = _("Event")
        urls = ["App.apps.event.urls"]
    apphook_pool.register(EventsApphook)
    

    menu.py

    from cms.menu_bases import CMSAttachMenu
    from menus.base import NavigationNode
    from menus.menu_pool import menu_pool
    from django.utils.translation import ugettext_lazy as _
    
    menuNodes = []
    
    class EventMenu(CMSAttachMenu):
        name = _("Event Sub-Menu")
        def get_nodes(self, request):
            return menuNodes
    menu_pool.register_menu(EventMenu)
    
    def add_menu_node(text, url):
        # only add a given url once
        if len(list(n for n in menuNodes if n.url == url)) == 0:
            menuNodes.append(NavigationNode(text, url, 1 + len(menuNodes), 0))
            menu_pool.clear()
    

    views.py

    from django.views.generic.detail import DetailView
    from django.core.urlresolvers import reverse
    from django.utils.translation import ugettext_lazy as _
    from App.apps.event.menu import add_menu_node
    from App.apps.event.models import Event
    
    class EventMenuMixin(object):
        def get_context_data(self, **kwargs):
            context = super(EventMenuMixin, self).get_context_data(**kwargs)
            member = self.request.user
    
            if 'pk' in self.kwargs.keys():
                event = Event.objects.get(id=self.kwargs['pk'])
                if event.is_registered_to_event(member):
                    add_menu_node(_('Unregister from this event'), reverse("unregister_from_event"))
                else:
                    add_menu_node(_('Register to participate in this event'), reverse("register_to_event", args=(self.kwargs['pk'])))
    
            add_menu_node(_("Create new events"), reverse("admin:event_event_add"))
            return context
    
    class EventDetailView(EventMenuMixin, DetailView):
        model = Event
        template_name = 'event/event_detail.html'
        context_object_name = 'event'
    

    I hope this will help others in the same predicament as me.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need help. I have custom uitableviewcell with uiscrollview inside, I iterate over an
I have a custom View that is nested inside ScrollView and HorizontalScrollView like this:
I have the following validator: # Source: http://guides.rubyonrails.org/active_record_validations_callbacks.html#custom-validators # app/validators/email_validator.rb class EmailValidator < ActiveModel::EachValidator
I have an Activity in Landscape-Mode. Inside there is a Custom-Title-View aligned like this:
I have a Django app with custom form fields, some of which have slow
I have custom classes that I currently instantiate within App.xaml as resources. I want
I have a custom validator (located in app/validators/uri_validator.rb) which is used in: validates :link,
I have a custom error pages in my rails app testing the 404 error
I have a custom view in my Android App that uses a ScaleGestureDetector.SimpleOnScaleGestureListener to
I have a custom animaiton that I use thru 90% of my app. I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.