geonode-project icon indicating copy to clipboard operation
geonode-project copied to clipboard

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

Open eruiz67 opened this issue 2 years ago • 4 comments

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]

eruiz67 avatar Jan 02 '23 13:01 eruiz67

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.

gannebamm avatar Jan 03 '23 09:01 gannebamm

Thank you so much for your help, but, Is it possible to create a menu and menu items with code?, I want to create a new django app for geonode, with some views and I want to create Menus and menu items for that app. So, when i install that new app, all menus and menu items will be installed,

El mar, 3 ene 2023 a las 4:15, Florian Hoedt @.***>) escribió:

Welcome to the community @eruiz67 https://github.com/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.

— Reply to this email directly, view it on GitHub https://github.com/GeoNode/geonode-project/issues/394#issuecomment-1369538169, or unsubscribe https://github.com/notifications/unsubscribe-auth/APEMEBAATOBW2EVQPPGPOTTWQPU3ZANCNFSM6AAAAAATO2YRFY . You are receiving this because you were mentioned.Message ID: @.***>

eruiz67 avatar Jan 03 '23 15:01 eruiz67

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'))]

gannebamm avatar Jan 04 '23 08:01 gannebamm

Hello, I just posted an issue on github Could you help me

In geonode when an user logs in, it is automatically redirected to the Profile page. I am trying to change that and redirect to the Home (index page). In order to to that I added the following line to the settings.py" in my geonode-project folder. But the user is still redirected to the Profile page when he/she performs the authentication

ACCOUNT_LOGIN_REDIRECT_URL = "/"

I also tried with the following line:

LOGIN_REDIRECT_URL = "/"

Am I doing something wrong? According to the geonode documentation ( https://docs.geonode.org/en/master/basic/settings/index.html) the ACCOUNT_LOGIN_REDIRECT_URL "allows specifying the default redirect URL after a successful login.", so why is not working

El mié, 4 ene 2023 a las 3:47, Florian Hoedt @.***>) escribió:

Hi @eruiz67 https://github.com/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'))]

— Reply to this email directly, view it on GitHub https://github.com/GeoNode/geonode-project/issues/394#issuecomment-1370629462, or unsubscribe https://github.com/notifications/unsubscribe-auth/APEMEBAQO22C5S6F2VMYAKTWQU2JNANCNFSM6AAAAAATO2YRFY . You are receiving this because you were mentioned.Message ID: @.***>

eruiz67 avatar Mar 12 '23 21:03 eruiz67