diff --git a/README.md b/README.md index f2152571fc59fbff2a1685259a957f20b22b9d41..025d05ec24ba1ba311a3d430ba4586d8b1eec86e 100644 --- a/README.md +++ b/README.md @@ -33,6 +33,25 @@ The current version of this package ships the following own stuff and awesome th Simply put this app into your projects `requirements.txt` file and run `pip install -r requirements.txt`. Once you installed it, you should put the name `hshcdn` into your projects `INSTALLED_APPS` setting. Tadaa! +Also if you want to use breadcrubs (you likely do), you need to add the settings context processor to your `TEMPLATES` setting: + +```python +TEMPLATES = [ + { + 'BACKEND': 'django.template.backends.django.DjangoTemplates', + # [...] + 'OPTIONS': { + 'context_processors': [ + # [...] + 'hshassets.context_processors.settings' # <-- add this line + ], + }, + }, +] +``` + +**More information about using breadcrumbs [can be found in the WIKI](https://lab.it.hs-hannover.de/django/hshassets/wikis/breadcrumbs)** + ## Usage Simply create an `assets` folder in your app(s) directory. It can contain the folders `fonts` for custom fonts, `img` diff --git a/hshassets/app_settings/defaults.py b/hshassets/app_settings/defaults.py index 6144f9d6d7af62e1c41d950dfbbc188e6c0fd6e2..d3e041a1e720e02e2f3592bbf5db8641124e1da1 100644 --- a/hshassets/app_settings/defaults.py +++ b/hshassets/app_settings/defaults.py @@ -24,4 +24,7 @@ COLOR_SCHEME = 'service' # read utils.get_scss_include_paths() for further information SCSS_INCLUDE_PATHS = [ ('hshassets', ['sass/lib/']), -] \ No newline at end of file +] + +# URI to the live service.it portal +SERVICE_IT_URI = 'https://service.it.hs-hannover.de/' diff --git a/hshassets/context_processors.py b/hshassets/context_processors.py new file mode 100644 index 0000000000000000000000000000000000000000..9274bbefb48fa22c412127c2ac742c2aca584ade --- /dev/null +++ b/hshassets/context_processors.py @@ -0,0 +1,9 @@ +""" +hshassets brings an own middleware to make some settings variables available in templates +""" + +from hshassets.app_settings import SERVICE_IT_URI + + +def settings(request): + return {'service_it_uri': SERVICE_IT_URI} diff --git a/hshassets/templates/hshassets/includes/breadcrumbs.html b/hshassets/templates/hshassets/includes/breadcrumbs.html new file mode 100644 index 0000000000000000000000000000000000000000..ef1f659ff1d21b840920f79556833da77e7f817e --- /dev/null +++ b/hshassets/templates/hshassets/includes/breadcrumbs.html @@ -0,0 +1,40 @@ +{% load i18n %} + +{% comment %} + This template provides an breadcrumb bar for the hero / hero_keyvisual template. Use it like this: + + {% block pre-section %} + {% include "hshassets/includes/breadcrumbs.html" %} + {% endblock %} + + This snippet will render a breadcrumb bar under the <div class="hero"> element. To use it, you need to edit your + views that they inherit from "hshassets.views.BreadCrumbMixin". Also provide the attributes "breadcrumb_name" and + "breadcrumb_parent" (only if you have a parent, otherwise the view will be the root element). Example: + + class ExploreView(ListView, BreadCrumbMixin): + template_name = 'myapp/explore.html' + + breadcrumb_name = _('Explore') + breadcrumb_parent = 'about' + + Please note that this template should be used via {% include "" %}, not {% extends "" %}! + This way you can specify your own navigation or hero text or general content stuff. +{% endcomment %} + +<div class="breadcrumb-wrapper"> + <div class="container"> + <nav class="breadcrumb" aria-label="breadcrumbs"> + <ul> + + <li><a href="{{ service_it_uri }}"><span class="icon"><i class="fa fa-home"></i></span> IT Services</a></li> + + {% for breadcrumb in breadcrumb_path %} + <li {% if forloop.last %}class="is-active"{% endif %}> + <a href="{{ breadcrumb.url }}">{{ breadcrumb.name }}</a> + </li> + {% endfor %} + + </ul> + </nav> + </div> +</div> diff --git a/hshassets/views.py b/hshassets/views.py new file mode 100644 index 0000000000000000000000000000000000000000..bf350aadd89797aff4d8589435721e82a5d659d3 --- /dev/null +++ b/hshassets/views.py @@ -0,0 +1,25 @@ +from django.urls import reverse, resolve +from django.views.generic.base import ContextMixin + + +class BreadCrumbMixin(ContextMixin): + + breadcrumb_parent = None + breadcrumb_name = None + + def get_breadcrumb_path(self, breadcrumb_path, url_name=''): + + if self.breadcrumb_parent: + parent_view_class = resolve(reverse(self.breadcrumb_parent)).func.view_class + breadcrumb_path.extend(parent_view_class().get_breadcrumb_path(breadcrumb_path, self.breadcrumb_parent)) + + return breadcrumb_path + [{'name': self.breadcrumb_name, 'url': reverse(url_name) if url_name else '#'}] + + def get_context_data(self, *args, **kwargs): + assert self.breadcrumb_name, 'Missing attribute "breadcrumb_name" on {}'.format(self.__class__) + + context = super().get_context_data(*args, **kwargs) + context.update({ + 'breadcrumb_path': self.get_breadcrumb_path([]) + }) + return context diff --git a/setup.py b/setup.py index bb9bed1bb65b679aa30f6444d32986281af411e0..535b6399254d4392318f35098bb671f8f5cb8dad 100644 --- a/setup.py +++ b/setup.py @@ -7,7 +7,7 @@ os.chdir(os.path.normpath(os.path.join(os.path.abspath(__file__), os.pardir))) setup( name='django-hshassets', - version='1.2.2', + version='1.3.0', packages=find_packages(), include_package_data=True, license='MIT License',