Skip to content

Commit

Permalink
feat(submod): texascale, load annual stylesheets
Browse files Browse the repository at this point in the history
  • Loading branch information
wesleyboar committed Jun 30, 2022
1 parent 07a7df2 commit bcd1bfa
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 1 deletion.
43 changes: 43 additions & 0 deletions taccsite_cms/templatetags/get_url_match.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import re

from django import template
from urllib.parse import urlparse

register = template.Library()

@register.filter
def get_url_match(path, pattern):
"""
Custom Template Filter `get_url_match`
Use: Render string that matches given pattern from current page URL.
Load custom filter into template:
{% load get_url_match %}
Template inline usage:
{# given path '.../2019/...', does nothing #}
{% if path|get_url_match:"/20\d\d/" %}
{# condition evaluates to False #}
{% endif %}
{# given path '.../2020/...', does something #}
{% if path|get_url_match:"/20\d\d/" %}
{# condition evaluates to True #}
{% endif %}
{# given path '.../2021/...', prints complete match #}
{% with year_path=path|get_url_match:"/20\d\d/" %}
<pre>{{ year_path }}</pre> {# prints complete match #}
{% endwith %}
{# given path '.../2022/...', prints matched content #}
{% with year_slug=path|get_url_match:"/(20\d\d)/" %}
<pre>{{ year_slug }}</pre> {# prints match within the (…) #}
{% endwith %}
"""
result = re.search(pattern, path)

if result:
try:
match = result.group(1)
except IndexError:
match = result[0]
else:
match = False

return match
2 changes: 1 addition & 1 deletion taccsite_custom

0 comments on commit bcd1bfa

Please sign in to comment.