Wagtail Global Settings
Global settings editor for Wagtail using django-solo
wagtail-global-settings provides a global singleton model editing interface and frontend access for Wagtail. It uses django-solo for the model.
Installation
Install wagtail-global-settings.
Add wagtail_global_settings to INSTALLED_APPS in your settings.py. It should be after any apps that use the global_settings_tags template tags.
Usage
Global settings
To use the global settings of wagtail-global-settings you need to define a model, which inherits from AbstractGlobalSettingsCollection:
from django.db import models
from wagtail.wagtailadmin.edit_handlers import FieldPanel
from wagtail_global_settings.models import AbstractGlobalSettingsCollection
class GlobalSettings(AbstractGlobalSettingsCollection):
facebook_app_id = models.CharField(max_length=256)
google_app_id = models.CharField(max_length=256)
analytics_id = models.CharField(max_length=256)
panels = [
FieldPanel('facebook_app_id'),
FieldPanel('google_app_id'),
FieldPanel('analytics_id'),
]
class Meta:
verbose_name = "Global settings"
For the frontend you have three options:
use the context processor:
Add 'wagtail_global_settings.context_processors.global_settings' to your TEMPLATE_CONTEXT_PROCESSORS and then use the settings in your template: {{ global_settings.home.GlobalSettings.facebook_app_id }}
use the template tags:
Add {% load global_settings_tags %} at the beginning of your template and then use the tags in your template: {% global_settings 'home' 'GlobalSettings' 'facebook_app_id' %} or {% get_global_settings 'home' 'GlobalSettings' 'facebook_app_id' as facebook_app_id %} {{ facebook_app_id }}. It’s possible to skip the field name, in which case you’ll get the singleton model instance: {% get_global_settings 'home' 'GlobalSettings' as global_settings %} {{ global_settings.facebook_app_id }}
use the template tags provided by django-solo:
Add {% load solo_tags %} at the beginning of your template and then use the tag in your template: {% get_solo 'home.GlobalSettings' as global_settings %} {{ global_settings.facebook_app_id }}
Site specific settings
To use the site specific settings of wagtail-global-settings you need to define a model, which inherits from AbstractSiteSettingsCollection:
from django.db import models
from wagtail.wagtailadmin.edit_handlers import FieldPanel
from wagtail_global_settings.models import AbstractSiteSettingsCollection
class GlobalSettings(AbstractSiteSettingsCollection):
facebook_app_id = models.CharField(max_length=256)
google_app_id = models.CharField(max_length=256)
analytics_id = models.CharField(max_length=256)
panels = [
FieldPanel('facebook_app_id'),
FieldPanel('google_app_id'),
FieldPanel('analytics_id'),
]
class Meta:
verbose_name = "Global site settings"
The usage is the same as with AbstractGlobalSettingsCollection, except:
make sure 'wagtail.wagtailcore.middleware.SiteMiddleware' is in MIDDLEWARE_CLASSES
use 'wagtail_global_settings.context_processors.site_settings' instead of 'wagtail_global_settings.context_processors.global_settings' and put it after 'django.template.context_processors.request' in TEMPLATE_CONTEXT_PROCESSORS
use {% load site_settings_tags %} instead of {% load global_settings_tags %}
use {% site_settings %} instead of {% global_settings %} in the template
use {% get_site_settings %} instead of {% get_global_settings %} in the template
django-solo cannot be used with site specific settings
The template tags for site specific settings allow passing and optional site argument: {% site_settings 'home' 'GlobalSettings' 'facebook_app_id' the_site %}. If this argument is missing the settings for the current site will be returned.
Usage in views
For AbstractGlobalSettingsCollection:
from home.models import GlobalSettings
def view_func_global(request):
global_settings = GlobalSettings.get_solo()
return render(request, 'home/the_template.html', {
'facebook_app_id': global_settings.facebook_app_id,
})
For AbstractSiteSettingsCollection:
from home.models import GlobalSettings
def view_func_global(request):
site_settings = GlobalSettings.objects.for_site(request.site)
return render(request, 'home/the_template.html', {
'facebook_app_id': site_settings.facebook_app_id,
})
General
The template tags may be used in two ways: {% site_settings 'home' 'GlobalSettings' 'facebook_app_id' %} and {% site_settings 'home.GlobalSettings.facebook_app_id' %}.
For more information about configuration and caching see django-solo.
Metadata
Release files for wagtail-global-settings 0.1.4
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| wagtail-global-settings-0.1.4.tar.gz | 11.3 kB | Without provenance | Details for wagtail-global-settings-0.1.4.tar.gz |
Release files / wagtail-global-settings-0.1.4.tar.gz
| Download URL | wagtail-global-settings-0.1.4.tar.gz |
|---|---|
| Size | 11.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
df44092babc5f40c2046ce32b92976b442a74d8be3d1fbd9351c2282ecf00512
|
|
BLAKE2b-256 checksum How to use checksums |
9971d788b98664357cfbddb74cef9d7f0cc3c6948b344cb647c05872bc1cbc99
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
Security for wagtail-global-settings 0.1.4
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.