Metadata-Version: 2.1
Name: django-view-breadcrumbs
Version: 0.0.7
Summary: Django generic view breadcrumbs
Home-page: https://github.com/jackton1/django-view-breadcrumbs
Author: Tonye Jack
Author-email: jtonye@ymail.com
License: UNKNOWN
Keywords: django breadcrumbs,breadcrumbs,django generic views breadcrumb
Platform: UNKNOWN
Classifier: Development Status :: 3 - Alpha
Classifier: Topic :: Internet :: WWW/HTTP
Classifier: License :: OSI Approved :: BSD License
Classifier: Programming Language :: Python :: 3.5
Classifier: Programming Language :: Python :: 3.6
Classifier: Framework :: Django :: 1.11
Classifier: Framework :: Django :: 2.0
Classifier: Framework :: Django :: 2.1
Requires-Python: >=3.5
Description-Content-Type: text/markdown
Provides-Extra: test
Provides-Extra: deploy
Provides-Extra: development
Provides-Extra: docs
Provides-Extra: lint
Requires-Dist: Django (<3.0,>=1.11.10,>=2.0.2)
Requires-Dist: django-bootstrap-breadcrumbs (==0.9.1)
Provides-Extra: deploy
Requires-Dist: bumpversion (==0.5.3); extra == 'deploy'
Provides-Extra: development
Requires-Dist: pip-tools (==2.0.2); extra == 'development'
Requires-Dist: Django (<3.0,>=1.11.10,>=2.0.2); extra == 'development'
Requires-Dist: django-bootstrap-breadcrumbs (==0.9.1); extra == 'development'
Requires-Dist: tox (==2.9.1); extra == 'development'
Requires-Dist: pytest (==3.7.2); extra == 'development'
Requires-Dist: pluggy (>=0.7); extra == 'development'
Requires-Dist: mock (==2.0.0); extra == 'development'
Requires-Dist: codacy-coverage (==1.3.10); extra == 'development'
Requires-Dist: Sphinx (==1.6.5); extra == 'development'
Requires-Dist: flake8 (==3.4.1); extra == 'development'
Requires-Dist: yamllint (==1.10.0); extra == 'development'
Requires-Dist: isort (==4.2.15); extra == 'development'
Provides-Extra: docs
Requires-Dist: Sphinx (==1.6.5); extra == 'docs'
Provides-Extra: lint
Requires-Dist: flake8 (==3.4.1); extra == 'lint'
Requires-Dist: yamllint (==1.10.0); extra == 'lint'
Requires-Dist: isort (==4.2.15); extra == 'lint'
Provides-Extra: test
Requires-Dist: tox (==2.9.1); extra == 'test'
Requires-Dist: pytest (==3.7.2); extra == 'test'
Requires-Dist: pluggy (>=0.7); extra == 'test'
Requires-Dist: mock (==2.0.0); extra == 'test'
Requires-Dist: codacy-coverage (==1.3.10); extra == 'test'

# django-view-breadcrumbs [![Build Status](https://travis-ci.org/jackton1/django-view-breadcrumbs.svg?branch=master)](https://travis-ci.org/jackton1/django-view-breadcrumbs) [![Codacy Badge](https://api.codacy.com/project/badge/Grade/6b447e364bef4988bda95bd0965bb4bc)](https://www.codacy.com/app/jackton1/django-view-breadcrumbs?utm_source=github.com&amp;utm_medium=referral&amp;utm_content=jackton1/django-view-breadcrumbs&amp;utm_campaign=Badge_Grade) [![PyPI version](https://badge.fury.io/py/django-view-breadcrumbs.svg)](https://badge.fury.io/py/django-view-breadcrumbs)

This extends [django-bootstrap-breadcrumbs](http://django-bootstrap-breadcrumbs.readthedocs.io/en/latest/) providing generic breadcrumb mixin classes.

Replaces having to add ```{% breadcrumb $label $viewname [*args] [**kwargs] %}``` to every template.



Breadcrumb mixin classes provided.
----------------------------------

- `BaseBreadcrumbMixin`    - Base view requires a `crumbs` class property.
- `CreateBreadcrumbMixin`  - For create views `Home \ Posts \ Add Post`
- `DetailBreadcrumbMixin`  - For detail views `Home \ Posts \ Post 1`
- `ListBreadcrumbMixin`    - For list views `Home \ Posts`
- `UpdateBreadcrumbMixin`  - For Update views `Home \ Posts \ Post 1 \ Update Post 1`


## Installation:

```bash
$ pip install django-view-breadcrumbs

```

Add app to your INSTALLED_APPS

```python

INSTALLED_APPS = [
    ...
    'django_bootstrap_breadcrumbs',
    'view_breadcrumbs',
    ...
]
```

## Usage:
`django-view-breadcrumbs` includes generic mixins that can be added to a class based view.

Using the generic breadcrumb mixin each breadcrumb will be added to the view dynamically
and can be overridden by providing a `crumbs` property.


### Sample crumbs:  `Home \ Posts \ Test - Post`

> NOTE: All url config should use a pattern `view_name=model_verbose_name_{action}` i.e `view_name=post_detail` for detail view. 

Actions include: 
 - "list" - `ListView`
 - "change" - `UpdateView`
 - "detail" - `DetailView`

In your `urls.py`
```python
  urlpatterns = [
      ...
      path('posts/<slug:slug>', views.PostDetail.as_view(), name='post_detail'),
      ...
  ]

```
`views.py`
```python
from django.views.generic import DetailView
from view_breadcrumbs import DetailBreadcrumbMixin


class PostDetail(DetailBreadcrumbMixin, DetailView):
    model = Post
    template_name = 'app/post/detail.html'
```

In the `base.html` template simply add the ``render_breadcrumbs`` tag and any template
that inherits the base should have breadcrumbs included.
i.e  

```base.html```

```jinja2
{% load django_bootstrap_breadcrumbs %}

{% block breadcrumbs %}
    {% render_breadcrumbs %}
{% endblock %}
```

And your ```create.html```.

```jinja2
{% extends 'base.html' %}
```


> All crumbs use the home root path `\` as the base this can be excluded by specifying `add_home = False`

### Sample crumbs: `Posts`

```python
from django.views.generic import ListView
from view_breadcrumbs import ListBreadcrumbMixin


class PostList(ListBreadcrumbMixin, ListView):
    model = Post
    template_name = 'app/post/list.html'
    add_home = False
```


> Can also override the view breadcrumb by specifying a list of tuples `[(Label, view path)]`.

### Custom crumbs: `Home \ My Test Breadcrumb`

URL conf.
```python
urlpatterns = [
   path('my-test-list-view/', views.TestView.as_view(), name='test_list_view'),
   path('my-test-detail-view/<int:pk>/', views.TestView.as_view(), name='test_detail_view'),
]
```

views.py

```python
from django.urls import reverse
from django.views.generic import ListView
from view_breadcrumbs import ListBreadcrumbMixin


class TestView(ListBreadcrumbMixin, ListView):
    model = TestModel
    template_name = 'app/test/test-list.html'
    crumbs = [('My Test Breadcrumb', reverse('test_list_view'))]  # OR reverse_lazy
```

OR

```python
class TestView(ListBreadcrumbMixin, ListView):
    model = TestModel
    template_name = 'app/test/test-list.html'

    @cached_property
    def crumbs(self):
        return super(TestView, self).crumbs + [
            (self.object.name , reverse('test_detail_view', kwargs={'pk': self.object.pk})
        ]

```



