# django-query-params
Django app providing template tags and JavaScript functions for query string management.
## Template Tag Library
To install the app, type:
```bash
(venv)$ pip install django-query-params
```
Then add `"query_params"` to the `INSTALLED_APPS` in the settings.
To use the template tags in templates:
```djangotemplate
{% load query_params_tags %}
{% modify_query ["only_query_string"] "param_to_remove" "another_param_to_remove" param_to_change="new-value" another_param_to_change="new-value" %}
{% add_to_query ["only_query_string"] "param_to_remove" "another_param_to_remove" param_to_add="new-value" another_param_to_add="new-value" %}
{% remove_from_query ["only_query_string"] "param_to_remove" another_param_to_remove="value" %}
```
## JavaScript Library
```djangotemplate
{% load static %}
<script src="{% static 'query_params/js/query_params.js' %}"></script>
<script>
var url1 = modify_query(
location,
['param_to_remove', 'another_param_to_remove'],
{
param_to_change: 'new-value',
another_param_to_change: 'new-value'
},
only_query_string=false
);
var url2 = add_to_query(
location,
['param_to_remove', 'another_param_to_remove'],
{
param_to_add: 'new-value',
another_param_to_add: 'new-value'
},
only_query_string=false
);
var url3 = remove_from_query(
location,
['param_to_remove'],
{
another_param_to_remove: 'value'
},
only_query_string=false
);
</script>
```
## Example
Let's say the current URL is:
`https://example.com/posts/?page=2&sort=by-date&tag=environment&tag=sustainability`
### modify_query
```djangotemplate
{% modify_query "page" tag="ecological" %}
```
will render:
`/posts/?sort=by-date&tag=ecological`
and
```djangotemplate
{% modify_query "only_query_string" "page" tag="ecological" %}
```
will render:
`?sort=by-date&tag=ecological`
### add_to_query
```djangotemplate
{% add_to_query "page" tag="ecological" %}
```
will render:
`/posts/?sort=by-date&tag=ecological&tag=environment&tag=sustainability`
and
```djangotemplate
{% add_to_query "only_query_string" "page" tag="ecological" %}
```
will render:
`?sort=by-date&tag=ecological&tag=environment&tag=sustainability`
### remove_from_query
```djangotemplate
{% remove_from_query "page" tag="environment" %}
```
will render:
`/posts/?sort=by-date&tag=sustainability`
and
```djangotemplate
{% remove_from_query "only_query_string" "page" tag="environment" %}
```
will render:
`?sort=by-date&tag=sustainability`
Raw data
{
"_id": null,
"home_page": "https://github.com/hyperlocalhq/django-query-params",
"name": "django-query-params",
"maintainer": "",
"docs_url": null,
"requires_python": "",
"maintainer_email": "",
"keywords": "query_params",
"author": "Aidas Bendoraitis",
"author_email": "aidasbend@yahoo.com",
"download_url": "https://files.pythonhosted.org/packages/ca/11/40751be221083ed3021e1192ba9dbf318c410a5bc530fda59e2106c85b7d/django-query-params-1.0.0.tar.gz",
"platform": null,
"description": "# django-query-params\nDjango app providing template tags and JavaScript functions for query string management.\n\n## Template Tag Library\n\nTo install the app, type:\n\n```bash\n(venv)$ pip install django-query-params\n```\n\nThen add `\"query_params\"` to the `INSTALLED_APPS` in the settings.\n\nTo use the template tags in templates:\n\n```djangotemplate\n{% load query_params_tags %}\n\n{% modify_query [\"only_query_string\"] \"param_to_remove\" \"another_param_to_remove\" param_to_change=\"new-value\" another_param_to_change=\"new-value\" %}\n\n{% add_to_query [\"only_query_string\"] \"param_to_remove\" \"another_param_to_remove\" param_to_add=\"new-value\" another_param_to_add=\"new-value\" %}\n\n{% remove_from_query [\"only_query_string\"] \"param_to_remove\" another_param_to_remove=\"value\" %}\n```\n\n## JavaScript Library\n\n```djangotemplate\n{% load static %}\n<script src=\"{% static 'query_params/js/query_params.js' %}\"></script>\n\n<script>\nvar url1 = modify_query(\n location, \n ['param_to_remove', 'another_param_to_remove'], \n {\n param_to_change: 'new-value',\n another_param_to_change: 'new-value'\n },\n only_query_string=false\n);\n\nvar url2 = add_to_query(\n location,\n ['param_to_remove', 'another_param_to_remove'],\n {\n param_to_add: 'new-value',\n another_param_to_add: 'new-value'\n },\n only_query_string=false\n);\n\nvar url3 = remove_from_query(\n location,\n ['param_to_remove'],\n {\n another_param_to_remove: 'value'\n },\n only_query_string=false\n);\n</script>\n```\n\n## Example\n\nLet's say the current URL is: \n`https://example.com/posts/?page=2&sort=by-date&tag=environment&tag=sustainability`\n\n### modify_query\n\n```djangotemplate\n{% modify_query \"page\" tag=\"ecological\" %}\n```\n\nwill render:\n\n`/posts/?sort=by-date&tag=ecological`\n\nand\n\n```djangotemplate\n{% modify_query \"only_query_string\" \"page\" tag=\"ecological\" %}\n```\n\nwill render:\n\n`?sort=by-date&tag=ecological`\n\n### add_to_query\n\n```djangotemplate\n{% add_to_query \"page\" tag=\"ecological\" %}\n```\n\nwill render:\n\n`/posts/?sort=by-date&tag=ecological&tag=environment&tag=sustainability`\n\nand\n\n```djangotemplate\n{% add_to_query \"only_query_string\" \"page\" tag=\"ecological\" %}\n```\n\nwill render:\n\n`?sort=by-date&tag=ecological&tag=environment&tag=sustainability`\n\n### remove_from_query\n\n```djangotemplate\n{% remove_from_query \"page\" tag=\"environment\" %}\n```\n\nwill render:\n\n`/posts/?sort=by-date&tag=sustainability`\n\nand\n\n```djangotemplate\n{% remove_from_query \"only_query_string\" \"page\" tag=\"environment\" %}\n```\n\nwill render:\n\n`?sort=by-date&tag=sustainability`\n",
"bugtrack_url": null,
"license": "MIT license",
"summary": "A Django app providing template tags for query string management",
"version": "1.0.0",
"split_keywords": [
"query_params"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "0494ff2f6233e4d6904be6c5e924e5c5ad62ea45401f1fa98401377abd44a45d",
"md5": "2d27b753853ceba5768e456fbb64ea19",
"sha256": "e672761d68356943bdf805d063e5ccc7886b438402c293b911aca0ff7df2a13f"
},
"downloads": -1,
"filename": "django_query_params-1.0.0-py3-none-any.whl",
"has_sig": false,
"md5_digest": "2d27b753853ceba5768e456fbb64ea19",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": null,
"size": 8479,
"upload_time": "2023-04-06T08:39:39",
"upload_time_iso_8601": "2023-04-06T08:39:39.221178Z",
"url": "https://files.pythonhosted.org/packages/04/94/ff2f6233e4d6904be6c5e924e5c5ad62ea45401f1fa98401377abd44a45d/django_query_params-1.0.0-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "ca1140751be221083ed3021e1192ba9dbf318c410a5bc530fda59e2106c85b7d",
"md5": "75010c39c3ac6bc60bc00f414907ac65",
"sha256": "9e6cc1293c9c8be0ac4869e9e1c5bc6d5ef090e7ce94cfbbc3697ca67f399aa8"
},
"downloads": -1,
"filename": "django-query-params-1.0.0.tar.gz",
"has_sig": false,
"md5_digest": "75010c39c3ac6bc60bc00f414907ac65",
"packagetype": "sdist",
"python_version": "source",
"requires_python": null,
"size": 6827,
"upload_time": "2023-04-06T08:39:41",
"upload_time_iso_8601": "2023-04-06T08:39:41.531456Z",
"url": "https://files.pythonhosted.org/packages/ca/11/40751be221083ed3021e1192ba9dbf318c410a5bc530fda59e2106c85b7d/django-query-params-1.0.0.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2023-04-06 08:39:41",
"github": true,
"gitlab": false,
"bitbucket": false,
"github_user": "hyperlocalhq",
"github_project": "django-query-params",
"travis_ci": false,
"coveralls": false,
"github_actions": false,
"lcname": "django-query-params"
}