本文整理匯總了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)
)
)
示例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
示例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 {}
示例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
示例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
示例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
示例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)
示例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)
示例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))
示例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)
示例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
示例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
)
示例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
示例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
示例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