Admin-editable settings for Wagtail projects
Project description
A plugin for Wagtail that provides add developer-defined settings to the admin.
Installing
Install using pip:
pip install wagtailsettings
It works with Wagtail 0.5 and upwards.
Add it to your INSTALLED_APPS:
INSTALLED_APPS += [
'wagtailnews',
]
Using
Create a model that inherits from BaseSetting, and register it using the register_setting decorator:
from wagtailnews.models import BaseSetting, register_setting
@register_setting
class SocialMediaSettings(BaseSetting):
facebook = models.URLField(
help_text='Your Facebook page URL')
instagram = models.CharField(
max_length=255, help_text='Your Instagram username, without the @')
trip_advisor = models.URLField(
help_text='Your Trip Advisor page URL')
youtube = models.URLField(
help_text='Your YouTube channel or user account URL')
A ‘Settings’ link will appear in the Wagtail admin, with links to each of the settings models defined.
Using in Python
If access to a setting is required in the code, the BaseSetting.for_site method will retrieve the setting for the supplied site:
def view(request):
social_media_settings = SocialMediaSettings.for_site(request.site)
...
Using in Templates
Add the request and wagtailnews context processors to your settings:
TEMPLATE_CONTEXT_PROCESSORS = global_settings.TEMPLATE_CONTEXT_PROCESSORS + (
'django.core.context_processors.request',
'wagtailsettings.context_processors.settings',
)
Then access the settings through settings:
{{ settings.app_label.SocialMediaSettings.instagram }}
If you are not in a RequestContext, then context processors will not have run, and the settings variable will not be availble. To get the settings, use the provided template tags:
{% load wagtailsettings_tags %}
{% get_settings %}
{{ settings.app_label.SocialMediaSettings.instagram }}
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
File details
Details for the file wagtailsettings-0.3.0.tar.gz
.
File metadata
- Download URL: wagtailsettings-0.3.0.tar.gz
- Upload date:
- Size: 6.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9dedd81bd1b17e4db5b3f674b362896157cf0a894c47c8a9878c0ac39ab1173b |
|
MD5 | 822c5e447f77a2f0a314b6ea55a20072 |
|
BLAKE2b-256 | e44950f14866e07ff280dec4ea7b49d28614c34ae97c77d20cfa4d12d8c35640 |