Demo Pages: Settings via Django Database
SmartAdmin for Django Settings: Local and Server Storage
The inbuilt SmartAdmin theme capabilities as detailed in the documentation are all availble in Sadj, extended to allow some more control, along with the ability to save the theme options to the server database.
When accessed locally, the values are held in local storage under 'themeSettings', which is stringified Json containing 'themeOptions' (body element modifiers), and 'themeURL' (stylesheet location, essentially the colourscheme). The equivalent Json is held in the database when saved by a user with save permissions.
When accessed via the server, the values are held in the database, against the user's login ID.
The HTML side of this page is straightforward, being built around the following template instruction, which wraps the same HTML for settings control as displayed in the settings popup
{% include 'sadjcore/fragments/pagesettings_div.html' %}
While the wrapper template (in the html example) or the base frame (in the ajax example), as usual, contains the instruction:
{% include 'sadjcore/fragments/bodyscript.html' %}
and the body element contains:
class="{{ themeOptions|default:'mod-bg-1 mod-nav-link' }}"
Then as long as the sadjcore
Django app is active on the server and the sadjcore.js
script is loaded, settings will be stored and retrieved against the user's login ID.
In the HTML, the 'head' element contains a 'mytheme' link containing the choice of stylesheet, and a 'myskin' link pointing to skin-master.css, while the 'body' element contains the layout modifiers as classes.
The bodyscript
template picks up several parameters from the template context (note some are strings to represent booleans, to render directly into javascript):
theme_from_server
- 'true' or 'false' to switch betwen server and local operation; defaults to regular SmartAdmin local operation.append_styles
- 'true' or 'false' whether to append the list of body classes found in the settings to the classes already on the body element.css_only
- 'true' or 'false', set to true to change only the colour scheme, not the layout options (for example, on the standalone login page).css_prefix
- for use if the location of the stylesheet files is not '/static/smartadmin/css/themes'themeURL
andthemeOptions
should be supplied if the settings are server-based (picked up in the head and body, not the bodyscript code)