A simple library for class based view breadcrumbs for any python web framework
Project description
crumbles
A simple library for class based view breadcrumbs for any python web framework.
Usage
First define a specific mixin for your framework. For example Django:
from django.urls import reverse
class DjangoCrumblesViewMixin(CrumblesViewMixin):
def url_resolve(self, *args, **kwargs):
return reverse(*args, **kwargs)
Use the Mixin in your View classes and define the breadcrumbs:
class MyListView(View, DjangoCrumblesViewMixin):
crumbles = (
CrumbleDefinition(url_name="my-list-view", title="Home"),
)
Add a default breadcrumb to the mixin like so:
class DjangoCrumblesViewMixin(CrumblesViewMixin):
def __init__(self):
self.crumbles = (
CrumbleDefinition(url_name="index", title="Home"),
) + type(self).crumbles
def url_resolve(self, *args, **kwargs):
return reverse(*args, **kwargs)
You can reuse "parent" crumbles for detail pages and use a callable for url resolve arguments or for defining the title:
from operator import attrgetter, methodcaller
class MyDetailView(View, DjangoCrumblesViewMixin):
crumbles = MyListView.crumbles + (
CrumbleDefinition(
url_name="my-detail-view",
url_resolve_kwargs={"pk": attrgetter("pk")},
title=methodcaller("__str__"),
),
)
The attributes context will be retrieved from instance.object. If this is not available it
will default to the View class instance itself. You can set a custom context variable
(including dotted syntakt) by using crumbles_context_attribute:
class MyDetailView(View, DjangoCrumblesViewMixin):
crumbles_context_attribute = "my_object.parent"
...
Rendering the breadcrumb should be done in a template. An example for Django (with bootstrap):
<nav aria-label="breadcrumb">
<ol class="breadcrumb">
{% for item in view.resolve_crumbles %}
{% if forloop.last %}
<li class="breadcrumb-item active" aria-current="page">{{ item.title }}</li>
{% else %}
<li class="breadcrumb-item">
{% if item.url %}
<a href="{{ item.url }}">{{ item.title}}</a>
{% else %}
{{ item.title }}
{% endif %}
</li>
{% endif %}
{% endfor %}
</ol>
</nav>
Development setup
First clone this repository
git clone https://github.com/maerteijn/crumbles.git
Install the python project
pyenv virtualenv crumbles # or your alternative to create a venv
pyenv activate crumbles
make install
Linting
ruff and mypy are installed and configured
make lint
Formatting
ruff are configured
make format
Test
Pytest with coverage is default enabled
make cov
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file crumbles-0.1.2.tar.gz.
File metadata
- Download URL: crumbles-0.1.2.tar.gz
- Upload date:
- Size: 7.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c61b7bca857bb102cde511f81169949c32ff74fd37f2b66462076edec22178f8
|
|
| MD5 |
c5af6fc2be13c31335b02069d7caba90
|
|
| BLAKE2b-256 |
644deaa494d07e1040d58cd5520f7aca33b786e7c9335c26e183a0bcdfd4d13f
|
Provenance
The following attestation bundles were made for crumbles-0.1.2.tar.gz:
Publisher:
publish-pypi.yaml on maerteijn/crumbles
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
crumbles-0.1.2.tar.gz -
Subject digest:
c61b7bca857bb102cde511f81169949c32ff74fd37f2b66462076edec22178f8 - Sigstore transparency entry: 177971905
- Sigstore integration time:
-
Permalink:
maerteijn/crumbles@d8b046ed682e1083cfa3d0de802b2e14725e07c3 -
Branch / Tag:
refs/tags/v0.1.2 - Owner: https://github.com/maerteijn
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-pypi.yaml@d8b046ed682e1083cfa3d0de802b2e14725e07c3 -
Trigger Event:
workflow_dispatch
-
Statement type:
File details
Details for the file crumbles-0.1.2-py3-none-any.whl.
File metadata
- Download URL: crumbles-0.1.2-py3-none-any.whl
- Upload date:
- Size: 4.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a80669b764f82957696da5874568201fcf4774e4fc0b8a584a52bbc0741045ec
|
|
| MD5 |
4eb2df804309edc82202a7df2a631db3
|
|
| BLAKE2b-256 |
7ca779089290952697188b72b029a3ed698597acec73c0fe0010f54f1c223fd3
|
Provenance
The following attestation bundles were made for crumbles-0.1.2-py3-none-any.whl:
Publisher:
publish-pypi.yaml on maerteijn/crumbles
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
crumbles-0.1.2-py3-none-any.whl -
Subject digest:
a80669b764f82957696da5874568201fcf4774e4fc0b8a584a52bbc0741045ec - Sigstore transparency entry: 177971908
- Sigstore integration time:
-
Permalink:
maerteijn/crumbles@d8b046ed682e1083cfa3d0de802b2e14725e07c3 -
Branch / Tag:
refs/tags/v0.1.2 - Owner: https://github.com/maerteijn
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-pypi.yaml@d8b046ed682e1083cfa3d0de802b2e14725e07c3 -
Trigger Event:
workflow_dispatch
-
Statement type: