dj-templates 0.0.1__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.
Files changed (97) hide show
  1. dj_templates-0.0.1/LICENSE +5 -0
  2. dj_templates-0.0.1/LICENSE.md +19 -0
  3. dj_templates-0.0.1/PKG-INFO +173 -0
  4. dj_templates-0.0.1/README.md +155 -0
  5. dj_templates-0.0.1/django_templates/__init__.py +8 -0
  6. dj_templates-0.0.1/django_templates/apps.py +72 -0
  7. dj_templates-0.0.1/django_templates/builtin_themes.yml +119 -0
  8. dj_templates-0.0.1/django_templates/context_processors.py +60 -0
  9. dj_templates-0.0.1/django_templates/django_templates.py +19 -0
  10. dj_templates-0.0.1/django_templates/locale/.include_directory +0 -0
  11. dj_templates-0.0.1/django_templates/locale/de/LC_MESSAGES/django.po +34 -0
  12. dj_templates-0.0.1/django_templates/mixins/__init__.py +0 -0
  13. dj_templates-0.0.1/django_templates/mixins/htmx.py +46 -0
  14. dj_templates-0.0.1/django_templates/mixins/theme.py +74 -0
  15. dj_templates-0.0.1/django_templates/settings.py +59 -0
  16. dj_templates-0.0.1/django_templates/static/assets/css/bootstrap5.css +20246 -0
  17. dj_templates-0.0.1/django_templates/static/assets/css/bootstrap5.css.map +1 -0
  18. dj_templates-0.0.1/django_templates/static/assets/css/bootstrap5.min.css +9 -0
  19. dj_templates-0.0.1/django_templates/static/assets/css/bootstrap5.min.css.map +1 -0
  20. dj_templates-0.0.1/django_templates/static/assets/css/bs5docs.css +17 -0
  21. dj_templates-0.0.1/django_templates/static/assets/css/bs5docs.css.map +1 -0
  22. dj_templates-0.0.1/django_templates/static/assets/css/bs5docs.min.css +17 -0
  23. dj_templates-0.0.1/django_templates/static/assets/css/bs5docs.min.css.map +1 -0
  24. dj_templates-0.0.1/django_templates/static/assets/css/html.css +215 -0
  25. dj_templates-0.0.1/django_templates/static/assets/css/tailwind.min.css +0 -0
  26. dj_templates-0.0.1/django_templates/static/assets/fonts/bootstrap-icons.woff +0 -0
  27. dj_templates-0.0.1/django_templates/static/assets/fonts/bootstrap-icons.woff2 +0 -0
  28. dj_templates-0.0.1/django_templates/static/assets/img/bookmarks.svg +4 -0
  29. dj_templates-0.0.1/django_templates/static/assets/img/django-python-logo.png +0 -0
  30. dj_templates-0.0.1/django_templates/static/assets/img/django-templates-favicon.ico +0 -0
  31. dj_templates-0.0.1/django_templates/static/assets/img/django-templates-logo-dark.svg +47 -0
  32. dj_templates-0.0.1/django_templates/static/assets/img/django-templates-logo-light.svg +47 -0
  33. dj_templates-0.0.1/django_templates/static/assets/img/django-templates-logo.png +0 -0
  34. dj_templates-0.0.1/django_templates/static/assets/img/django-templates-logo.svg +47 -0
  35. dj_templates-0.0.1/django_templates/static/assets/js/bootstrap.min.js +7 -0
  36. dj_templates-0.0.1/django_templates/static/assets/js/htmx.min.js +1 -0
  37. dj_templates-0.0.1/django_templates/static/assets/js/popper.min.js +6 -0
  38. dj_templates-0.0.1/django_templates/static/assets/legal/de/django-templates.LICENSE.html +31 -0
  39. dj_templates-0.0.1/django_templates/static/assets/legal/de/django-templates.LICENSE.md +9 -0
  40. dj_templates-0.0.1/django_templates/static/assets/legal/de/django-templates.LICENSE.txt +21 -0
  41. dj_templates-0.0.1/django_templates/static/assets/legal/django-templates.LICENSE.html +33 -0
  42. dj_templates-0.0.1/django_templates/static/assets/legal/django-templates.LICENSE.md +20 -0
  43. dj_templates-0.0.1/django_templates/static/assets/legal/django-templates.LICENSE.txt +18 -0
  44. dj_templates-0.0.1/django_templates/static/assets/scss/bootstrap5.scss +48 -0
  45. dj_templates-0.0.1/django_templates/static/assets/scss/bs5docs.scss +45 -0
  46. dj_templates-0.0.1/django_templates/static/assets/scss/tailwind.scss +0 -0
  47. dj_templates-0.0.1/django_templates/templates/django_templates/license.html +0 -0
  48. dj_templates-0.0.1/django_templates/templates/django_templates/test.dj.html +56 -0
  49. dj_templates-0.0.1/django_templates/templates/themes/bootstrap5/base.dj.html +57 -0
  50. dj_templates-0.0.1/django_templates/templates/themes/bootstrap5/breadcrumbs.dj.html +22 -0
  51. dj_templates-0.0.1/django_templates/templates/themes/bootstrap5/extra_body.dj.html +6 -0
  52. dj_templates-0.0.1/django_templates/templates/themes/bootstrap5/footer.dj.html +7 -0
  53. dj_templates-0.0.1/django_templates/templates/themes/bootstrap5/head.dj.html +27 -0
  54. dj_templates-0.0.1/django_templates/templates/themes/bootstrap5/header.dj.html +23 -0
  55. dj_templates-0.0.1/django_templates/templates/themes/bootstrap5/nav.dj.html +77 -0
  56. dj_templates-0.0.1/django_templates/templates/themes/bootstrap5/secondary_sidebar.dj.html +0 -0
  57. dj_templates-0.0.1/django_templates/templates/themes/bootstrap5/sidebar.dj.html +24 -0
  58. dj_templates-0.0.1/django_templates/templates/themes/bs5docs/base.dj.html +59 -0
  59. dj_templates-0.0.1/django_templates/templates/themes/bs5docs/breadcrumbs.dj.html +22 -0
  60. dj_templates-0.0.1/django_templates/templates/themes/bs5docs/footer.dj.html +7 -0
  61. dj_templates-0.0.1/django_templates/templates/themes/bs5docs/head.dj.html +21 -0
  62. dj_templates-0.0.1/django_templates/templates/themes/bs5docs/header.dj.html +12 -0
  63. dj_templates-0.0.1/django_templates/templates/themes/bs5docs/nav.dj.html +75 -0
  64. dj_templates-0.0.1/django_templates/templates/themes/bs5docs/page_title.dj.html +6 -0
  65. dj_templates-0.0.1/django_templates/templates/themes/bs5docs/secondary_sidebar.dj.html +2 -0
  66. dj_templates-0.0.1/django_templates/templates/themes/bs5docs/sidebar.dj.html +30 -0
  67. dj_templates-0.0.1/django_templates/templates/themes/html/base.dj.html +32 -0
  68. dj_templates-0.0.1/django_templates/templates/themes/html/breadcrumbs.dj.html +24 -0
  69. dj_templates-0.0.1/django_templates/templates/themes/html/extra_body.dj.html +2 -0
  70. dj_templates-0.0.1/django_templates/templates/themes/html/footer.dj.html +5 -0
  71. dj_templates-0.0.1/django_templates/templates/themes/html/form.html +8 -0
  72. dj_templates-0.0.1/django_templates/templates/themes/html/head.dj.html +28 -0
  73. dj_templates-0.0.1/django_templates/templates/themes/html/header.dj.html +21 -0
  74. dj_templates-0.0.1/django_templates/templates/themes/html/nav.dj.html +51 -0
  75. dj_templates-0.0.1/django_templates/templates/themes/html/secondary_sidebar.dj.html +0 -0
  76. dj_templates-0.0.1/django_templates/templates/themes/html/sidebar.dj.html +26 -0
  77. dj_templates-0.0.1/django_templates/templates/themes/tailwindcss4/base.dj.html +0 -0
  78. dj_templates-0.0.1/django_templates/templates/themes/tailwindcss4/breadcrumbs.dj.html +0 -0
  79. dj_templates-0.0.1/django_templates/templates/themes/tailwindcss4/footer.dj.html +0 -0
  80. dj_templates-0.0.1/django_templates/templates/themes/tailwindcss4/head.dj.html +10 -0
  81. dj_templates-0.0.1/django_templates/templates/themes/tailwindcss4/nav.dj.html +0 -0
  82. dj_templates-0.0.1/django_templates/templates/themes/tailwindcss4/secondary_sidebar.dj.html +0 -0
  83. dj_templates-0.0.1/django_templates/templates/themes/tailwindcss4/sidebar.dj.html +0 -0
  84. dj_templates-0.0.1/django_templates/templatetags/__init__.py +0 -0
  85. dj_templates-0.0.1/django_templates/templatetags/templates.py +169 -0
  86. dj_templates-0.0.1/django_templates/tests/__init__.py +0 -0
  87. dj_templates-0.0.1/django_templates/tests/test_Theme.py +170 -0
  88. dj_templates-0.0.1/django_templates/tests/test_ThemeManager.py +0 -0
  89. dj_templates-0.0.1/django_templates/theme/__init__.py +7 -0
  90. dj_templates-0.0.1/django_templates/theme/manager.py +264 -0
  91. dj_templates-0.0.1/django_templates/theme/theme.py +404 -0
  92. dj_templates-0.0.1/django_templates/urls.py +10 -0
  93. dj_templates-0.0.1/django_templates/utils/__init__.py +0 -0
  94. dj_templates-0.0.1/django_templates/utils/logging.py +44 -0
  95. dj_templates-0.0.1/django_templates/utils/theme.py +144 -0
  96. dj_templates-0.0.1/django_templates/views.py +127 -0
  97. dj_templates-0.0.1/pyproject.toml +48 -0
