Package: django-global-query-strings
Django global query stringsDjango global query stringsallows adding query strings (query params) globally.The app looks for all the<a>tags in a html content thanks toBeautifulSoup.There are two ways of using the app. Each way can be used separately or conjointly:Using the middlewareGlobalQueryStringsMiddlewareUsing the utility functionadd_query_strings_to_linksInstallationInstall with pip:pip install django-global-query-stringsSetupIn order to makedjango-global-query-stringsworks, you'll need to follow the steps below:SettingsFirst, you need to add the app and the middleware to your settings. The middleware is optional depending on your usage:INSTALLED_APPS=('django.contrib.admin','django.contrib.auth','django.contrib.sessions','django.contrib.messages','global_query_strings',...)MIDDLEWARE_CLASSES=('django.middleware.common.CommonMiddleware','django.contrib.sessions.middleware.SessionMiddleware','django.contrib.auth.middleware.AuthenticationMiddleware','global_query_strings.middleware.GlobalQueryStringsMiddleware',...)SettingsHere is the list of all the settings with their default values:GLOBAL_QUERY_STRINGS_IGNORE_URLS=[]GLOBAL_QUERY_STRINGS_IGNORE_RELATIVE_PATHS=FalseGLOBAL_QUERY_STRINGS_PARAMS={}GLOBAL_QUERY_STRINGS_EXCLUDE_PATHS_LIST=[]GLOBAL_QUERY_STRINGS_IGNORE_URLSGLOBAL_QUERY_STRINGS_IGNORE_URLStakes a list of domain name or urls e.g.:["example.com", "https://www.foo.org"]. When the html parser finds those values, the global query strings won't be added to the urls.GLOBAL_QUERY_STRINGS_IGNORE_RELATIVE_PATHSGLOBAL_QUERY_STRINGS_IGNORE_RELATIVE_PATHSis a boolean. When set toTrue, the parser will ignore relative paths.GLOBAL_QUERY_STRINGS_PARAMSGLOBAL_QUERY_STRINGS_PARAMStakes a dictionary of global query strings to set e.g.:{"foo": "bar", "lorem": "ipsum"}. The query strings found inGLOBAL_QUERY_STRINGS_PARAMSwould be replaced / added to the urls found by the parser.GLOBAL_QUERY_STRINGS_EXCLUDE_PATHS_LISTGLOBAL_QUERY_STRINGS_EXCLUDE_PATHS_LISTis a list of paths to exclude that takes place in the middleware only.
All the paths that starts with any elements of the list will bypass the middleware. e.g.:["/admin"]UsageHere is an example of input / output with the following settings:GLOBAL_QUERY_STRINGS_IGNORE_URLS=["example.com","https://www.foo.org"]GLOBAL_QUERY_STRINGS_IGNORE_RELATIVE_PATHS=TrueGLOBAL_QUERY_STRINGS_PARAMS={"foo":"bar","lorem":"ipsum"}Input:<htmllang="en"><body><ahref="https://www.foo.org">Lorem Ipsum</a>is simply dummy text of the printing and typesetting industry.<ahref="https://foo.org">Lorem Ipsum</a>has been the industry's standard dummy text ever since the 1500s,
        when an unknown printer took a galley of type and scrambled it to make a type specimen book.
        It has survived not only<ahref="https://www.bar.com">five centuries</a>, but also the leap into electronic
        typesetting,<ahref="/lorem/ipsum">remaining essentially</a>unchanged.
        It was popularised in the 1960s with the release of<ahref="https://www.bar.com?example=true">Letraset sheets</a>containing Lorem Ipsum passages, and more recently with desktop<ahref="https://www.foo.org?foo=ipsum">publishing software</a>like Aldus PageMaker including versions of Lorem Ipsum.</body></html>Output:<htmllang="en"><body><ahref="https://www.foo.org">Lorem Ipsum</a>is simply dummy text of the printing and typesetting industry.<ahref="https://foo.org?foo=bar&lorem=ipsum">Lorem Ipsum</a>has been the industry's standard dummy text ever since the 1500s,
        when an unknown printer took a galley of type and scrambled it to make a type specimen book.
        It has survived not only<ahref="https://www.bar.com?foo=bar&lorem=ipsum">five centuries</a>, but also the leap into electronic
        typesetting,<ahref="/lorem/ipsum">remaining essentially</a>unchanged.
        It was popularised in the 1960s with the release of<ahref="https://www.bar.com?example=true&foo=bar&lorem=ipsum">Letraset sheets</a>containing Lorem Ipsum passages, and more recently with desktop<ahref="https://www.foo.org?foo=bar&lorem=ipsum">publishing software</a>like Aldus PageMaker including versions of Lorem Ipsum.</body></html>TestsTesting is managed bypytest. Required package for testing can be installed with:pip install -r test_requirements.txtTo run testing locally:pytest