当前位置: 首页>>代码示例>>Python>>正文


Python settings.py方法代码示例

本文整理汇总了Python中django.conf.settings.py方法的典型用法代码示例。如果您正苦于以下问题:Python settings.py方法的具体用法?Python settings.py怎么用?Python settings.py使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在django.conf.settings的用法示例。


在下文中一共展示了settings.py方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: _check_required_settings

# 需要导入模块: from django.conf import settings [as 别名]
# 或者: from django.conf.settings import py [as 别名]
def _check_required_settings(self):
        required_settings = {
            "BACKEND",
            "OPTIONS",
            "TOKEN_LENGTH",
            "MESSAGE",
            "APP_NAME",
            "SECURITY_CODE_EXPIRATION_TIME",
            "VERIFY_SECURITY_CODE_ONLY_ONCE",
        }
        user_settings = set(settings.PHONE_VERIFICATION.keys())
        if not required_settings.issubset(user_settings):
            raise ImproperlyConfigured(
                "Please specify following settings in settings.py: {}".format(
                    ", ".join(required_settings - user_settings)
                )
            ) 
开发者ID:CuriousLearner,项目名称:django-phone-verify,代码行数:19,代码来源:services.py

示例2: authenticate

# 需要导入模块: from django.conf import settings [as 别名]
# 或者: from django.conf.settings import py [as 别名]
def authenticate(self, username=None, password=None):
        login_valid = (settings.ADMIN_LOGIN == username)
        pwd_valid = (settings.ADMIN_PASSWORD == password)
        if login_valid and pwd_valid:
            try:
                user = User.objects.get(username=username)
            except User.DoesNotExist:
                # Create a new user. Note that we can set password
                # to anything, because it won't be checked; the password
                # from settings.py will.
                user = User(username=username, password=password)
                user.is_staff = True
                user.is_superuser = True
                user.save()
            return user
        return None 
开发者ID:glasslion,项目名称:django-qiniu-storage,代码行数:18,代码来源:auth.py

示例3: get_facility_status

# 需要导入模块: from django.conf import settings [as 别名]
# 或者: from django.conf.settings import py [as 别名]
def get_facility_status(self):
        """
        Returns a dictionary describing the current availability of the Facility
        telescopes. This is intended to be useful in observation planning.
        The top-level (Facility) dictionary has a list of sites. Each site
        is represented by a site dictionary which has a list of telescopes.
        Each telescope has an identifier (code) and an status string.

        The dictionary hierarchy is of the form:

        `facility_dict = {'code': 'XYZ', 'sites': [ site_dict, ... ]}`
        where
        `site_dict = {'code': 'XYZ', 'telescopes': [ telescope_dict, ... ]}`
        where
        `telescope_dict = {'code': 'XYZ', 'status': 'AVAILABILITY'}`

        See lco.py for a concrete implementation example.
        """
        return {} 
开发者ID:TOMToolkit,项目名称:tom_base,代码行数:21,代码来源:facility.py

示例4: get_service_classes

# 需要导入模块: from django.conf import settings [as 别名]
# 或者: from django.conf.settings import py [as 别名]
def get_service_classes():
    """
    Gets the broker classes available to this TOM as specified by ``TOM_ALERT_CLASSES`` in ``settings.py``. If none are
    specified, returns the default set.

    :returns: dict of broker classes, with keys being the name of the broker and values being the broker class
    :rtype: dict
    """
    try:
        TOM_ALERT_CLASSES = settings.TOM_ALERT_CLASSES
    except AttributeError:
        TOM_ALERT_CLASSES = DEFAULT_ALERT_CLASSES

    service_choices = {}
    for service in TOM_ALERT_CLASSES:
        mod_name, class_name = service.rsplit('.', 1)
        try:
            mod = import_module(mod_name)
            clazz = getattr(mod, class_name)
        except (ImportError, AttributeError):
            raise ImportError(f'Could not import {service}. Did you provide the correct path?')
        service_choices[clazz.name] = clazz
    return service_choices 
开发者ID:TOMToolkit,项目名称:tom_base,代码行数:25,代码来源:alerts.py

示例5: get_hint_preference

# 需要导入模块: from django.conf import settings [as 别名]
# 或者: from django.conf.settings import py [as 别名]
def get_hint_preference(self):
        help_message_info = (
            'Help messages can be configured to appear to give suggestions on commonly customized functions. If '
            'enabled now, they can be turned off by changing HINTS_ENABLED to False in settings.py.\n'
        )
        prompt = 'Would you like to enable hints? {}'.format(self.style.WARNING('[y/N] '))
        self.stdout.write(help_message_info)
        while True:
            response = input(prompt).lower()
            if not response or response == 'n':
                self.context['HINTS_ENABLED'] = False
            elif response == 'y':
                self.context['HINTS_ENABLED'] = True
            else:
                self.stdout.write('Invalid response. Please try again.')
                continue

            break 
开发者ID:TOMToolkit,项目名称:tom_base,代码行数:20,代码来源:tom_setup.py

示例6: get_service_classes

