This repository has been archived by the owner on Oct 28, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 51
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #171 from walison17/fix-pagination-links
Fix pagination links
- Loading branch information
Showing
4 changed files
with
52 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
from django import template | ||
|
||
register = template.Library() | ||
|
||
|
||
@register.simple_tag(takes_context=True) | ||
def merge_query_params(context, **kwargs): | ||
query_params = context["request"].GET.copy() | ||
|
||
for k, v in kwargs.items(): | ||
query_params[k] = v | ||
|
||
return query_params.urlencode() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
from django.test import SimpleTestCase, RequestFactory | ||
from django.template import Context, Template | ||
|
||
|
||
class TestMergeQueryParamsTag(SimpleTestCase): | ||
def setUp(self): | ||
self.rf = RequestFactory() | ||
|
||
def test_add_param(self): | ||
request = self.rf.get("/", {"description": "descricao", "salary_range": 1}) | ||
context = Context({"request": request}) | ||
template = Template( | ||
"{% load core_tags %}" | ||
'<a class="page-link" href="/?{% merge_query_params page=1 %}">1</a>' | ||
) | ||
rendered_template = template.render(context) | ||
|
||
self.assertInHTML( | ||
'<a class="page-link" href="/?description=descricao&salary_range=1&page=1">1</a>', | ||
rendered_template, | ||
) | ||
|
||
def test_replace_param(self): | ||
request = self.rf.get( | ||
"/", {"description": "descricao", "salary_range": 1, "page": 2} | ||
) | ||
context = Context({"request": request}) | ||
template = Template( | ||
"{% load core_tags %}" | ||
'<a class="page-link" href="/?{% merge_query_params page=10 %}">1</a>' | ||
) | ||
rendered_template = template.render(context) | ||
|
||
self.assertInHTML( | ||
'<a class="page-link" href="/?description=descricao&salary_range=1&page=10">1</a>', | ||
rendered_template, | ||
) |