@@ -0,0 +1,5 @@
1
+ Weiterverbreitung und Verwendung in nichtkompilierter oder kompilierter Form, mit oder ohne Veränderung, sind unter den folgenden Bedingungen zulässig:
2
+
3
+ Weiterverbreitete Software-Quelltexte müssen den obigen Copyright-Vermerk, diese Liste der Bedingungen und die ihnen folgende Haftungsklausel enthalten.
4
+
5
+ DIESE SOFTWARE WIRD VOM AUTOR UND DEN BEITRAGSLEISTENDEN OHNE JEGLICHE AUSDRÜCKLICHE ODER IMPLIZIERTE GARANTIEN ZUR VERFÜGUNG GESTELLT, DIE UNTER ANDEREM EINSCHLIESSEN: DIE IMPLIZIERTE GARANTIE DER VERWENDBARKEIT DER SOFTWARE FÜR EINEN BESTIMMTEN ZWECK. AUF KEINEN FALL SIND DER AUTOR ODER DIE BEITRAGSLEISTENDEN FÜR IRGENDWELCHE DIREKTEN, INDIREKTEN, ZUFÄLLIGEN, SPEZIELLEN, BEISPIELHAFTEN ODER FOLGESCHÄDEN (UNTER ANDEREM VERSCHAFFEN VON ERSATZGÜTERN ODER -DIENSTLEISTUNGEN; EINSCHRÄNKUNG DER NUTZUNGSFÄHIGKEIT; VERLUST VON NUTZUNGSFÄHIGKEIT, DATEN, ODER PROFIT; ODER GESCHÄFTSUNTERBRECHUNG), WIE AUCH IMMER VERURSACHT UND UNTER WELCHER VERPFLICHTUNG AUCH IMMER, OB IN VERTRAG, STRIKTER VERPFLICHTUNG ODER UNERLAUBTER HANDLUNG (INKLUSIVE FAHRLÄSSIGKEIT) VERANTWORTLICH, AUF WELCHEM WEG SIE AUCH IMMER DURCH DIE BENUTZUNG DIESER SOFTWARE ENTSTANDEN SIND, SOGAR, WENN SIE AUF DIE MÖGLICHKEIT EINES SOLCHEN SCHADENS HINGEWIESEN WORDEN SIND.
@@ -0,0 +1,19 @@
1
+ # DJ Templates Lizenz
2
+ **Weiterverbreitung und Verwendung in nichtkompilierter oder kompilierter Form,
3
+ mit oder ohne Veränderung, sind unter den folgenden Bedingungen zulässig:**
4
+
5
+ 1. Weiterverbreitete Software-Quelltexte müssen den obigen Copyright-Vermerk,
6
+ diese Liste der Bedingungen und die ihnen folgende Haftungsklausel enthalten.
7
+
8
+ DIESE SOFTWARE WIRD VOM AUTOR UND DEN BEITRAGSLEISTENDEN OHNE JEGLICHE AUSDRÜCKLICHE
9
+ ODER IMPLIZIERTE GARANTIEN ZUR VERFÜGUNG GESTELLT, DIE UNTER ANDEREM EINSCHLIESSEN:
10
+ DIE IMPLIZIERTE GARANTIE DER VERWENDBARKEIT DER SOFTWARE FÜR EINEN BESTIMMTEN ZWECK.
11
+ AUF KEINEN FALL SIND DER AUTOR ODER DIE BEITRAGSLEISTENDEN FÜR IRGENDWELCHE DIREKTEN,
12
+ INDIREKTEN, ZUFÄLLIGEN, SPEZIELLEN, BEISPIELHAFTEN ODER FOLGESCHÄDEN (UNTER ANDEREM
13
+ VERSCHAFFEN VON ERSATZGÜTERN ODER -DIENSTLEISTUNGEN; EINSCHRÄNKUNG DER
14
+ NUTZUNGSFÄHIGKEIT; VERLUST VON NUTZUNGSFÄHIGKEIT, DATEN, ODER PROFIT; ODER
15
+ GESCHÄFTSUNTERBRECHUNG), WIE AUCH IMMER VERURSACHT UND UNTER WELCHER VERPFLICHTUNG
16
+ AUCH IMMER, OB IN VERTRAG, STRIKTER VERPFLICHTUNG ODER UNERLAUBTER HANDLUNG
17
+ (INKLUSIVE FAHRLÄSSIGKEIT) VERANTWORTLICH, AUF WELCHEM WEG SIE AUCH IMMER DURCH DIE
18
+ BENUTZUNG DIESER SOFTWARE ENTSTANDEN SIND, SOGAR, WENN SIE AUF DIE MÖGLICHKEIT EINES
19
+ SOLCHEN SCHADENS HINGEWIESEN WORDEN SIND.
@@ -0,0 +1,173 @@
1
+ Metadata-Version: 2.4
2
+ Name: dj-templates
3
+ Version: 0.0.1
4
+ Summary: Minimal django project
5
+ License-Expression: BSD-1-Clause
6
+ License-File: LICENSE
7
+ License-File: LICENSE.md
8
+ Author: Christian Moser
9
+ Author-email: devel@c-moser.at
10
+ Requires-Python: >=3.13,<3.15
11
+ Classifier: Programming Language :: Python :: 3
12
+ Classifier: Programming Language :: Python :: 3.13
13
+ Classifier: Programming Language :: Python :: 3.14
14
+ Requires-Dist: django (>=6.0.6,<7.0.0)
15
+ Requires-Dist: orjson (>=3.11.9,<4.0.0)
16
+ Description-Content-Type: text/markdown
17
+
18
+ # django-templates
19
+
20
+ *django-templates* is a Django app that provides a centralized registry for
21
+ accessing the dictionary of templates used in a request.
22
+ It also provides a context processor for accessing the registry.
23
+
24
+ ## Installation
25
+
26
+ Add *django_templates* to the list of *INSTALLED_APPS* in your project's settings.py.
27
+
28
+ ```python
29
+ INSTALLED_APPS = [
30
+ ...
31
+ django_templates,
32
+ ...
33
+ ]
34
+ ```
35
+
36
+ Add the *templates* context processor to your project's settings.py.
37
+
38
+ ```python
39
+ TEMPLATES = [
40
+ {
41
+ ...
42
+ "APP_DIRS": True,
43
+ # Optionally add the global templates directory if it is not in an app's templates directory.
44
+ "DIRS": [
45
+ "/path/to/global/templates",
46
+ ],
47
+ ...
48
+ # Add the templates context processor to the list of context processors.
49
+ "OPTIONS": {
50
+ "context_processors": [
51
+ ...
52
+ "django_templates.context_processors.templates",
53
+ ...
54
+ ],
55
+ },
56
+ },
57
+ ]
58
+ ...
59
+
60
+ ```
61
+
62
+ Then you can use the *DJANGO_TEMPLATES* setting in settings.py to override the
63
+ templates of apps using this library.
64
+
65
+
66
+ ```python
67
+ DJANGO_TEMPLATES = {
68
+ "html": {
69
+ "app_name/index": "app_name/templates/app_name/index.html",
70
+ ...
71
+ }
72
+ }
73
+ ```
74
+
75
+ You can also use a *filename* or `Path` object to load the templates from a YAML
76
+ or JSON file.
77
+
78
+ Set the global THEME variable to the default theme for your project.
79
+
80
+ The default theme is "html", but you can change it to any other theme provided
81
+ in the "django_templates/themes" directory.
82
+
83
+ Themes provided in the "django_templates/themes" directory are:
84
+
85
+ - html
86
+ - bootstrap5 (Work in progress)
87
+ - tailwindcss (Work in progress)
88
+
89
+ ```python
90
+ THEME = "html"
91
+ ```
92
+
93
+ Set the global GET_THEME_FUNCTION variable to the function that will be used to
94
+ get the theme for a request. This allows you to implement theming in your app by
95
+ providing a function that returns the theme for a request.
96
+
97
+ ```python
98
+ GET_THEME_FUNCTION = 'myapp.module.get_theme_for_request'
99
+ ```
100
+
101
+ ...
102
+ ## Usage
103
+
104
+ To use the template registry in your app, create the file
105
+ "your_app/django_templates.py" and define your templates there.
106
+
107
+ Set the `DJANGO_TEMPLATES` variable, which should contain your default template
108
+ dictionary or a *filename* or `Path` object.
109
+
110
+ If passing a filename it should be an absolute path to a YAML or JSON file
111
+ containing the template dictionary.
112
+
113
+ ```python
114
+ DJANGO_TEMPLATES = {
115
+ "html": {
116
+ "app_name/index": "app_name/templates/app_name/index.html"
117
+ }
118
+ ...
119
+ }
120
+ ```
121
+
122
+ ### Accessing the registry in your templates
123
+
124
+ You can access the registry in your templates by using the `template` filter
125
+ from the `django_templates` template tag library.
126
+ The templates filter requires the `request` object to be passed to it, which is
127
+ available in the template context if you have added the
128
+ `django_templates.context_processors.templates` context processor to your
129
+ project's settings.py or a theme name.
130
+
131
+ ```django
132
+ {% extends base_template %}
133
+ ...
134
+ {% load templates %}
135
+ {{ "template_name"|template:request }}
136
+ ...
137
+ ```
138
+
139
+ ### Accessing the registry un your views
140
+
141
+ ```python
142
+ from django.shortcuts import render
143
+ from django_templates.utils import get_template
144
+
145
+ def my_view(request):
146
+ template_name = get_template("template_key", request=request)
147
+ ...
148
+ render(request, template_name, context)
149
+ ```
150
+
151
+ #### Getting the theme for a request
152
+
153
+ ```python
154
+ from django_templates.utils import get_theme
155
+
156
+ current_theme = get_theme(request)
157
+ ```
158
+
159
+ ### Accessing the registry in your app
160
+
161
+ You can access the registry in your app by using the `get_template_name`
162
+ function from the `django_templates.utils` module.
163
+
164
+ An optional `theme` argument can be passed to the function to get the template
165
+ name for a specific theme. You can also pass a `request` object to the function
166
+ to get the template name for the current theme.
167
+
168
+ ```python
169
+ from django_templates.utils import get_template
170
+
171
+ template_name = get_template("template_key")
172
+ ```
173
+
@@ -0,0 +1,155 @@
1
+ # django-templates
2
+
3
+ *django-templates* is a Django app that provides a centralized registry for
4
+ accessing the dictionary of templates used in a request.
5
+ It also provides a context processor for accessing the registry.
6
+
7
+ ## Installation
8
+
9
+ Add *django_templates* to the list of *INSTALLED_APPS* in your project's settings.py.
10
+
11
+ ```python
12
+ INSTALLED_APPS = [
13
+ ...
14
+ django_templates,
15
+ ...
16
+ ]
17
+ ```
18
+
19
+ Add the *templates* context processor to your project's settings.py.
20
+
21
+ ```python
22
+ TEMPLATES = [
23
+ {
24
+ ...
25
+ "APP_DIRS": True,
26
+ # Optionally add the global templates directory if it is not in an app's templates directory.
27
+ "DIRS": [
28
+ "/path/to/global/templates",
29
+ ],
30
+ ...
31
+ # Add the templates context processor to the list of context processors.
32
+ "OPTIONS": {
33
+ "context_processors": [
34
+ ...
35
+ "django_templates.context_processors.templates",
36
+ ...
37
+ ],
38
+ },
39
+ },
40
+ ]
41
+ ...
42
+
43
+ ```
44
+
45
+ Then you can use the *DJANGO_TEMPLATES* setting in settings.py to override the
46
+ templates of apps using this library.
47
+
48
+
49
+ ```python
50
+ DJANGO_TEMPLATES = {
51
+ "html": {
52
+ "app_name/index": "app_name/templates/app_name/index.html",
53
+ ...
54
+ }
55
+ }
56
+ ```
57
+
58
+ You can also use a *filename* or `Path` object to load the templates from a YAML
59
+ or JSON file.
60
+
61
+ Set the global THEME variable to the default theme for your project.
62
+
63
+ The default theme is "html", but you can change it to any other theme provided
64
+ in the "django_templates/themes" directory.
65
+
66
+ Themes provided in the "django_templates/themes" directory are:
67
+
68
+ - html
69
+ - bootstrap5 (Work in progress)
70
+ - tailwindcss (Work in progress)
71
+
72
+ ```python
73
+ THEME = "html"
74
+ ```
75
+
76
+ Set the global GET_THEME_FUNCTION variable to the function that will be used to
77
+ get the theme for a request. This allows you to implement theming in your app by
78
+ providing a function that returns the theme for a request.
79
+
80
+ ```python
81
+ GET_THEME_FUNCTION = 'myapp.module.get_theme_for_request'
82
+ ```
83
+
84
+ ...
85
+ ## Usage
86
+
87
+ To use the template registry in your app, create the file
88
+ "your_app/django_templates.py" and define your templates there.
89
+
90
+ Set the `DJANGO_TEMPLATES` variable, which should contain your default template
91
+ dictionary or a *filename* or `Path` object.
92
+
93
+ If passing a filename it should be an absolute path to a YAML or JSON file
94
+ containing the template dictionary.
95
+
96
+ ```python
97
+ DJANGO_TEMPLATES = {
98
+ "html": {
99
+ "app_name/index": "app_name/templates/app_name/index.html"
100
+ }
101
+ ...
102
+ }
103
+ ```
104
+
105
+ ### Accessing the registry in your templates
106
+
107
+ You can access the registry in your templates by using the `template` filter
108
+ from the `django_templates` template tag library.
109
+ The templates filter requires the `request` object to be passed to it, which is
110
+ available in the template context if you have added the
111
+ `django_templates.context_processors.templates` context processor to your
112
+ project's settings.py or a theme name.
113
+
114
+ ```django
115
+ {% extends base_template %}
116
+ ...
117
+ {% load templates %}
118
+ {{ "template_name"|template:request }}
119
+ ...
120
+ ```
121
+
122
+ ### Accessing the registry un your views
123
+
124
+ ```python
125
+ from django.shortcuts import render
126
+ from django_templates.utils import get_template
127
+
128
+ def my_view(request):
129
+ template_name = get_template("template_key", request=request)
130
+ ...
131
+ render(request, template_name, context)
132
+ ```
133
+
134
+ #### Getting the theme for a request
135
+
136
+ ```python
137
+ from django_templates.utils import get_theme
138
+
139
+ current_theme = get_theme(request)
140
+ ```
141
+
142
+ ### Accessing the registry in your app
143
+
144
+ You can access the registry in your app by using the `get_template_name`
145
+ function from the `django_templates.utils` module.
146
+
147
+ An optional `theme` argument can be passed to the function to get the template
148
+ name for a specific theme. You can also pass a `request` object to the function
149
+ to get the template name for the current theme.
150
+
151
+ ```python
152
+ from django_templates.utils import get_template
153
+
154
+ template_name = get_template("template_key")
155
+ ```
@@ -0,0 +1,8 @@
1
+ from django_templates.utils.logging import get_logger
2
+ from django_templates.utils.theme import get_static_file, get_template, get_theme
3
+
4
+ __all__ = [
5
+ "get_template",
6
+ "get_theme",
7
+ "get_logger",
8
+ ]
@@ -0,0 +1,72 @@
1
+ from pathlib import Path
2
+
3
+ from django.apps import AppConfig
4
+ from django.utils.module_loading import import_string
5
+
6
+ from django_templates.utils.logging import get_templates_logger
7
+
8
+ logger = get_templates_logger(__name__)
9
+
10
+
11
+ class DjangoTemplatesConfig(AppConfig):
12
+ name = "django_templates"
13
+
14
+ def ready(self):
15
+ from django.conf import settings
16
+
17
+ from django_templates.theme import Theme, ThemeManager
18
+
19
+ manager = ThemeManager.get_global()
20
+
21
+ logger.info("Loading themes from installed apps and settings")
22
+ for app in settings.INSTALLED_APPS:
23
+ try:
24
+ themes = import_string(f"{app}.django_templates.THEMES")
25
+ if isinstance(themes, (str, Path)):
26
+ logger.debug(f"Loading themes for app {app} from file: {themes}.")
27
+ manager.update_themes_from_file(themes)
28
+ elif isinstance(themes, dict):
29
+ logger.debug(f"Loading themes for app {app} from dict.")
30
+ manager.update_themes_from_dict(themes)
31
+ except (ImportError, ModuleNotFoundError):
32
+ logger.debug(f"No themes found for app {app}. Skipping")
33
+
34
+ if hasattr(settings, "DJANGO_THEMES"):
35
+ logger.debug("Loading themes from DJANGO_THEMES setting")
36
+ if isinstance(settings.DJANGO_THEMES, (str, Path)):
37
+ logger.debug(f"Loading themes from file: {settings.DJANGO_THEMES}.")
38
+ manager.update_themes_from_file(settings.DJANGO_THEMES)
39
+ elif isinstance(settings.DJANGO_THEMES, dict):
40
+ logger.debug("Loading themes from dict.")
41
+ manager.update_themes_from_dict(settings.DJANGO_THEMES)
42
+
43
+ logger.info("Loading templates from installed apps and settings")
44
+ for app in settings.INSTALLED_APPS:
45
+ try:
46
+ templates = import_string(f"{app}.django_templates.TEMPLATES")
47
+ if isinstance(templates, (str, Path)):
48
+ logger.debug(
49
+ "Loading templates for app {app} from file: {templates}."
50
+ )
51
+ manager.update_from_file(templates)
52
+ elif isinstance(templates, dict):
53
+ logger.debug(f"Loading templates for app {app} from dict.")
54
+ manager.update_from_dict(templates)
55
+ except (ImportError, ModuleNotFoundError):
56
+ logger.debug(f"No templates found for app {app}. Skipping")
57
+
58
+ if hasattr(settings, "DJANGO_TEMPLATES"):
59
+ logger.debug("Loading templates from DJANGO_TEMPLATES setting")
60
+ if isinstance(settings.DJANGO_TEMPLATES, (str, Path)):
61
+ logger.debug(
62
+ f"Loading templates from file: {settings.DJANGO_TEMPLATES}."
63
+ )
64
+ tc.update_from_file(settings.DJANGO_TEMPLATES)
65
+ elif isinstance(settings.DJANGO_TEMPLATES, dict):
66
+ logger.debug("Loading templates from dict.")
67
+ tc.update_from_dict(settings.DJANGO_TEMPLATES)
68
+
69
+ logger.debug(
70
+ f"Available themes: {", ".join([f"\"{i}\"" for i in sorted(manager.keys()) if isinstance(manager[i], Theme)])}"
71
+ ) # noqa: E501
72
+ logger.info("Loaded themes and templates from installed apps and settings.")
@@ -0,0 +1,119 @@
1
+ default: html
2
+ plain: html
3
+ html:
4
+ display_name: "HTML"
5
+ extends: null
6
+ theme_dir: ./templates/themes/html
7
+ description: "A simple HTML theme with no CSS or JS dependencies."
8
+ version: "0.1.0"
9
+ templates:
10
+ theme/404: "themes/html/404.dj.html"
11
+ theme/base: "themes/html/base.dj.html"
12
+ theme/breadcrumbs: "themes/html/breadcrumbs.dj.html"
13
+ theme/extra_body: "themes/html/extra_body.dj.html"
14
+ theme/footer: "themes/html/footer.dj.html"
15
+ theme/head: "themes/html/head.dj.html"
16
+ theme/header: "themes/html/header.dj.html"
17
+ theme/nav: "themes/html/nav.dj.html"
18
+ theme/secondary_sidebar: "themes/html/secondary_sidebar.dj.html"
19
+ theme/sidebar: "themes/html/sidebar.dj.html"
20
+ static_files:
21
+ theme/css: assets/css/html.css
22
+ theme/logo: assets/img/django-templates-logo.svg
23
+ theme/logo-light: assets/img/django-templates-logo-light.svg
24
+ theme/logo-dark: assets/img/django-templates-logo-dark.svg
25
+ theme/favicon: assets/img/django-templates-favicon.ico
26
+ css_files:
27
+ - "@theme/css"
28
+ js-files:
29
+ - src: "https://cdn.jsdelivr.net/npm/htmx.org@2.0.10/dist/htmx.min.js"
30
+ integrity: "sha384-H5SrcfygHmAuTDZphMHqBJLc3FhssKjG7w/CeCpFReSfwBWDTKpkzPP8c+cLsK+V"
31
+ crossorigin: "anonymous"
32
+ bootstrap: bootstrap5
33
+ bootstrap5:
34
+ display_name: "Bootstrap 5"
35
+ extends: html
36
+ theme_dir: ./templates/themes/bootstrap5
37
+ description: "A theme based on Bootstrap 5 with responsive design and modern UI components."
38
+ version: "5.3.8"
39
+ templates:
40
+ theme/404: "themes/bootstrap5/404.dj.html"
41
+ theme/base: "themes/bootstrap5/base.dj.html"
42
+ theme/breadcrumbs: "themes/bootstrap5/breadcrumbs.dj.html"
43
+ theme/extra_body: "themes/bootstrap5/extra_body.dj.html"
44
+ theme/footer: "themes/bootstrap5/footer.dj.html"
45
+ theme/head: "themes/bootstrap5/head.dj.html"
46
+ theme/header: "themes/bootstrap5/header.dj.html"
47
+ theme/nav: "themes/bootstrap5/nav.dj.html"
48
+ theme/secondary_sidebar: "themes/bootstrap5/secondary_sidebar.dj.html"
49
+ theme/sidebar: "themes/bootstrap5/sidebar.dj.html"
50
+ static_files:
51
+ theme/css: assets/css/bootstrap5.min.css
52
+ css_files:
53
+ - "@theme/css"
54
+ js_files:
55
+ - src: "https://cdn.jsdelivr.net/npm/htmx.org@2.0.10/dist/htmx.min.js"
56
+ integrity: "sha384-H5SrcfygHmAuTDZphMHqBJLc3FhssKjG7w/CeCpFReSfwBWDTKpkzPP8c+cLsK+V"
57
+ crossorigin: "anonymous"
58
+ body_js_files:
59
+ - src: "https://cdn.jsdelivr.net/npm/@popperjs/core@2.11.8/dist/umd/popper.min.js"
60
+ integrity: "sha384-I7E8VVD/ismYTF4hNIPjVp/Zjvgyol6VFvRkX/vR+Vc4jQkC+hVqc2pM8ODewa9r"
61
+ crossorigin: "anonymous"
62
+ - src: "https://cdn.jsdelivr.net/npm/bootstrap@5.3.8/dist/js/bootstrap.min.js"
63
+ integrity: "sha384-G/EV+4j2dNv+tEPo3++6LCgdCROaejBqfUeNjuKAiuXbjrxilcCdDz6ZAVfHWe1Y"
64
+ crossorigin: "anonymous"
65
+ #tailwind: tailwindcss4
66
+ #tailwind4: tailwindcss4
67
+ #tailwindcss: tailwindcss4
68
+ #tailwindcss4:
69
+ # display_name: Tailwind CSS 4
70
+ # extends: html
71
+ # theme_dir: ./templates/themes/tailwindcss4
72
+ # description: "A theme based on Tailwind CSS 4 with utility-first styling and responsive design."
73
+ # version: "4.0.0"
74
+ # templates:
75
+ # theme/404: "themes/tailwindcss4/404.dj.html"
76
+ # theme/base: "themes/tailwindcss4/base.dj.html"
77
+ # theme/breadcrumbs: "themes/tailwindcss4/breadcrumbs.dj.html"
78
+ # theme/extra_body: "themes/tailwindcss4/extra_body.dj.html"
79
+ # theme/footer: "themes/tailwindcss4/footer.dj.html"
80
+ # theme/head: "themes/tailwindcss4/head.dj.html"
81
+ # theme/header: "themes/tailwindcss4/header.dj.html"
82
+ # theme/nav: "themes/tailwindcss4/nav.dj.html"
83
+ # theme/secondary_sidebar: "themes/tailwindcss4/secondary_sidebar.dj.html"
84
+ # theme/sidebar: "themes/tailwindcss4/sidebar.dj.html"
85
+ # js-files:
86
+ # - src: "https://cdn.jsdelivr.net/npm/htmx.org@2.0.10/dist/htmx.min.js"
87
+ # integrity: "sha384-H5SrcfygHmAuTDZphMHqBJLc3FhssKjG7w/CeCpFReSfwBWDTKpkzPP8c+cLsK+V"
88
+ # crossorigin: "anonymous"
89
+ bs5docs:
90
+ extends: bootstrap5
91
+ display_name: "Bootstrap 5 Docs"
92
+ theme_dir: ./templates/themes/bs5docs
93
+ templates:
94
+ theme/404: "themes/bs5docs/404.dj.html"
95
+ theme/base: "themes/bs5docs/base.dj.html"
96
+ theme/breadcrumbs: "themes/bs5docs/breadcrumbs.dj.html"
97
+ theme/extra_body: "themes/bs5docs/extra_body.dj.html"
98
+ theme/footer: "themes/bs5docs/footer.dj.html"
99
+ theme/head: "themes/bs5docs/head.dj.html"
100
+ theme/header: "themes/bs5docs/header.dj.html"
101
+ theme/nav: "themes/bs5docs/nav.dj.html"
102
+ theme/page-title: "themes/bs5docs/page_title.dj.html"
103
+ theme/secondary_sidebar: "themes/bs5docs/secondary_sidebar.dj.html"
104
+ theme/sidebar: "themes/bs5docs/sidebar.dj.html"
105
+ static_files:
106
+ theme/css: assets/css/bs5docs.min.css
107
+ css_files:
108
+ - "@theme/css"
109
+ js_files:
110
+ - src: "https://cdn.jsdelivr.net/npm/htmx.org@2.0.10/dist/htmx.min.js"
111
+ integrity: "sha384-H5SrcfygHmAuTDZphMHqBJLc3FhssKjG7w/CeCpFReSfwBWDTKpkzPP8c+cLsK+V"
112
+ crossorigin: "anonymous"
113
+ body_js_files:
114
+ - src: "https://cdn.jsdelivr.net/npm/@popperjs/core@2.11.8/dist/umd/popper.min.js"
115
+ integrity: "sha384-I7E8VVD/ismYTF4hNIPjVp/Zjvgyol6VFvRkX/vR+Vc4jQkC+hVqc2pM8ODewa9r"
116
+ crossorigin: "anonymous"
117
+ - src: "https://cdn.jsdelivr.net/npm/bootstrap@5.3.8/dist/js/bootstrap.min.js"
118
+ integrity: "sha384-G/EV+4j2dNv+tEPo3++6LCgdCROaejBqfUeNjuKAiuXbjrxilcCdDz6ZAVfHWe1Y"
119
+ crossorigin: "anonymous"
@@ -0,0 +1,60 @@
1
+ from django.http import HttpRequest
2
+
3
+ from django_templates import settings
4
+
5
+
6
+ def django_templates(request: HttpRequest):
7
+ """
8
+ Sets the context variables *BASE_TEMPLATE* and *CSS_FRAMEWORK*.
9
+
10
+ :param request: The HTTP request object.
11
+ :type request: HttpRequest
12
+ :return: A dictionary containing the base template and CSS framework settings.
13
+ :rtype: dict
14
+ """
15
+ from django_templates.theme.theme import Theme
16
+ from django_templates.utils.theme import get_template, get_theme
17
+
18
+ theme = getattr(request, "theme", get_theme(request))
19
+
20
+ if isinstance(theme, str):
21
+ theme = get_theme(theme)
22
+ elif not isinstance(theme, Theme):
23
+ raise TypeError(
24
+ f"Invalid theme type: {type(theme)}. Expected Theme or str."
25
+ )
26
+
27
+ base_template = settings.BASE_TEMPLATE
28
+
29
+ if base_template[0] in ("$", "@"):
30
+ base_template = get_template(base_template[1:], theme=theme)
31
+
32
+ favicon = None
33
+ favicon_type = None
34
+ if settings.FAVICON:
35
+ if settings.FAVICON[0] in ("$", "@"):
36
+ match settings.FAVICON[0]:
37
+ case "$":
38
+ favicon = settings.settings.MEDIA_URL + settings.FAVICON[1:]
39
+ case "@":
40
+ favicon = theme.get_static_file(settings.FAVICON[1:])
41
+ else:
42
+ favicon = settings.FAVICON
43
+
44
+ if favicon.endswith('.svg'):
45
+ favicon_type = 'image/svg+xml'
46
+ elif favicon.endswith('.png'):
47
+ favicon_type = 'image/png'
48
+ elif favicon.endswith('.ico'):
49
+ favicon_type = 'image/x-icon'
50
+ else:
51
+ favicon_type = 'image/x-icon' # Default type for unknown extensions
52
+
53
+ return {
54
+ "theme": theme,
55
+ "base_template": base_template,
56
+ "favicon": {
57
+ 'href': favicon,
58
+ 'type': favicon_type if favicon_type else 'image/x-icon'
59
+ } if favicon else None,
60
+ }
@@ -0,0 +1,19 @@
1
+ from pathlib import Path
2
+
3
+ THEMES = Path(__file__).resolve().parent / "builtin_themes.yml"
4
+ TEMPLATES = {
5
+ "html": {
6
+ "templates": {
7
+ "django-templates/test": "django_templates/test.dj.html",
8
+ },
9
+ "static_files": {
10
+ "django-templates/logo": "assets/img/django-templates-logo.svg",
11
+ "django-templates/logo-light": "assets/img/django-templates-logo-light.svg",
12
+ "django-templates/logo-dark": "assets/img/django-templates-logo-dark.svg",
13
+ "django-templates/img/logo.svg": "assets/img/django-templates-logo.svg",
14
+ "django-templates/img/logo.png": "assets/img/django-templates-logo.png",
15
+ "django-templates/img/logo-light.svg": "assets/img/django-templates-logo-light.svg",
16
+ "django-templates/img/logo-dark.svg": "assets/img/django-templates-logo-dark.svg",
17
+ }
18
+ },
19
+ }
@@ -0,0 +1,34 @@
1
+ # SOME DESCRIPTIVE TITLE.
2
+ # Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER
3
+ # This file is distributed under the same license as the PACKAGE package.
4
+ # FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
5
+ #
6
+ #, fuzzy
7
+ msgid ""
8
+ msgstr ""
9
+ "Project-Id-Version: django-templates 0.0.1\n"
10
+ "Report-Msgid-Bugs-To: \n"
11
+ "POT-Creation-Date: 2026-07-11 17:05+0000\n"
12
+ "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
13
+ "Last-Translator: Christian Moser <translate@c-moser.at>\n"
14
+ "Language-Team: German\n"
15
+ "Language: German \n"
16
+ "MIME-Version: 1.0\n"
17
+ "Content-Type: text/plain; charset=UTF-8\n"
18
+ "Content-Transfer-Encoding: 8bit\n"
19
+ "Plural-Forms: nplurals=2; plural=(n != 1);\n"
20
+ #: django_templates/templates/templates/html/base.dj.html:17
21
+ msgid "It Works"
22
+ msgstr "Es funktioniert"
23
+
24
+ #: django_templates/templates/templates/html/base.dj.html:18
25
+ #, python-format
26
+ msgid ""
27
+ "You are viewing <code>%(request_path)s</code> in <code>%(app_name)s</code> "
28
+ "app."
29
+ msgstr "Du siehst <code>%(request_path)s</code> in der <code>%(app_name)s</code> App."
30
+
31
+ #: django_templates/templates/templates/html/base.dj.html:19
32
+ msgid ""
33
+ "You should override this template in your app to display your own content."
34
+ msgstr "Du solltest diese Vorlage in deiner App überschreiben, um deinen eigenen Inhalt anzuzeigen."
File without changes