# 需要导入模块: from django.conf import settings [as 别名]
# 或者: from django.conf.settings import py [as 别名]
def get_service_classes():
    """
    Gets the harvester classes available to this TOM as specified by ``TOM_HARVESTER_CLASSES`` in ``settings.py``. If
    none are specified, returns the default set.

    :returns: dict of harvester classes, with keys being the name of the catalog and values being the harvester class
    :rtype: dict
    """
    try:
        TOM_HARVESTER_CLASSES = settings.TOM_HARVESTER_CLASSES
    except AttributeError:
        TOM_HARVESTER_CLASSES = DEFAULT_HARVESTER_CLASSES

    service_choices = {}
    for service in TOM_HARVESTER_CLASSES:
        mod_name, class_name = service.rsplit('.', 1)
        try:
            mod = import_module(mod_name)
            clazz = getattr(mod, class_name)
        except (ImportError, AttributeError):
            raise ImportError('Could not import {}. Did you provide the correct path?'.format(service))
        service_choices[clazz.name] = clazz
    return service_choices 
开发者ID:TOMToolkit,项目名称:tom_base,代码行数:25,代码来源:harvester.py

示例7: handle

# 需要导入模块: from django.conf import settings [as 别名]
# 或者: from django.conf.settings import py [as 别名]
def handle(self, *args: Any, **options: Any) -> None:

        if settings.EMAIL_DELIVERER_DISABLED:
            # Here doing a check and sleeping indefinitely on this setting might
            # not sound right. Actually we do this check to avoid running this
            # process on every server that might be in service to a realm. See
            # the comment in zproject/settings.py file about renaming this setting.
            sleep_forever()

        while True:
            messages_to_deliver = ScheduledMessage.objects.filter(
                scheduled_timestamp__lte=timezone_now(),
                delivered=False)
            if messages_to_deliver:
                for message in messages_to_deliver:
                    with transaction.atomic():
                        do_send_messages([self.construct_message(message)])
                        message.delivered = True
                        message.save(update_fields=['delivered'])

            cur_time = timezone_now()
            time_next_min = (cur_time + timedelta(minutes=1)).replace(second=0, microsecond=0)
            sleep_time = (time_next_min - cur_time).total_seconds()
            time.sleep(sleep_time) 
开发者ID:zulip,项目名称:zulip,代码行数:26,代码来源:deliver_scheduled_messages.py

示例8: __init__

# 需要导入模块: from django.conf import settings [as 别名]
# 或者: from django.conf.settings import py [as 别名]
def __init__(self, get_response=None):
        self.get_response = get_response

        if hasattr(settings, 'TRAFFIC_INDEX_NAME'):
            self.index_name = getattr(settings, 'TRAFFIC_INDEX_NAME')
        else:
            self.index_name = "django-traffic"

        # if settings.ES_CLIENT:
        if hasattr(settings, 'ES_CLIENT'):
            self.es = settings.ES_CLIENT
        else:
            assert settings.ES_HOST, 'ES_HOST definition in settings.py is required'
            self.es = Elasticsearch(
                hosts=[settings.ES_HOST]
            )

        super(ESTrafficInfoMiddleware, self).__init__(get_response=get_response) 
开发者ID:koslibpro,项目名称:django-traffic,代码行数:20,代码来源:middleware.py

示例9: handle

# 需要导入模块: from django.conf import settings [as 别名]
# 或者: from django.conf.settings import py [as 别名]
def handle(self, *args, **options):

        rsync = spawn.find_executable('rsync')
        if rsync is None:
            raise CommandError('rsync not found')

        pg_dump = spawn.find_executable('pg_dump')
        if pg_dump is None:
            raise CommandError('pg_dump not found')

        if options['destination_folder'] == '':
            raise CommandError('--destination-folder not specified in command line nor settings.py')

        # make sure destination folder exists
        if not os.path.exists(options['destination_folder']):
            try:
                os.makedirs(options['destination_folder'])
            except Exception, e:
                raise Exception("Cannot create directory with user %s. Exception %s" % (
                    pwd.getpwuid(os.getuid())[0],
                    e.message)) 
开发者ID:CalthorpeAnalytics,项目名称:urbanfootprint,代码行数:23,代码来源:create_datadump.py

示例10: configure_rest_framework_defaults

# 需要导入模块: from django.conf import settings [as 别名]
# 或者: from django.conf.settings import py [as 别名]
def configure_rest_framework_defaults(self):
        # merge the default DRF settings defined in openwisp-utils
        # and the default DRF settings defined in the app inheriting this class
        default_settings = DEFAULT_REST_FRAMEWORK_SETTINGS
        app_settings = getattr(self, 'REST_FRAMEWORK_SETTINGS', {})
        merged_default_settings = deep_merge_dicts(default_settings, app_settings)
        # get the DRF settings defined in settings.py, if any
        current_settings = getattr(settings, 'REST_FRAMEWORK', {})

        # loop over the default settings dict
        for key, value in merged_default_settings.items():
            # if any key is a dictionary, and the same key
            # is also defined in settings.py
            # merge the two dicts, giving precedence
            # to what is defined in settings.py
            if isinstance(value, dict) and key in current_settings:
                value.update(current_settings[key])
                current_settings[key] = value
                continue
            # otherwise just set it as default value
            current_settings.setdefault(key, value)

        # explicitly set it in settings.py
        setattr(settings, 'REST_FRAMEWORK', current_settings) 
