Skip to content

Instantly share code, notes, and snippets.

Avatar

Andrea Robertson RoboAndie

View GitHub Profile
@RoboAndie
RoboAndie / bootstrap_modal_tag.py
Last active May 18, 2020
Django block template tag to display a Bootstrap modal
View bootstrap_modal_tag.py
from django import template
from django.core.exceptions import ValidationError
from django.core.validators import validate_slug
from django.template import TemplateSyntaxError
from django.template.base import token_kwargs
register = template.Library()
@register.tag
@RoboAndie
RoboAndie / active_nav_tag.py
Last active Oct 19, 2020
Django template tag to highlight the active navigation item
View active_nav_tag.py
@register.simple_tag(takes_context=True)
def active_nav(context, pattern_or_urlname, is_sr_text=False):
path = context['request'].path
if ',' in pattern_or_urlname:
patterns_to_try = pattern_or_urlname.split(',')
else:
patterns_to_try = [pattern_or_urlname]
for pattern in patterns_to_try:
try:
p = '^' + reverse(pattern)