Skip to content

Commit

Permalink
Refactor templatetag logic into multiple modules
Browse files Browse the repository at this point in the history
  • Loading branch information
huangsam committed Feb 19, 2023
1 parent 8d072cd commit f3d8a35
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 12 deletions.
2 changes: 1 addition & 1 deletion places/templates/places/restaurant_list.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{% extends 'simple.html' %}
{% load base_extras %}
{% load query_extras %}

{% block meta %}
<title>Chowist | Restaurant List</title>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,3 @@ def nav_active(request, url):
if reverse_url in current_url and reverse_url != "/":
return _NavigationStatus.ACTIVE
return _NavigationStatus.INACTIVE


@register.simple_tag(takes_context=True)
def updated_params(context, **kwargs):
# https://blog.ovalerio.net/archives/1512
# https://docs.djangoproject.com/en/4.1/ref/request-response/
query_dict = context["request"].GET.copy()
for k, v in kwargs.items():
query_dict[k] = v
return query_dict.urlencode()
14 changes: 14 additions & 0 deletions portal/templatetags/query_extras.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
from django import template
from django.urls import reverse

register = template.Library()


@register.simple_tag(takes_context=True)
def updated_params(context, **kwargs):
# https://blog.ovalerio.net/archives/1512
# https://docs.djangoproject.com/en/4.1/ref/request-response/
query_dict = context["request"].GET.copy()
for k, v in kwargs.items():
query_dict[k] = v
return query_dict.urlencode()
2 changes: 1 addition & 1 deletion templates/core/navigation.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{% load base_extras %}
{% load navbar_extras %}

<nav class="navbar navbar-expand-md navbar-dark bg-dark">
<div class="container-fluid">
Expand Down

0 comments on commit f3d8a35

Please sign in to comment.