Source code for config.apps

"""App configuration."""

from django.apps import AppConfig
from django.db import connection

#: Variables used to generate ``static/styles/_variables.scss``.
SCSS_VARS = """\
$main-bg: %(MAIN_BG_COLOR)s;
$alter-bg: %(ALTER_BG_COLOR)s;
$main-fg: %(MAIN_TEXT_COLOR)s;
$alter-fg: %(ALTER_TEXT_COLOR)s;
$shadow-color: %(SHADOW_COLOR)s;
$font-family: %(FONT_NAME)s;

[docs]class SiteConfig(AppConfig): """Configuration for the config app.""" name = 'config' verbose_name = 'Configuration' verbose_name_plural = 'Configuration'
[docs] def ready(self): """Configure the site when the app is ready.""" super(SiteConfig, self).ready() if 'django_site' in connection.introspection.table_names(): self._configure()
def _configure(self): from django.conf import settings from django.contrib.sites.models import Site site = Site.objects.get_or_create(pk=settings.SITE_ID)[0] site.domain = settings.CONFIG['DOMAIN'] = settings.CONFIG['NAME'] self._compile_scss(settings) def _compile_scss(self, settings): from sass import compile as sassc src = settings.STATIC_ROOT / 'styles' dst = settings.STATIC_ROOT / 'COMPILED' / 'styles' with open(src / '_variables.scss', 'w') as f: f.write(SCSS_VARS % settings.CONFIG) sassc(dirname=(src, dst), output_style='compressed') src = settings.STATIC_ROOT / 'extra' dst = settings.STATIC_ROOT / 'COMPILED' / 'extra' sassc(dirname=(src, dst), output_style='compressed')
__all__ = ['SCSS_VARS', 'SiteConfig']