Use generated settings
↑ Parent: Python Utils
← Previous: Avoid generating translation terms for terms already available in Django framework
MagiCircles automatically generates some settings, including cache for some data, to avoid fetching them in database every time someone loads a page. If you followed the instructions to set up a project in your local or in production, you had to call generate_settings
at some point, or set up a cron to call it every 24 hours. This is what this command does.
By default, the following settings will be generated / data will be cached.
Saved/updated setting key | Description | Type |
---|---|---|
STAFF_CONFIGURATIONS |
Staff configurations get cached (see Allow your staff team to change configurations) | Dict |
LATEST_NEWS |
Banners saved in staff configurations get cached (see "Latest news" below) Banners to celebrate characters birthdays get cached (see Characters and "Latest news" below) |
Dict |
FAVORITE _CHARACTERS , OTHER _CHARACTERS_KEYS , FAVORITE _CHARACTERS _BIRTHDAYS , FAVORITE _CHARACTERS _BIRTHDAY_TODAY , FAVORITE _CHARACTERS _NAMES , {character_type} , {character_type} _BIRTHDAYS , {character_type} _BIRTHDAY_TODAY , {character_type}_NAMES
|
Favorite characters and other characters options get cached (see "Characters below) | Lists |
HOMEPAGE_ARTS |
See Background illustrations | List of dicts |
BACKGROUNDS |
See Background illustrations | List of dicts |
TOTAL_DONATORS |
Number of donators this month (See DonateCollection in Default collections) |
Int |
DONATION_MONTH |
Details of the current donation month (See DonateCollection in Default collections) |
Dict with date (datetime), donations (int), percent_int (int), percent (float), reached_100_percent (bool) |
SEASONAL_SETTINGS |
Details of the current season (see Seasons) | Dict of season name → dict |
GENERATED_DATE |
Date when the settings were generated last | datetime |
As well as these which are only meant to be used by MagiCircles internally:
Key | Description | Type |
---|---|---|
GENERATED_SHARE_IMAGES |
Collage images generated automatically from share images of items and used as share images for list views | Dict |
GENERATED_SHARE_IMAGES_LAST_DATE |
Last date share images were generated, to make sure they get re-generated every week | datetime |
PAST_ACTIVITY_TAGS_COUNT |
Number of activities posted under past tags, displayed when looking them up and used to hide past tags that were never used | Dict |
The rotating banners that show up on the homepage are called "latest news".
Some banners get added by default:
Description | How many banners? | Links to | Configurable |
---|---|---|---|
Banners from staff configurations (see Allow your staff team to change configurations + user doc) | 4 banners by default, but it's possible add as many banner settings as you want | Links setup in configuration | Using the staff configurations (see Allow your staff team to change configurations page (image, text, URL and wether the text shows up or not, if the image already has text) |
Birthdays of favorite characters and other characters | 1 banner per character | Item URL of character's collection |
|
Users who are celebrating their birthday today, sorted by popularity | All on 1 banner | Full list of users who are celebrating today | How many users show up max? Default: limited to 4 (by calling getUsersBirthdaysToday yourself, see Customize default generated settings
|
Seasonal limited hashtags | 1 per limited hashtag | Activities posted using this tag |
activity_tag_banner within season details, see Seasons
|
See Add more latest news below.
${PROJECT}/management/commands/generate_settings.py
:
from magi.tools import generateSettings
def generate_settings():
something = ...
...
generateSettings({
'SOMETHING': something,
...
})
It's that simple!
You can add anything you want in generated settings and access them wherever you want:
from django.conf import settings as django_settings
print django_settings.SOMETHING
It's also possible to customize default generated settings by providing them yourself. Functions are available in magi.tools
to call them yourself, see source code. Values you provide have priority, dicts and lists get merged.
One example is you can choose to display all donators instead of donators for this month only by calling totalDonators
(instead of totalDonatorsThisMonth
that gets called by default):
from magi.tools import totalDonators
def generate_settings():
total_donators = totalDonators()
...
generateSettings(
'TOTAL_DONATORS': total_donators,
...
)
Provide LATEST_NEWS
to the dict. It will later be sorted by priority
, so you can use that. Otherwise, your news will be displayed first.
Latest news is a list of dicts. Each dict contains the following keys:
Key | Description | Default | Example |
---|---|---|---|
title |
Name of the banner. It's required even when it's not displayed for SEO purpose | Required | Happy Birthday! |
t_titles |
Dict with names translated in various languages | Displays value of title
|
{'es': u'¡Feliz cumpleaños!' } |
hide_title |
Should the title be displayed or not? It's useful to display it if the banner doesn't contain any text | Text is displayed | True |
url |
URL to link to | Required | /cards/ |
ajax |
An Ajax URL to load in a modal | Only regular link | /ajax/cards/?ajax_modal_only |
image |
Banner image | No image, shows a background color or image | banner1.png |
background |
Background image. The difference with a regular image is that it can be cropped if needed, to keep the same aspect ratio as the other banners (displayed as cover in CSS) |
No background image | banner_background.png |
color |
Background color. Will not show up if a background image or image is set | Site's color, see Website settings | blue |
css_classes |
CSS classes to add to the banner, to allow to design certain banners a certain way with LESS | None | 'important_banner blue_banner' |
priority |
A number that allows you to sort banners. The first banner is the most viewed. You can use negative values | 1 | 2 |
→ Next: Templates utils
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