Skip to main content

No project description provided

Project description

Garpix Menu

Customizable menus for garpix_page.

Quickstart

First, install and set up garpix_page.


Install with pip:

pip install garpix_menu

Add the garpix_menu and dependency packages to your INSTALLED_APPS:

# settings.py

INSTALLED_APPS = [
    # ...
    'garpix_menu',
]

Package not included migrations, set path to migration directory. Don’t forget create this directory (app/migrations/garpix_page/) and place empty __init__.py:

app/migrations/
app/migrations/__init__.py  # empty file
app/migrations/garpix_menu/__init__.py  # empty file

Add path and other settings:

# settings.py

MIGRATION_MODULES = {
    'garpix_menu': 'app.migrations.garpix_menu',
}

TEMPLATES = [
    {
        # ...
        'OPTIONS': {
            'context_processors': [
                # ...
                'garpix_menu.context_processors.menu_processor',
            ],
        },
    },
]

Run make migrations:

python manage.py makemigrations

Migrate:

python manage.py migrate

Example

Set up your custom menus in settings.py, for example:

# settings.py

MENU_TYPE_HEADER_MENU = 'header_menu'
MENU_TYPE_FOOTER_MENU = 'footer_menu'

MENU_TYPES = {
    MENU_TYPE_HEADER_MENU: {
        'title': 'Header menu',
    },
    MENU_TYPE_FOOTER_MENU: {
        'title': 'Footer menu',
    },
}

CHOICE_MENU_TYPES = [(k, v['title']) for k, v in MENU_TYPES.items()]

Example template for default menu:

# templates/menus/default.html

{% for menu_item in menu %}
<a {% if menu_item.target_blank %}target="_blank" {% endif %}
   href="{{ menu_item.get_link }}">{{ menu_item.title }}</a>
{% if not forloop.last %}|{% endif %}
{% endfor %}

Example with all templates:

# templates/base.html

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    {% include 'garpix_page/seo.html' %}
    <link href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css" rel="stylesheet"
          crossorigin="anonymous">
</head>
<body>
{% include 'include/header.html' %}

<main class="container">
    {% block content %}
    {% endblock %}
</main>

{% include 'include/footer.html' %}
</body>
</html>

# templates/pages/default.html

{% extends 'base.html' %}

{% block content %}
<h1>{{object.title}}</h1>
<div>
    {{object.content|safe}}
</div>
{% endblock %}

# templates/include/header.html

<nav class="navbar navbar-expand-md navbar-dark bg-dark">
    <div class="container-fluid">
        <a class="navbar-brand" href="/">My Site</a>
        <button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarsExampleDefault"
                aria-controls="navbarsExampleDefault" aria-expanded="false" aria-label="Toggle navigation">
            <span class="navbar-toggler-icon"></span>
        </button>

        <div class="collapse navbar-collapse" id="navbarsExampleDefault">
            {% include 'menus/header_menu.html' with menu=menus.header_menu %}
        </div>
    </div>
</nav>

# templates/include/footer.html

<style>
    /* Sticky footer styles
    -------------------------------------------------- */
    html {
        position: relative;
        min-height: 100%;
    }

    body {
        margin-bottom: 60px; /* Margin bottom by footer height */
    }

    .footer {
        position: absolute;
        bottom: 0;
        width: 100%;
        height: 60px; /* Set the fixed height of the footer here */
        line-height: 60px; /* Vertically center the text there */
        background-color: #f5f5f5;
    }

</style>

<footer class="footer">
    <div class="container">
        <span class="text-muted">
            {% include 'menus/footer_menu.html' with menu=menus.footer_menu %}
        </span>
    </div>
</footer>

# templates/menus/header_menu.html

<ul class="navbar-nav me-auto mb-2 mb-md-0">
    {% for menu_item in menu %}
    <li class="nav-item">
        <a class="nav-link {% if menu_item.is_current %}active{% endif %}" aria-current="page"
           {% if menu_item.target_blank %}target="_blank" {% endif %}
           href="{{ menu_item.get_link }}">{{ menu_item.title }}</a>
    </li>
    {% endfor %}
</ul>

# templates/menus/footer_menu.html

{% for menu_item in menu %}
<a {% if menu_item.target_blank %}target="_blank" {% endif %}
   href="{{ menu_item.get_link }}">{{ menu_item.title }}</a>
{% if not forloop.last %}|{% endif %}
{% endfor %}

Now you can auth in admin panel and starting add menus and pages.

Changelog

See CHANGELOG.md.

Contributing

See CONTRIBUTING.md.

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

garpix_menu-1.7.0.tar.gz (15.0 kB view details)

Uploaded Source

Built Distribution

garpix_menu-1.7.0-py3-none-any.whl (23.3 kB view details)

Uploaded Python 3

File details

Details for the file garpix_menu-1.7.0.tar.gz.

File metadata

  • Download URL: garpix_menu-1.7.0.tar.gz
  • Upload date:
  • Size: 15.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.2 CPython/3.8.12

File hashes

Hashes for garpix_menu-1.7.0.tar.gz
Algorithm Hash digest
SHA256 35fb9f44adf9d94f36c7ca8c076d3a060f7bb7a151e2ba8b6966dbc463420188
MD5 d9db9d2345b2e01c8cf904b616a90872
BLAKE2b-256 1269009c4b8fdc78cc694a02649153aaac1c116c6ba906891c0e364d090c8eba

See more details on using hashes here.

File details

Details for the file garpix_menu-1.7.0-py3-none-any.whl.

File metadata

  • Download URL: garpix_menu-1.7.0-py3-none-any.whl
  • Upload date:
  • Size: 23.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.2 CPython/3.8.12

File hashes

Hashes for garpix_menu-1.7.0-py3-none-any.whl
Algorithm Hash digest
SHA256 2f42282beb5fdc63eebc024d26fa154e56aed243ac1a4e0635f88fb787f170f3
MD5 8c2524214db1a20195032887ad70fa7b
BLAKE2b-256 79c94ac8521fd34c6402033118c2ed812b8f76b9497569deb4510810ffd44514

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page