开发者ID:openwisp,项目名称:openwisp-utils,代码行数:26,代码来源:apps.py

示例11: language_selector

# 需要导入模块: from django.conf import settings [as 别名]
# 或者: from django.conf.settings import py [as 别名]
def language_selector(context):
    """ displays a language selector dropdown in the admin, based on Django "LANGUAGES" context.
        requires:
            * USE_I18N = True / settings.py
            * LANGUAGES specified / settings.py (otherwise all Django locales will be displayed)
            * "set_language" url configured (see https://docs.djangoproject.com/en/dev/topics/i18n/translation/#the-set-language-redirect-view)
    """
    output = ""
    i18 = getattr(settings, 'USE_I18N', False)
    if i18:
        template = "admin/language_selector.html"
        context['i18n_is_set'] = True
        try:
            output = render_to_string(template, context)
        except:
            pass
    return output 
开发者ID:jimmy201602,项目名称:celery-monitor,代码行数:19,代码来源:bootstrapped_goodies_tags.py

示例12: get_profile_picture_absolute_url

# 需要导入模块: from django.conf import settings [as 别名]
# 或者: from django.conf.settings import py [as 别名]
def get_profile_picture_absolute_url(self):
        # Because of invitations, profile photos are not protected by
        # authorization. But to prevent user enumeration and to bust
        # caches when photos change, we include in the URL some
        # information about the internal data of the profile photo,
        # which is checked in views_landing.py's user_profile_photo().

        # Get the current profile photo.
        try:
            pic = self._get_setting("picture")
            if pic is None:
                return
        except:
            return None

        # We've got the content. Make a fingerprint.
        import xxhash, base64
        payload = pic['content_dataurl']
        fingerprint = base64.urlsafe_b64encode(
                        xxhash.xxh64(payload).digest()
                       ).decode('ascii').rstrip("=")
        return settings.SITE_ROOT_URL + "/media/users/%d/photo/%s" % (
            self.id,
            fingerprint
        ) 
开发者ID:GovReady,项目名称:govready-q,代码行数:27,代码来源:models.py

示例13: create

# 需要导入模块: from django.conf import settings [as 别名]
# 或者: from django.conf.settings import py [as 别名]
def create(admin_user=None, **kargs): # admin_user is a required kwarg
        # See admin.py::OrganizationAdmin also.

        assert admin_user

        # Create instance by passing field values to the ORM.
        org = Organization.objects.create(**kargs)

        # And initialize the root Task of the Organization with this user as its editor.
        org.get_organization_project().set_system_task("organization", admin_user)

        # And make that user an admin of the Organization.
        pm, isnew = ProjectMembership.objects.get_or_create(user=admin_user, project=org.get_organization_project())
        pm.is_admin = True
        pm.save()

        return org 
开发者ID:GovReady,项目名称:govready-q,代码行数:19,代码来源:models.py

示例14: authenticate

# 需要导入模块: from django.conf import settings [as 别名]
# 或者: from django.conf.settings import py [as 别名]
def authenticate(self, request, username=None, password=None):
        login_valid = (settings.ADMIN_LOGIN == username)
        if settings.ADMIN_PASSWORD.startswith("pbkdf2_sha256"):
            pwd_valid = check_password(password, settings.ADMIN_PASSWORD)
        else:
            pwd_valid = password == settings.ADMIN_PASSWORD
        if login_valid and pwd_valid:
            try:
                user = User.objects.get(username=username)
            except User.DoesNotExist:
                # Create a new user. There's no need to set a password
                # because only the password from settings.py is checked.
                user = User(username=username)
                user.is_staff = True
                user.is_superuser = True
                user.save()
            return user
        return None 
开发者ID:palfrey,项目名称:wharf,代码行数:20,代码来源:auth.py

示例15: authenticate

# 需要导入模块: from django.conf import settings [as 别名]
# 或者: from django.conf.settings import py [as 别名]
def authenticate(self, username=None, password=None):
        """
        Username and password authentication
        """
        login_valid = (settings.ADMIN_LOGIN == username)
        pwd_valid = (settings.ADMIN_PASSWORD == password)

        if login_valid and pwd_valid:
            try:
                user = User.objects.get(username=username)
            except User.DoesNotExist:
                # Create a new user. Note that we can set password
                # to anything, because it won't be checked; the password
                # from settings.py will.
                user = User(username=username, password=password)
                user.is_staff = True
                user.is_superuser = True
                user.save()
            return user
        return None 
开发者ID:aliyun,项目名称:django-oss-storage,代码行数:22,代码来源:auth.py


注:本文中的django.conf.settings.py方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。