Package: wagtail-global-settings
Global settings editor for Wagtail using django-solowagtail-global-settingsprovides a global singleton model editing
interface and frontend access for Wagtail. It usesdjango-solofor the model.InstallationInstallwagtail-global-settings.Addwagtail_global_settingstoINSTALLED_APPSin yoursettings.py. It should be after any apps that use theglobal_settings_tagstemplate tags.UsageGlobal settingsTo use the global settings ofwagtail-global-settingsyou need to
define a model, which inherits fromAbstractGlobalSettingsCollection:fromdjango.dbimportmodelsfromwagtail.wagtailadmin.edit_handlersimportFieldPanelfromwagtail_global_settings.modelsimportAbstractGlobalSettingsCollectionclassGlobalSettings(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'),]classMeta:verbose_name="Global settings"For the frontend you have three options:use the context processor:Add'wagtail_global_settings.context_processors.global_settings'to
yourTEMPLATE_CONTEXT_PROCESSORSand 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 bydjango-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 settingsTo use the site specific settings ofwagtail-global-settingsyou
need to define a model, which inherits fromAbstractSiteSettingsCollection:fromdjango.dbimportmodelsfromwagtail.wagtailadmin.edit_handlersimportFieldPanelfromwagtail_global_settings.modelsimportAbstractSiteSettingsCollectionclassGlobalSettings(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'),]classMeta:verbose_name="Global site settings"The usage is the same as withAbstractGlobalSettingsCollection,
except:make sure'wagtail.wagtailcore.middleware.SiteMiddleware'is inMIDDLEWARE_CLASSESuse'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'inTEMPLATE_CONTEXT_PROCESSORSuse{% load site_settings_tags %}instead of{% load global_settings_tags %}use{% site_settings %}instead of{% global_settings %}in
the templateuse{% get_site_settings %}instead of{% get_global_settings %}in the templatedjango-solocannot be used with site specific settingsThe 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 viewsFor AbstractGlobalSettingsCollection:fromhome.modelsimportGlobalSettingsdefview_func_global(request):global_settings=GlobalSettings.get_solo()returnrender(request,'home/the_template.html',{'facebook_app_id':global_settings.facebook_app_id,})For AbstractSiteSettingsCollection:fromhome.modelsimportGlobalSettingsdefview_func_global(request):site_settings=GlobalSettings.objects.for_site(request.site)returnrender(request,'home/the_template.html',{'facebook_app_id':site_settings.facebook_app_id,})GeneralThe 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 seedjango-solo.