def load_site_config(): """Set up the SiteConfiguration, provide defaults and sync settings.""" try: siteconfig = SiteConfiguration.objects.get_current() except SiteConfiguration.DoesNotExist: # Either warn or just create the thing. Depends on your app. siteconfig = SiteConfiguration(site=Site.objects.get_current(), version="1.0") siteconfig.save() if not siteconfig.get_defaults(): siteconfig.add_defaults(generate_defaults(SETTINGS_MAP)) apply_django_settings(siteconfig, SETTINGS_MAP) return siteconfig
def load_site_config(): """Set up the SiteConfiguration, provide defaults and sync settings.""" try: siteconfig = SiteConfiguration.objects.get_current() except SiteConfiguration.DoesNotExist: # Either warn or just create the thing. Depends on your app. siteconfig = SiteConfiguration(site=Site.objects.get_current(), version="1.0") siteconfig.save() # If TITLE and DESCRIPTION are not on the database then pick the defaults # from the settings and save them in the database. if not siteconfig.get_defaults(): SETTINGS_MAP = { # siteconfig key settings.py key 'DESCRIPTION': 'DESCRIPTION', 'TITLE': 'TITLE', } siteconfig.add_defaults(generate_defaults(SETTINGS_MAP)) return siteconfig
def load_site_config(): """Set up the SiteConfiguration, provide defaults and sync settings.""" try: siteconfig = SiteConfiguration.objects.get_current() except SiteConfiguration.DoesNotExist: # Either warn or just create the thing. Depends on your app. siteconfig = SiteConfiguration(site=Site.objects.get_current(), version="1.0") siteconfig.save() # If TITLE and DESCRIPTION are not on the database then pick the defaults # from the settings and save them in the database. if not siteconfig.get_defaults(): SETTINGS_MAP = { # siteconfig key settings.py key 'DESCRIPTION': 'DESCRIPTION', 'TITLE': 'TITLE', } siteconfig.add_defaults(generate_defaults(SETTINGS_MAP)) return siteconfig
# NOTE: Import this file in your urls.py or some place before # any code relying on settings is imported. from django.contrib.sites.models import Site from djblets.siteconfig.models import SiteConfiguration from djblets.siteconfig.django_settings import apply_django_settings, generate_defaults settings_map = { # siteconfig key settings.py key 'DESCRIPTION': 'DESCRIPTION', 'TITLE': 'TITLE', } defaults = generate_defaults(settings_map) def load_site_config(): """Sets up the SiteConfiguration, provides defaults and syncs settings.""" try: siteconfig = SiteConfiguration.objects.get_current() except SiteConfiguration.DoesNotExist: # Either warn or just create the thing. Depends on your app siteconfig = SiteConfiguration(site=Site.objects.get_current(), version="1.0") siteconfig.save() if not siteconfig.get_defaults(): siteconfig.add_defaults(defaults) apply_django_settings(siteconfig, settings_map) return siteconfig
# NOTE: Import this file in your urls.py or some place before # any code relying on settings is imported. from django.contrib.sites.models import Site from djblets.siteconfig.models import SiteConfiguration from djblets.siteconfig.django_settings import apply_django_settings, generate_defaults settings_map = { # siteconfig key settings.py key 'DESCRIPTION': 'DESCRIPTION', 'TITLE': 'TITLE', } defaults = generate_defaults(settings_map) def load_site_config(): """Sets up the SiteConfiguration, provides defaults and syncs settings.""" try: siteconfig = SiteConfiguration.objects.get_current() except SiteConfiguration.DoesNotExist: # Either warn or just create the thing. Depends on your app siteconfig = SiteConfiguration(site=Site.objects.get_current(), version="1.0") siteconfig.save() if not siteconfig.get_defaults(): siteconfig.add_defaults(defaults) apply_django_settings(siteconfig, settings_map) return siteconfig