Skip to main content

Garpix Menu

Настраиваемые меню для garpix_page.

Быстрый старт

Сначала установите и настройте garpix_page.


Установите с pip:

pip install garpix_menu

Добавьте garpix_menu и пакеты зависимостей в INSTALLED_APPS:

# settings.py

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

Пакет не включает миграции, укажите путь к каталогу миграций. Не забудьте создать этот каталог (app/migrations/garpix_page/) и поместить в него пустой __init__.py:

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

Добавьте путь и другие настройки:

# settings.py

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

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

Создайте миграции:

python manage.py makemigrations

Примените миграции:

python manage.py migrate

Пример

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

Пример шаблона меню по умолчанию:

# 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 %}

Пример со всеми шаблонами:

# 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 %}

Теперь вы можете авторизоваться в панели администратора и начать добавлять меню и страницы.

Changelog

Смотрите CHANGELOG.md.

Contributing

Смотрите CONTRIBUTING.md.

License

MIT

Metadata

Release files for garpix-menu 1.17.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for garpix-menu 1.17.1
File Size Uploaded
garpix_menu-1.17.1.tar.gz 21.2 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for garpix-menu 1.17.1
File Interpreter ABI Platform
garpix_menu-1.17.1-py3-none-any.whl Python 3 none any Details

Total release size: 54.4 kB

Release files / garpix_menu-1.17.1.tar.gz

Download URL garpix_menu-1.17.1.tar.gz
Size 21.2 kB
Tags Source
SHA-256 checksum
How to use checksums
92b2867b47d9b909847750122bd6a1911f3ffc7b668351d10bf85302948167d9
BLAKE2b-256 checksum
How to use checksums
ab8245a04e5fe0a0769c8e5861ac865fa3304d4e9b6e7f280f07d5908cc759e6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.0.0 CPython/3.8.18

Release files / garpix_menu-1.17.1-py3-none-any.whl

Download URL garpix_menu-1.17.1-py3-none-any.whl
Size 33.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
9e79725b49cf57ba39eef1d550e6e3e642fd921be31a37d9fbb2ffcedcf803de
BLAKE2b-256 checksum
How to use checksums
db8be6d6e5389c9aa660f2964854e0bc1c22d4e370ace8c9e19268a5d3347de1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.0.0 CPython/3.8.18
Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page