Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to add buttons (links) to Geonode Menu bar using geonode-project 4.1.x? #394

Open
eruiz67 opened this issue Jan 2, 2023 · 4 comments

Comments

@eruiz67
Copy link

eruiz67 commented Jan 2, 2023

I just install Geonode-project 4.1.x and try to follow the official documentation (https://docs.geonode.org/en/4.x/devel/workshops/index.html#customize-the-look-and-feel) to customize the look and add some Links (buttons) to the navigarion bar.
So far I have created the templatetags folder and create the "get_menu_json.py" file with the following content
IIKaS


    from django import template
    
    register = template.Library()
    
    @register.simple_tag(takes_context=True)
    def get_base_right_topbar_menu(context):
    
        #is_mobile = _is_mobile_device(context)
    
        #if is_mobile:
        #    return []
    
        return [
            {
                "type": "link",
                "href": "/",
                "label": "Custom 3"
            },
            {
                "type": "link",
                "href": "/",
                "label": "Custom 4"
            },
        ]
    @register.simple_tag(takes_context=True)
    def get_base_left_topbar_menu(context):
    
        #is_mobile = _is_mobile_device(context)
    
        return [
            {
                "type": "link",
                "href": "/",
                "label": "Custom 1"
            },
            {
                "type": "link",
                "href": "/",
                "label": "Custom 2"
            },
        ]

I have also modified the settings.py to add the templatetags

    TEMPLATES[0]['OPTIONS']['libraries']={
                    'my_template_tag_menu': 'templatetags.get_menu_json',
                }

But this is not working. Geonode is still showing the same buttons (Dataset, Maps, etc). My intention is to add (I am saying add, not override) buttons to the Navigation Bar, so i can access the new views I have created for geonode project. I am using geonode-project 4.1.x. Documentations appears to be outdated.
I posted this question with pictures
[https://stackoverflow.com/questions/74941783/how-to-add-buttons-links-to-geonode-menu-bar-using-geonode-project-4-1-x]

@gannebamm
Copy link

Welcome to the community @eruiz67
Will this functionality solve your issue: https://docs.geonode.org/en/master/admin/admin_panel/index.html#menus-items-and-placeholders

You do not need to fiddle with the code but could use the already implemented configurable additional menu bar.

@eruiz67
Copy link
Author

eruiz67 commented Jan 3, 2023 via email

@gannebamm
Copy link

Hi @eruiz67
You could use your externalapplications/__init__.py and run_setup_hooks() to auto-create these entries if they are not present. Here is a (not fully working) example which should give you a good enough insight:

def run_setup_hooks(*args, **kwargs):
    from django.conf import settings
    from geonode.urls import urlpatterns
    from geonode.base.models import Menu, MenuItem, MenuPlaceholder

    LOCAL_ROOT = os.path.abspath(os.path.dirname(__file__))
    settings.MAPSTORE_TRANSLATIONS_PATH += ("/static/mapstore/ea-translations",)
    settings.TEMPLATES[0]["DIRS"].insert(0, os.path.join(LOCAL_ROOT, "templates"))

    # THIS IS THE IMPORTANT PART:
    if not Menu.objects.filter(title="External Applications").exists():
        ph = MenuPlaceholder.objects.filter(name="TOPBAR_MENU_LEFT").first()
        menu = Menu.objects.create(title="External Applications", placeholder=ph, order=1)
        MenuItem.objects.create(title="External Applications", menu=menu, order=1, blank_target=False,
                                url="/catalogue/#/search/?f=externalapplication")

    urlpatterns += [url(r'^external-applications/', include('externalapplications.urls'))]

@eruiz67
Copy link
Author

eruiz67 commented Mar 12, 2023 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants