Пример #1
0
    def load(self):
        # First set some sane defaults.
        domain_method = self.siteconfig.get("site_domain_method")
        site = Site.objects.get_current()
        self.fields["server"].initial = "%s://%s" % (domain_method, site.domain)

        can_enable_search, reason = get_can_enable_search()
        if not can_enable_search:
            self.disabled_fields["search_enable"] = True
            self.disabled_fields["search_index_file"] = True
            self.disabled_reasons["search_enable"] = reason

        super(GeneralSettingsForm, self).load()
Пример #2
0
    def load(self):
        # First set some sane defaults.
        domain_method = self.siteconfig.get("site_domain_method")
        site = Site.objects.get_current()
        self.fields['server'].initial = "%s://%s" % (domain_method,
                                                     site.domain)

        can_enable_search, reason = get_can_enable_search()
        if not can_enable_search:
            self.disabled_fields['search_enable'] = True
            self.disabled_fields['search_index_file'] = True
            self.disabled_reasons['search_enable'] = reason

        super(GeneralSettingsForm, self).load()
Пример #3
0
    def load(self):
        domain_method = self.siteconfig.get("site_domain_method")
        site = Site.objects.get_current()

        can_enable_search, reason = get_can_enable_search()
        if not can_enable_search:
            self.disabled_fields['search_enable'] = True
            self.disabled_fields['search_index_file'] = True
            self.disabled_reasons['search_enable'] = reason

        super(GeneralSettingsForm, self).load()

        # This must come after we've loaded the general settings.
        self.fields['server'].initial = "%s://%s" % (domain_method,
                                                     site.domain)
Пример #4
0
    def load(self):
        domain_method = self.siteconfig.get("site_domain_method")
        site = Site.objects.get_current()

        can_enable_search, reason = get_can_enable_search()
        if not can_enable_search:
            self.disabled_fields['search_enable'] = True
            self.disabled_fields['search_index_file'] = True
            self.disabled_reasons['search_enable'] = reason

        super(GeneralSettingsForm, self).load()

        # This must come after we've loaded the general settings.
        self.fields['server'].initial = "%s://%s" % (domain_method,
                                                     site.domain)
Пример #5
0
    def load(self):
        # First set some sane defaults.
        domain_method = self.siteconfig.get("site_domain_method")
        site = Site.objects.get_current()
        self.fields['server'].initial = "%s://%s" % (domain_method,
                                                     site.domain)
        self.fields['auth_anonymous_access'].initial = \
            not self.siteconfig.get("auth_require_sitewide_login")

        self.fields['custom_backends'].initial = \
            ', '.join(self.siteconfig.get('auth_custom_backends'))

        can_enable_search, reason = get_can_enable_search()
        if not can_enable_search:
            self.disabled_fields['search_enable'] = True
            self.disabled_fields['search_index_file'] = True
            self.disabled_reasons['search_enable'] = reason

        can_enable_dns, reason = get_can_enable_dns()
        if not can_enable_dns:
            self.disabled_fields['auth_ad_find_dc_from_dns'] = reason

        can_enable_ldap, reason = get_can_enable_ldap()

        if not can_enable_ldap:
            self.disabled_fields['auth_ldap_uri'] = True
            self.disabled_fields['auth_ldap_email_domain'] = True
            self.disabled_fields['auth_ldap_email_attribute'] = True
            self.disabled_fields['auth_ldap_tls'] = True
            self.disabled_fields['auth_ldap_base_dn'] = True
            self.disabled_fields['auth_ldap_uid_mask'] = True
            self.disabled_fields['auth_ldap_anon_bind_uid'] = True
            self.disabled_fields['auth_ldap_anon_bind_password'] = True

            self.disabled_fields['auth_ad_use_tls'] = True
            self.disabled_fields['auth_ad_group_name'] = True
            self.disabled_fields['auth_ad_recursion_depth'] = True
            self.disabled_fields['auth_ad_ou_name'] = True
            self.disabled_fields['auth_ad_search_root'] = True
            self.disabled_fields['auth_ad_find_dc_from_dns'] = True
            self.disabled_fields['auth_ad_domain_controller'] = True
            self.disabled_fields['auth_ad_domain_name'] = _(reason)

            self.disabled_reasons['auth_ldap_uri'] = reason

        super(GeneralSettingsForm, self).load()
Пример #6
0
    def load(self):
        domain_method = self.siteconfig.get("site_domain_method")
        site = Site.objects.get_current()

        can_enable_search, reason = get_can_enable_search()
        if not can_enable_search:
            self.disabled_fields['search_enable'] = True
            self.disabled_fields['search_index_file'] = True
            self.disabled_reasons['search_enable'] = reason

        # Load the rest of the settings from the form.
        super(GeneralSettingsForm, self).load()

        # Load the cache settings.
        cache_backend = normalize_cache_backend(
            self.siteconfig.get('cache_backend'))

        cache_type = self.CACHE_TYPES_MAP.get(cache_backend['BACKEND'],
                                              'custom')
        self.fields['cache_type'].initial = cache_type

        if settings.DEBUG:
            self.fields['cache_type'].choices += (
                ('locmem', _('Local memory cache')),
            )

        if cache_type == 'custom':
            self.fields['cache_type'].choices += (
                ('custom', _('Custom')),
            )
            cache_locations = []
        elif cache_type != 'locmem':
            cache_locations = cache_backend['LOCATION']

            if not isinstance(cache_locations, list):
                cache_locations = [cache_locations]

            location_field = self.CACHE_LOCATION_FIELD_MAP[cache_type]
            self.fields[location_field].initial = ';'.join(cache_locations)

        # This must come after we've loaded the general settings.
        self.fields['server'].initial = "%s://%s" % (domain_method,
                                                     site.domain)
Пример #7
0
    def load(self):
        domain_method = self.siteconfig.get("site_domain_method")
        site = Site.objects.get_current()

        can_enable_search, reason = get_can_enable_search()
        if not can_enable_search:
            self.disabled_fields['search_enable'] = True
            self.disabled_fields['search_index_file'] = True
            self.disabled_reasons['search_enable'] = reason

        # Load the rest of the settings from the form.
        super(GeneralSettingsForm, self).load()

        # Load the cache settings.
        cache_backend = normalize_cache_backend(
            self.siteconfig.get('cache_backend'))

        cache_type = self.CACHE_TYPES_MAP.get(cache_backend['BACKEND'],
                                              'custom')
        self.fields['cache_type'].initial = cache_type

        if settings.DEBUG:
            self.fields['cache_type'].choices += (('locmem',
                                                   _('Local memory cache')), )

        if cache_type == 'custom':
            self.fields['cache_type'].choices += (('custom', _('Custom')), )
            cache_locations = []
        elif cache_type != 'locmem':
            cache_locations = cache_backend['LOCATION']

            if not isinstance(cache_locations, list):
                cache_locations = [cache_locations]

            location_field = self.CACHE_LOCATION_FIELD_MAP[cache_type]
            self.fields[location_field].initial = ';'.join(cache_locations)

        # This must come after we've loaded the general settings.
        self.fields['server'].initial = "%s://%s" % (domain_method,
                                                     site.domain)
Пример #8
0
def load_site_config():
    """
    Loads any stored site configuration settings and populates the Django
    settings object with any that need to be there.
    """
    def apply_setting(settings_key, db_key, default=None):
        db_value = siteconfig.settings.get(db_key)

        if db_value:
            setattr(settings, settings_key, db_value)
        elif default:
            setattr(settings, settings_key, default)


    try:
        siteconfig = SiteConfiguration.objects.get_current()
    except SiteConfiguration.DoesNotExist:
        raise ImproperlyConfigured, \
            "The site configuration entry does not exist in the database. " \
            "Re-run `./manage.py` syncdb to fix this."
    except:
        # We got something else. Likely, this doesn't exist yet and we're
        # doing a syncdb or something, so silently ignore.
        return


    # Populate defaults if they weren't already set.
    if not siteconfig.get_defaults():
        siteconfig.add_defaults(defaults)

    # The default value for DEFAULT_EMAIL_FROM (webmaster@localhost)
    # is less than good, so use a better one if it's set to that or if
    # we haven't yet set this value in siteconfig.
    mail_default_from = \
        siteconfig.settings.get('mail_default_from',
                                global_settings.DEFAULT_FROM_EMAIL)

    if (not mail_default_from or
        mail_default_from == global_settings.DEFAULT_FROM_EMAIL):
        domain = siteconfig.site.domain.split(':')[0]
        siteconfig.set('mail_default_from', 'noreply@' + domain)


    # Populate the settings object with anything relevant from the siteconfig.
    apply_django_settings(siteconfig, settings_map)


    # Now for some more complicated stuff...

    # Do some dependency checks and disable things if we don't support them.
    if not get_can_enable_search()[0]:
        siteconfig.set('search_enable', False)

    if not get_can_enable_syntax_highlighting()[0]:
        siteconfig.set('diffviewer_syntax_highlighting', False)


    # Site administrator settings
    apply_setting("ADMINS", None, (
        (siteconfig.get("site_admin_name", ""),
         siteconfig.get("site_admin_email", "")),
    ))

    apply_setting("MANAGERS", None, settings.ADMINS)

    # Explicitly base this off the MEDIA_URL
    apply_setting("ADMIN_MEDIA_PREFIX", None, settings.MEDIA_URL + "admin/")


    # Set the auth backends
    auth_backend_map = dict(get_registered_auth_backends())
    auth_backend_id = siteconfig.settings.get("auth_backend", "builtin")
    builtin_backend_obj = auth_backend_map['builtin']
    builtin_backend = "%s.%s" % (builtin_backend_obj.__module__,
                                 builtin_backend_obj.__name__)

    if auth_backend_id == "custom":
        custom_backends = siteconfig.settings.get("auth_custom_backends")

        if isinstance(custom_backends, basestring):
            custom_backends = (custom_backends,)
        elif isinstance(custom_backends, list):
            custom_backends = tuple(custom_backends)

        settings.AUTHENTICATION_BACKENDS = custom_backends

        if builtin_backend not in custom_backends:
            settings.AUTHENTICATION_BACKENDS += (builtin_backend,)
    elif auth_backend_id != "builtin" and auth_backend_id in auth_backend_map:
        backend = auth_backend_map[auth_backend_id]

        settings.AUTHENTICATION_BACKENDS = \
            ("%s.%s" % (backend.__module__, backend.__name__),
             builtin_backend)
    else:
        settings.AUTHENTICATION_BACKENDS = (builtin_backend,)

    # Set the storage backend
    storage_backend = siteconfig.settings.get('storage_backend', 'builtin')

    if storage_backend in storage_backend_map:
        settings.DEFAULT_FILE_STORAGE = storage_backend_map[storage_backend]
    else:
        settings.DEFAULT_FILE_STORAGE = storage_backend_map['builtin']

    # These blow up if they're not the perfectly right types
    settings.AWS_ACCESS_KEY_ID = str(siteconfig.get('aws_access_key_id'))
    settings.AWS_SECRET_ACCESS_KEY = str(siteconfig.get('aws_secret_access_key'))
    settings.AWS_STORAGE_BUCKET_NAME = str(siteconfig.get('aws_s3_bucket_name'))
    settings.AWS_CALLING_FORMAT = int(siteconfig.get('aws_calling_format'))
Пример #9
0
def load_site_config():
    """
    Loads any stored site configuration settings and populates the Django
    settings object with any that need to be there.
    """
    def apply_setting(settings_key, db_key, default=None):
        db_value = siteconfig.settings.get(db_key)

        if db_value:
            setattr(settings, settings_key, db_value)
        elif default:
            setattr(settings, settings_key, default)

    try:
        siteconfig = SiteConfiguration.objects.get_current()
    except SiteConfiguration.DoesNotExist:
        raise ImproperlyConfigured, \
            "The site configuration entry does not exist in the database. " \
            "Re-run `./manage.py` syncdb to fix this."
    except:
        # We got something else. Likely, this doesn't exist yet and we're
        # doing a syncdb or something, so silently ignore.
        return

    # Populate defaults if they weren't already set.
    if not siteconfig.get_defaults():
        siteconfig.add_defaults(defaults)

    # The default value for DEFAULT_EMAIL_FROM (webmaster@localhost)
    # is less than good, so use a better one if it's set to that or if
    # we haven't yet set this value in siteconfig.
    mail_default_from = \
        siteconfig.settings.get('mail_default_from',
                                global_settings.DEFAULT_FROM_EMAIL)

    if (not mail_default_from
            or mail_default_from == global_settings.DEFAULT_FROM_EMAIL):
        domain = siteconfig.site.domain.split(':')[0]
        siteconfig.set('mail_default_from', 'noreply@' + domain)

    # Populate the settings object with anything relevant from the siteconfig.
    apply_django_settings(siteconfig, settings_map)

    # Now for some more complicated stuff...

    # Do some dependency checks and disable things if we don't support them.
    if not get_can_enable_search()[0]:
        siteconfig.set('search_enable', False)

    if not get_can_enable_syntax_highlighting()[0]:
        siteconfig.set('diffviewer_syntax_highlighting', False)

    # Site administrator settings
    apply_setting("ADMINS", None, ((siteconfig.get(
        "site_admin_name", ""), siteconfig.get("site_admin_email", "")), ))

    apply_setting("MANAGERS", None, settings.ADMINS)

    # Explicitly base this off the MEDIA_URL
    apply_setting("ADMIN_MEDIA_PREFIX", None, settings.MEDIA_URL + "admin/")

    # Set the auth backends
    auth_backend_map = dict(get_registered_auth_backends())
    auth_backend_id = siteconfig.settings.get("auth_backend", "builtin")
    builtin_backend_obj = auth_backend_map['builtin']
    builtin_backend = "%s.%s" % (builtin_backend_obj.__module__,
                                 builtin_backend_obj.__name__)

    if auth_backend_id == "custom":
        custom_backends = siteconfig.settings.get("auth_custom_backends")

        if isinstance(custom_backends, basestring):
            custom_backends = (custom_backends, )
        elif isinstance(custom_backends, list):
            custom_backends = tuple(custom_backends)

        settings.AUTHENTICATION_BACKENDS = custom_backends

        if builtin_backend not in custom_backends:
            settings.AUTHENTICATION_BACKENDS += (builtin_backend, )
    elif auth_backend_id != "builtin" and auth_backend_id in auth_backend_map:
        backend = auth_backend_map[auth_backend_id]

        settings.AUTHENTICATION_BACKENDS = \
            ("%s.%s" % (backend.__module__, backend.__name__),
             builtin_backend)
    else:
        settings.AUTHENTICATION_BACKENDS = (builtin_backend, )

    # Set the storage backend
    storage_backend = siteconfig.settings.get('storage_backend', 'builtin')

    if storage_backend in storage_backend_map:
        settings.DEFAULT_FILE_STORAGE = storage_backend_map[storage_backend]
    else:
        settings.DEFAULT_FILE_STORAGE = storage_backend_map['builtin']

    # These blow up if they're not the perfectly right types
    settings.AWS_ACCESS_KEY_ID = str(siteconfig.get('aws_access_key_id'))
    settings.AWS_SECRET_ACCESS_KEY = str(
        siteconfig.get('aws_secret_access_key'))
    settings.AWS_STORAGE_BUCKET_NAME = str(
        siteconfig.get('aws_s3_bucket_name'))
    try:
        settings.AWS_CALLING_FORMAT = int(siteconfig.get('aws_calling_format'))
    except ValueError:
        settings.AWS_CALLING_FORMAT = 0
Пример #10
0
def load_site_config():
    """
    Loads any stored site configuration settings and populates the Django
    settings object with any that need to be there.
    """
    def apply_setting(settings_key, db_key, default=None):
        db_value = siteconfig.settings.get(db_key)

        if db_value:
            setattr(settings, settings_key, db_value)
        elif default:
            setattr(settings, settings_key, default)


    try:
        siteconfig = SiteConfiguration.objects.get_current()
    except SiteConfiguration.DoesNotExist:
        raise ImproperlyConfigured, \
            "The site configuration entry does not exist in the database. " \
            "Re-run `./manage.py` syncdb to fix this."
    except:
        # We got something else. Likely, this doesn't exist yet and we're
        # doing a syncdb or something, so silently ignore.
        return


    # Populate defaults if they weren't already set.
    if not siteconfig.get_defaults():
        siteconfig.add_defaults(defaults)


    # Populate the settings object with anything relevant from the siteconfig.
    apply_django_settings(siteconfig, settings_map)


    # Now for some more complicated stuff...

    # Do some dependency checks and disable things if we don't support them.
    if not get_can_enable_search()[0]:
        siteconfig.set('search_enable', False)

    if not get_can_enable_syntax_highlighting()[0]:
        siteconfig.set('diffviewer_syntax_highlighting', False)


    # Site administrator settings
    apply_setting("ADMINS", None, (
        (siteconfig.get("site_admin_name", ""),
         siteconfig.get("site_admin_email", "")),
    ))

    apply_setting("MANAGERS", None, settings.ADMINS)

    # Explicitly base this off the MEDIA_URL
    apply_setting("ADMIN_MEDIA_PREFIX", None, settings.MEDIA_URL + "admin/")


    # Set the auth backends
    auth_backend = siteconfig.settings.get("auth_backend", "builtin")
    builtin_backend = auth_backend_map['builtin']

    if auth_backend == "custom":
        custom_backends = siteconfig.settings.get("auth_custom_backends")

        if isinstance(custom_backends, basestring):
            custom_backends = (custom_backends,)
        elif isinstance(custom_backends, list):
            custom_backends = tuple(custom_backends)

        settings.AUTHENTICATION_BACKENDS = custom_backends

        if builtin_backend not in custom_backends:
            settings.AUTHENTICATION_BACKENDS += (builtin_backend,)
    elif auth_backend != "builtin" and auth_backend in auth_backend_map:
        settings.AUTHENTICATION_BACKENDS = \
            (auth_backend_map[auth_backend], builtin_backend)
    else:
        settings.AUTHENTICATION_BACKENDS = (builtin_backend,)
Пример #11
0
def load_site_config():
    """
    Loads any stored site configuration settings and populates the Django
    settings object with any that need to be there.
    """

    def apply_setting(settings_key, db_key, default=None):
        db_value = siteconfig.settings.get(db_key)

        if db_value:
            setattr(settings, settings_key, db_value)
        elif default:
            setattr(settings, settings_key, default)

    try:
        siteconfig = SiteConfiguration.objects.get_current()
    except SiteConfiguration.DoesNotExist:
        raise ImproperlyConfigured(
            "The site configuration entry does not exist in the database. " "Re-run `./manage.py` syncdb to fix this."
        )
    except:
        # We got something else. Likely, this doesn't exist yet and we're
        # doing a syncdb or something, so silently ignore.
        return

    # Populate defaults if they weren't already set.
    if not siteconfig.get_defaults():
        siteconfig.add_defaults(defaults)

    # The default value for DEFAULT_EMAIL_FROM (webmaster@localhost)
    # is less than good, so use a better one if it's set to that or if
    # we haven't yet set this value in siteconfig.
    mail_default_from = siteconfig.settings.get("mail_default_from", global_settings.DEFAULT_FROM_EMAIL)

    if not mail_default_from or mail_default_from == global_settings.DEFAULT_FROM_EMAIL:
        domain = siteconfig.site.domain.split(":")[0]
        siteconfig.set("mail_default_from", "noreply@" + domain)

    # STATIC_* and MEDIA_* must be different paths, and differ in meaning.
    # If site_static_* is empty or equal to media_static_*, we're probably
    # migrating from an earlier Review Board install.
    site_static_root = siteconfig.settings.get("site_static_root", "")
    site_media_root = siteconfig.settings.get("site_media_root")

    if site_static_root == "" or site_static_root == site_media_root:
        siteconfig.set("site_static_root", settings.STATIC_ROOT)

    site_static_url = siteconfig.settings.get("site_static_url", "")
    site_media_url = siteconfig.settings.get("site_media_url")

    if site_static_url == "" or site_static_url == site_media_url:
        siteconfig.set("site_static_url", settings.STATIC_URL)

    # Populate the settings object with anything relevant from the siteconfig.
    apply_django_settings(siteconfig, settings_map)

    # Now for some more complicated stuff...

    # Do some dependency checks and disable things if we don't support them.
    if not get_can_enable_search()[0]:
        siteconfig.set("search_enable", False)

    if not get_can_enable_syntax_highlighting()[0]:
        siteconfig.set("diffviewer_syntax_highlighting", False)

    # Site administrator settings
    apply_setting("ADMINS", None, ((siteconfig.get("site_admin_name", ""), siteconfig.get("site_admin_email", "")),))

    apply_setting("MANAGERS", None, settings.ADMINS)

    # Explicitly base this off the STATIC_URL
    apply_setting("ADMIN_MEDIA_PREFIX", None, settings.STATIC_URL + "admin/")

    # Set the auth backends
    auth_backend_map = dict(get_registered_auth_backends())
    auth_backend_id = siteconfig.settings.get("auth_backend", "builtin")
    builtin_backend_obj = auth_backend_map["builtin"]
    builtin_backend = "%s.%s" % (builtin_backend_obj.__module__, builtin_backend_obj.__name__)

    if auth_backend_id == "custom":
        custom_backends = siteconfig.settings.get("auth_custom_backends")

        if isinstance(custom_backends, six.string_types):
            custom_backends = (custom_backends,)
        elif isinstance(custom_backends, list):
            custom_backends = tuple(custom_backends)

        settings.AUTHENTICATION_BACKENDS = custom_backends

        if builtin_backend not in custom_backends:
            settings.AUTHENTICATION_BACKENDS += (builtin_backend,)
    elif auth_backend_id != "builtin" and auth_backend_id in auth_backend_map:
        backend = auth_backend_map[auth_backend_id]

        settings.AUTHENTICATION_BACKENDS = ("%s.%s" % (backend.__module__, backend.__name__), builtin_backend)
    else:
        settings.AUTHENTICATION_BACKENDS = (builtin_backend,)

    # Set the storage backend
    storage_backend = siteconfig.settings.get("storage_backend", "builtin")

    if storage_backend in storage_backend_map:
        settings.DEFAULT_FILE_STORAGE = storage_backend_map[storage_backend]
    else:
        settings.DEFAULT_FILE_STORAGE = storage_backend_map["builtin"]

    # These blow up if they're not the perfectly right types
    settings.AWS_QUERYSTRING_AUTH = siteconfig.get("aws_querystring_auth")
    settings.AWS_ACCESS_KEY_ID = six.text_type(siteconfig.get("aws_access_key_id"))
    settings.AWS_SECRET_ACCESS_KEY = six.text_type(siteconfig.get("aws_secret_access_key"))
    settings.AWS_STORAGE_BUCKET_NAME = six.text_type(siteconfig.get("aws_s3_bucket_name"))
    try:
        settings.AWS_CALLING_FORMAT = int(siteconfig.get("aws_calling_format"))
    except ValueError:
        settings.AWS_CALLING_FORMAT = 0