adunblock-server-tag-django 1.0.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,15 @@
1
+ ISC License
2
+
3
+ Copyright (c) 2024 Adunblock
4
+
5
+ Permission to use, copy, modify, and/or distribute this software for any
6
+ purpose with or without fee is hereby granted, provided that the above
7
+ copyright notice and this permission notice appear in all copies.
8
+
9
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10
+ WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11
+ MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12
+ ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13
+ WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14
+ ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15
+ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
@@ -0,0 +1,8 @@
1
+ include README.md
2
+ include LICENSE
3
+ include pyproject.toml
4
+ recursive-include server_tag *.py
5
+ recursive-include server_tag/templatetags *.py
6
+ global-exclude *.pyc
7
+ global-exclude __pycache__
8
+ global-exclude .DS_Store
@@ -0,0 +1,144 @@
1
+ Metadata-Version: 2.4
2
+ Name: adunblock-server-tag-django
3
+ Version: 1.0.0
4
+ Summary: A Django package to fetch and render scripts from a remote URL with template tag integration and caching support.
5
+ Author-email: Adunblock <dev@adunblock.com>
6
+ License: ISC
7
+ Project-URL: Homepage, https://github.com/adunblock/adunblock-server-tag
8
+ Project-URL: Repository, https://github.com/adunblock/adunblock-server-tag
9
+ Project-URL: Issues, https://github.com/adunblock/adunblock-server-tag/issues
10
+ Keywords: django,python,server-tag,script-loading,remote-scripts,template-tags
11
+ Classifier: Development Status :: 5 - Production/Stable
12
+ Classifier: Environment :: Web Environment
13
+ Classifier: Framework :: Django
14
+ Classifier: Framework :: Django :: 3.2
15
+ Classifier: Framework :: Django :: 4.0
16
+ Classifier: Framework :: Django :: 4.1
17
+ Classifier: Framework :: Django :: 4.2
18
+ Classifier: Framework :: Django :: 5.0
19
+ Classifier: Intended Audience :: Developers
20
+ Classifier: License :: OSI Approved :: ISC License (ISCL)
21
+ Classifier: Operating System :: OS Independent
22
+ Classifier: Programming Language :: Python
23
+ Classifier: Programming Language :: Python :: 3
24
+ Classifier: Programming Language :: Python :: 3.8
25
+ Classifier: Programming Language :: Python :: 3.9
26
+ Classifier: Programming Language :: Python :: 3.10
27
+ Classifier: Programming Language :: Python :: 3.11
28
+ Classifier: Programming Language :: Python :: 3.12
29
+ Classifier: Topic :: Internet :: WWW/HTTP
30
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
31
+ Requires-Python: >=3.8
32
+ Description-Content-Type: text/markdown
33
+ License-File: LICENSE
34
+ Requires-Dist: Django>=3.2
35
+ Requires-Dist: requests>=2.25.0
36
+ Dynamic: license-file
37
+
38
+ # Server Tag Django Package
39
+
40
+ A Django package to fetch and render scripts from a remote URL with template tag integration and caching support.
41
+
42
+ ## Installation
43
+
44
+ Install the package via pip:
45
+
46
+ ```bash
47
+ pip install adunblock-server-tag-django
48
+ ```
49
+
50
+ Add the `server_tag` app to your `INSTALLED_APPS` in your Django `settings.py`:
51
+
52
+ ```python
53
+ INSTALLED_APPS = [
54
+ # ... other apps
55
+ 'server_tag',
56
+ ]
57
+ ```
58
+
59
+ Configure caching in your `settings.py` (recommended for production):
60
+
61
+ ```python
62
+ CACHES = {
63
+ 'default': {
64
+ 'BACKEND': 'django.core.cache.backends.redis.RedisCache',
65
+ 'LOCATION': 'redis://127.0.0.1:6379/1',
66
+ }
67
+ }
68
+
69
+ # Or for development, use local memory cache:
70
+ CACHES = {
71
+ 'default': {
72
+ 'BACKEND': 'django.core.cache.backends.locmem.LocMemCache',
73
+ 'LOCATION': 'unique-snowflake',
74
+ }
75
+ }
76
+ ```
77
+
78
+ ## Usage
79
+
80
+ In your Django template, load the `server_tag_tags` and use the `server_tag` tag:
81
+
82
+ ```html
83
+ {% load server_tag_tags %}
84
+
85
+ <!DOCTYPE html>
86
+ <html>
87
+ <head>
88
+ <title>My Page</title>
89
+ {% server_tag "https://your-remote-url.com/scripts" %}
90
+ </head>
91
+ <body>
92
+ <h1>My Page</h1>
93
+ </body>
94
+ </html>
95
+ ```
96
+
97
+ ### Custom Rendering
98
+
99
+ You can provide a custom Python function to the `render_script` parameter to customize how script tags are rendered:
100
+
101
+ ```python
102
+ # my_app/templatetags/custom_tags.py
103
+ from django import template
104
+ from django.utils.safestring import mark_safe
105
+
106
+ register = template.Library()
107
+
108
+ @register.simple_tag
109
+ def custom_script_renderer(js_files):
110
+ from django.utils.html import escape
111
+ scripts = [f'<script src="{escape(src)}" defer></script>' for src in js_files.get('js', [])]
112
+ return mark_safe('\n'.join(scripts))
113
+ ```
114
+
115
+ ```html
116
+ {% load server_tag_tags %}
117
+ {% load custom_tags %}
118
+
119
+ <!DOCTYPE html>
120
+ <html>
121
+ <head>
122
+ <title>My Page</title>
123
+ {% server_tag "https://your-remote-url.com/scripts" render_script=custom_script_renderer %}
124
+ </head>
125
+ <body>
126
+ <h1>My Page</h1>
127
+ </body>
128
+ </html>
129
+ ```
130
+
131
+ ## Features
132
+
133
+ - **Template Tag Integration**: Easy-to-use Django template tag
134
+ - **HTTP Client**: Uses requests library for reliable HTTP operations
135
+ - **Caching**: Built-in Django cache integration with configurable TTL
136
+ - **Error Handling**: Graceful error handling with fallback to empty arrays
137
+ - **Security**: XSS protection with proper HTML escaping
138
+ - **Django Integration**: Proper Django app structure with apps.py
139
+
140
+ ## Requirements
141
+
142
+ - Python 3.8 or higher
143
+ - Django 3.2 or higher
144
+ - requests 2.25.0 or higher
@@ -0,0 +1,107 @@
1
+ # Server Tag Django Package
2
+
3
+ A Django package to fetch and render scripts from a remote URL with template tag integration and caching support.
4
+
5
+ ## Installation
6
+
7
+ Install the package via pip:
8
+
9
+ ```bash
10
+ pip install adunblock-server-tag-django
11
+ ```
12
+
13
+ Add the `server_tag` app to your `INSTALLED_APPS` in your Django `settings.py`:
14
+
15
+ ```python
16
+ INSTALLED_APPS = [
17
+ # ... other apps
18
+ 'server_tag',
19
+ ]
20
+ ```
21
+
22
+ Configure caching in your `settings.py` (recommended for production):
23
+
24
+ ```python
25
+ CACHES = {
26
+ 'default': {
27
+ 'BACKEND': 'django.core.cache.backends.redis.RedisCache',
28
+ 'LOCATION': 'redis://127.0.0.1:6379/1',
29
+ }
30
+ }
31
+
32
+ # Or for development, use local memory cache:
33
+ CACHES = {
34
+ 'default': {
35
+ 'BACKEND': 'django.core.cache.backends.locmem.LocMemCache',
36
+ 'LOCATION': 'unique-snowflake',
37
+ }
38
+ }
39
+ ```
40
+
41
+ ## Usage
42
+
43
+ In your Django template, load the `server_tag_tags` and use the `server_tag` tag:
44
+
45
+ ```html
46
+ {% load server_tag_tags %}
47
+
48
+ <!DOCTYPE html>
49
+ <html>
50
+ <head>
51
+ <title>My Page</title>
52
+ {% server_tag "https://your-remote-url.com/scripts" %}
53
+ </head>
54
+ <body>
55
+ <h1>My Page</h1>
56
+ </body>
57
+ </html>
58
+ ```
59
+
60
+ ### Custom Rendering
61
+
62
+ You can provide a custom Python function to the `render_script` parameter to customize how script tags are rendered:
63
+
64
+ ```python
65
+ # my_app/templatetags/custom_tags.py
66
+ from django import template
67
+ from django.utils.safestring import mark_safe
68
+
69
+ register = template.Library()
70
+
71
+ @register.simple_tag
72
+ def custom_script_renderer(js_files):
73
+ from django.utils.html import escape
74
+ scripts = [f'<script src="{escape(src)}" defer></script>' for src in js_files.get('js', [])]
75
+ return mark_safe('\n'.join(scripts))
76
+ ```
77
+
78
+ ```html
79
+ {% load server_tag_tags %}
80
+ {% load custom_tags %}
81
+
82
+ <!DOCTYPE html>
83
+ <html>
84
+ <head>
85
+ <title>My Page</title>
86
+ {% server_tag "https://your-remote-url.com/scripts" render_script=custom_script_renderer %}
87
+ </head>
88
+ <body>
89
+ <h1>My Page</h1>
90
+ </body>
91
+ </html>
92
+ ```
93
+
94
+ ## Features
95
+
96
+ - **Template Tag Integration**: Easy-to-use Django template tag
97
+ - **HTTP Client**: Uses requests library for reliable HTTP operations
98
+ - **Caching**: Built-in Django cache integration with configurable TTL
99
+ - **Error Handling**: Graceful error handling with fallback to empty arrays
100
+ - **Security**: XSS protection with proper HTML escaping
101
+ - **Django Integration**: Proper Django app structure with apps.py
102
+
103
+ ## Requirements
104
+
105
+ - Python 3.8 or higher
106
+ - Django 3.2 or higher
107
+ - requests 2.25.0 or higher
@@ -0,0 +1,144 @@
1
+ Metadata-Version: 2.4
2
+ Name: adunblock-server-tag-django
3
+ Version: 1.0.0
4
+ Summary: A Django package to fetch and render scripts from a remote URL with template tag integration and caching support.
5
+ Author-email: Adunblock <dev@adunblock.com>
6
+ License: ISC
7
+ Project-URL: Homepage, https://github.com/adunblock/adunblock-server-tag
8
+ Project-URL: Repository, https://github.com/adunblock/adunblock-server-tag
9
+ Project-URL: Issues, https://github.com/adunblock/adunblock-server-tag/issues
10
+ Keywords: django,python,server-tag,script-loading,remote-scripts,template-tags
11
+ Classifier: Development Status :: 5 - Production/Stable
12
+ Classifier: Environment :: Web Environment
13
+ Classifier: Framework :: Django
14
+ Classifier: Framework :: Django :: 3.2
15
+ Classifier: Framework :: Django :: 4.0
16
+ Classifier: Framework :: Django :: 4.1
17
+ Classifier: Framework :: Django :: 4.2
18
+ Classifier: Framework :: Django :: 5.0
19
+ Classifier: Intended Audience :: Developers
20
+ Classifier: License :: OSI Approved :: ISC License (ISCL)
21
+ Classifier: Operating System :: OS Independent
22
+ Classifier: Programming Language :: Python
23
+ Classifier: Programming Language :: Python :: 3
24
+ Classifier: Programming Language :: Python :: 3.8
25
+ Classifier: Programming Language :: Python :: 3.9
26
+ Classifier: Programming Language :: Python :: 3.10
27
+ Classifier: Programming Language :: Python :: 3.11
28
+ Classifier: Programming Language :: Python :: 3.12
29
+ Classifier: Topic :: Internet :: WWW/HTTP
30
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
31
+ Requires-Python: >=3.8
32
+ Description-Content-Type: text/markdown
33
+ License-File: LICENSE
34
+ Requires-Dist: Django>=3.2
35
+ Requires-Dist: requests>=2.25.0
36
+ Dynamic: license-file
37
+
38
+ # Server Tag Django Package
39
+
40
+ A Django package to fetch and render scripts from a remote URL with template tag integration and caching support.
41
+
42
+ ## Installation
43
+
44
+ Install the package via pip:
45
+
46
+ ```bash
47
+ pip install adunblock-server-tag-django
48
+ ```
49
+
50
+ Add the `server_tag` app to your `INSTALLED_APPS` in your Django `settings.py`:
51
+
52
+ ```python
53
+ INSTALLED_APPS = [
54
+ # ... other apps
55
+ 'server_tag',
56
+ ]
57
+ ```
58
+
59
+ Configure caching in your `settings.py` (recommended for production):
60
+
61
+ ```python
62
+ CACHES = {
63
+ 'default': {
64
+ 'BACKEND': 'django.core.cache.backends.redis.RedisCache',
65
+ 'LOCATION': 'redis://127.0.0.1:6379/1',
66
+ }
67
+ }
68
+
69
+ # Or for development, use local memory cache:
70
+ CACHES = {
71
+ 'default': {
72
+ 'BACKEND': 'django.core.cache.backends.locmem.LocMemCache',
73
+ 'LOCATION': 'unique-snowflake',
74
+ }
75
+ }
76
+ ```
77
+
78
+ ## Usage
79
+
80
+ In your Django template, load the `server_tag_tags` and use the `server_tag` tag:
81
+
82
+ ```html
83
+ {% load server_tag_tags %}
84
+
85
+ <!DOCTYPE html>
86
+ <html>
87
+ <head>
88
+ <title>My Page</title>
89
+ {% server_tag "https://your-remote-url.com/scripts" %}
90
+ </head>
91
+ <body>
92
+ <h1>My Page</h1>
93
+ </body>
94
+ </html>
95
+ ```
96
+
97
+ ### Custom Rendering
98
+
99
+ You can provide a custom Python function to the `render_script` parameter to customize how script tags are rendered:
100
+
101
+ ```python
102
+ # my_app/templatetags/custom_tags.py
103
+ from django import template
104
+ from django.utils.safestring import mark_safe
105
+
106
+ register = template.Library()
107
+
108
+ @register.simple_tag
109
+ def custom_script_renderer(js_files):
110
+ from django.utils.html import escape
111
+ scripts = [f'<script src="{escape(src)}" defer></script>' for src in js_files.get('js', [])]
112
+ return mark_safe('\n'.join(scripts))
113
+ ```
114
+
115
+ ```html
116
+ {% load server_tag_tags %}
117
+ {% load custom_tags %}
118
+
119
+ <!DOCTYPE html>
120
+ <html>
121
+ <head>
122
+ <title>My Page</title>
123
+ {% server_tag "https://your-remote-url.com/scripts" render_script=custom_script_renderer %}
124
+ </head>
125
+ <body>
126
+ <h1>My Page</h1>
127
+ </body>
128
+ </html>
129
+ ```
130
+
131
+ ## Features
132
+
133
+ - **Template Tag Integration**: Easy-to-use Django template tag
134
+ - **HTTP Client**: Uses requests library for reliable HTTP operations
135
+ - **Caching**: Built-in Django cache integration with configurable TTL
136
+ - **Error Handling**: Graceful error handling with fallback to empty arrays
137
+ - **Security**: XSS protection with proper HTML escaping
138
+ - **Django Integration**: Proper Django app structure with apps.py
139
+
140
+ ## Requirements
141
+
142
+ - Python 3.8 or higher
143
+ - Django 3.2 or higher
144
+ - requests 2.25.0 or higher
@@ -0,0 +1,14 @@
1
+ LICENSE
2
+ MANIFEST.in
3
+ README.md
4
+ pyproject.toml
5
+ setup.py
6
+ adunblock_server_tag_django.egg-info/PKG-INFO
7
+ adunblock_server_tag_django.egg-info/SOURCES.txt
8
+ adunblock_server_tag_django.egg-info/dependency_links.txt
9
+ adunblock_server_tag_django.egg-info/requires.txt
10
+ adunblock_server_tag_django.egg-info/top_level.txt
11
+ server_tag/__init__.py
12
+ server_tag/apps.py
13
+ server_tag/templatetags/__init__.py
14
+ server_tag/templatetags/server_tag_tags.py
@@ -0,0 +1,2 @@
1
+ Django>=3.2
2
+ requests>=2.25.0
@@ -0,0 +1,52 @@
1
+ [build-system]
2
+ requires = ["setuptools>=61.0", "wheel"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "adunblock-server-tag-django"
7
+ version = "1.0.0"
8
+ description = "A Django package to fetch and render scripts from a remote URL with template tag integration and caching support."
9
+ readme = "README.md"
10
+ license = {text = "ISC"}
11
+ authors = [
12
+ {name = "Adunblock", email = "dev@adunblock.com"}
13
+ ]
14
+ keywords = ["django", "python", "server-tag", "script-loading", "remote-scripts", "template-tags"]
15
+ classifiers = [
16
+ "Development Status :: 5 - Production/Stable",
17
+ "Environment :: Web Environment",
18
+ "Framework :: Django",
19
+ "Framework :: Django :: 3.2",
20
+ "Framework :: Django :: 4.0",
21
+ "Framework :: Django :: 4.1",
22
+ "Framework :: Django :: 4.2",
23
+ "Framework :: Django :: 5.0",
24
+ "Intended Audience :: Developers",
25
+ "License :: OSI Approved :: ISC License (ISCL)",
26
+ "Operating System :: OS Independent",
27
+ "Programming Language :: Python",
28
+ "Programming Language :: Python :: 3",
29
+ "Programming Language :: Python :: 3.8",
30
+ "Programming Language :: Python :: 3.9",
31
+ "Programming Language :: Python :: 3.10",
32
+ "Programming Language :: Python :: 3.11",
33
+ "Programming Language :: Python :: 3.12",
34
+ "Topic :: Internet :: WWW/HTTP",
35
+ "Topic :: Software Development :: Libraries :: Python Modules",
36
+ ]
37
+ requires-python = ">=3.8"
38
+ dependencies = [
39
+ "Django>=3.2",
40
+ "requests>=2.25.0",
41
+ ]
42
+
43
+ [project.urls]
44
+ Homepage = "https://github.com/adunblock/adunblock-server-tag"
45
+ Repository = "https://github.com/adunblock/adunblock-server-tag"
46
+ Issues = "https://github.com/adunblock/adunblock-server-tag/issues"
47
+
48
+ [tool.setuptools.packages.find]
49
+ include = ["server_tag*"]
50
+
51
+ [tool.setuptools.package-data]
52
+ server_tag = ["templatetags/*.py"]
@@ -0,0 +1,10 @@
1
+ """
2
+ Django Server Tag Package
3
+
4
+ A Django package to fetch and render scripts from a remote URL with template tag integration.
5
+ """
6
+
7
+ __version__ = '1.0.0'
8
+ __author__ = 'Adunblock'
9
+
10
+ default_app_config = 'server_tag.apps.ServerTagConfig'
@@ -0,0 +1,7 @@
1
+ from django.apps import AppConfig
2
+
3
+
4
+ class ServerTagConfig(AppConfig):
5
+ default_auto_field = 'django.db.models.BigAutoField'
6
+ name = 'server_tag'
7
+ verbose_name = 'Server Tag'
@@ -0,0 +1,40 @@
1
+
2
+ import requests
3
+ from django import template
4
+ from django.core.cache import cache
5
+ from django.utils.safestring import mark_safe
6
+
7
+ register = template.Library()
8
+
9
+ @register.simple_tag
10
+ def server_tag(remote_url, cache_interval=300, render_script=None):
11
+ cached_data = cache.get(remote_url)
12
+
13
+ if cached_data:
14
+ js_files = cached_data
15
+ else:
16
+ try:
17
+ response = requests.get(remote_url)
18
+ response.raise_for_status()
19
+ data = response.json()
20
+ # New format: API returns array directly instead of object with js property
21
+ if isinstance(data, list):
22
+ # New format: array directly
23
+ js_files = {'js': data}
24
+ elif isinstance(data, dict) and 'js' in data:
25
+ # Old format: object with js property (backward compatibility)
26
+ js_files = data
27
+ else:
28
+ js_files = {'js': []}
29
+ cache.set(remote_url, js_files, cache_interval)
30
+ except requests.exceptions.RequestException as e:
31
+ print(f'Error fetching remote script: {e}')
32
+ js_files = {'js': []}
33
+
34
+ if render_script:
35
+ return mark_safe(render_script(js_files))
36
+ else:
37
+ from django.utils.html import escape
38
+ scripts = [f'<script src="{escape(src)}" async></script>' for src in js_files.get('js', [])]
39
+ return mark_safe('\n'.join(scripts))
40
+
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1,16 @@
1
+ from setuptools import setup, find_packages
2
+
3
+ setup(
4
+ name='adunblock-server-tag-django',
5
+ version='1.0.0',
6
+ packages=find_packages(),
7
+ include_package_data=True,
8
+ license='ISC',
9
+ description='A Django package to fetch and render scripts from a remote URL.',
10
+ long_description=open('README.md').read(),
11
+ long_description_content_type='text/markdown',
12
+ install_requires=[
13
+ 'Django',
14
+ 'requests',
15
+ ],
16
+ )