-
Notifications
You must be signed in to change notification settings - Fork 11
Allow your staff team to change configurations
↑ Parent: Advanced tutorials
← Previous: Roles and permissions
Most of the website can be configured via Website settings. But some configurations might change more often than developers want to deploy new versions to production.
For this reason, MagiCircles provides "Staff configurations" which are stored in the database and can be configured via the website itself.
ℹ️ Staff configurations are then cached and updated every 24 hours via generated settings.
-
Enable StaffConfiguration collection in
${PROJECT}/magicollections.py
:from magi.magicollections import StaffConfigurationCollection as _StaffConfigurationCollection class StaffConfigurationCollection(_StaffConfigurationCollection): enabled = True
-
The first time you enable staff configurations, on your local or in production, as well as whenever a new language gets added to the website, the database can be populated using:
python manage.py populate_staffconfigurations
-
Add the new configuration via the web interface, both on your local and in production.
-
The key is what's used within the code. It's recommended but not enforced to use lowercase snake case strings (
foo_bar
). -
The name is a verbose name for staff members. It can give details about where it's used.
-
Is long
,Is markdown
andIs boolean
are just a way to display the right form fields when staff will fill the value.
-
-
Use it in Python:
from django.conf import settings as django_settings
# Not per language:
print django_settings.STAFF_CONFIGURATIONS.get('max_level', 0)
# Per language:
print django_settings.STAFF_CONFIGURATIONS.get('team_introduction', {}).get(request.LANGUAGE_CODE, 'default')
- Use it in a template:
{# Not per language: #}
{% if staff_configurations.max_level %}
<span>{{ staff_configurations.max_level }}</span>
{% endif %}
{# Per language: #}
{% if staff_configurations.team_introduction and staff_configurations.team_introduction|getattribute:LANGUAGE_CODE %}
<p>{{ staff_configurations.team_introduction|getattribute:LANGUAGE_CODE }}</p>
{% endif %}
You can also create a script to add the staff configurations like so:
${PROJECT}/management/commands/populate_staffconfigurations_${PROJECT}.py
:
from django.core.management.base import BaseCommand, CommandError
from magi.utils import LANGUAGES_DICT
from magi.management.commands.populate_staffconfigurations import create
class Command(BaseCommand):
can_import_settings = True
def handle(self, *args, **options):
##################################
# Translatable
for language in LANGUAGES_DICT.keys():
create({
'key': 'card_skill_template',
'verbose_key': 'Template of card skills, must contain {percent} and {bonus}',
'is_markdown': True,
'is_long': True,
'i_language': language,
})
##################################
# Non translatable
create({
'key': 'max_song_length',
'verbose_key': 'Maximum length of a song, in seconds',
})
create({
'key': 'allow_emojis_card_tags',
'verbose_key': 'Are emojis allowed in cards tags?',
'is_boolean': True,
})
On your local or in production, when this script gets added, whenever it gets updated to add new configurations, as well as whenever a new language gets added to the website, you'll need to populate the database like so:
python manage.py populate_staffconfigurations_${PROJECT}
I. Introduction
II. Tutorials
III. References
- Files tree
- Default collections
- Default pages
- Website settings
- MagiCollection settings
- Abstract models
- Abstract collections
- MagiForm settings
- MagiFiltersForm settings
- Single pages settings
IV. Utils
-
MagiModel utils
- MagiModel images and files
- DateTime fields
- BaseAccount model
- Save choices values as integer rather than strings
- Store comma separated values
- Store dictionaries
- Store Markdown texts
- Translate fields values in multiple languages
- Store JSON
- More model field types
- Transform images before saving them
- Check choices at form level instead of model level
- Use an internal cache for foreign keys in models
- Customize views with MagiModel properties
- Events
- Form utils
- Python utils
- Templates utils
- Javascript utils
- Enable and disable existing collections and pages
- Translations
- Page titles and descriptions
- Characters
- Seasons
- Roles and permissions
- Allow your staff team to change configurations
- Custom users preferences and settings
- Background illustrations
- Activities tabs
- Corner popups
VI. More