A plugin for Wagtail that adds developer-defined settings to the admin.
Installing
Install using pip:
pip install wagtailsettings
It is compatible with Wagtail 1.0 and upwards.
Add it to your INSTALLED_APPS:
INSTALLED_APPS += [
'wagtailsettings',
]
Using
Create a model that inherits from BaseSetting, and register it using the register_setting decorator:
from wagtailsettings 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 ‘Social media settings’ link will appear in the Wagtail admin ‘Settings’ menu.
You can change the label used in the menu by changing the verbose_name of your model.
You can add an icon to the menu by passing an ‘icon’ argument to the register_setting decorator:
@register_setting(icon='icon-placeholder')
class SocialMediaSettings(BaseSetting):
# ...
For a list of all available icons, please see the Wagtail style guide.
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 wagtailsettings context processors to your settings:
from django.conf import global_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 }}
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.2.tar.gz.
File metadata
- Download URL: wagtailsettings-0.3.2.tar.gz
- Upload date:
- Size: 8.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7fe8d9a1de9ca22573416514656878321f542db68d8de43ecc52885955f59b78
|
|
| MD5 |
8a3d2d472231ff88dde713ecfcc2455f
|
|
| BLAKE2b-256 |
31180c410fd8a46096c835eafe6d9b8e9f22acaa1946a6acd177bfb824ee2068
|