本文整理汇总了Python中django.conf.settings.ENVIRONMENT属性的典型用法代码示例。如果您正苦于以下问题:Python settings.ENVIRONMENT属性的具体用法?Python settings.ENVIRONMENT怎么用?Python settings.ENVIRONMENT使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类django.conf.settings
的用法示例。
在下文中一共展示了settings.ENVIRONMENT属性的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: send_email
# 需要导入模块: from django.conf import settings [as 别名]
# 或者: from django.conf.settings import ENVIRONMENT [as 别名]
def send_email(self, user, place):
config = SiteConfiguration.get_solo()
email_template_subject = get_template('email/new_authorization_subject.txt')
email_template_text = get_template('email/new_authorization.txt')
email_template_html = get_template('email/new_authorization.html')
# TODO : Unsubscribe link in the email
email_context = {
'site_name': config.site_name,
'ENV': settings.ENVIRONMENT,
'subject_prefix': settings.EMAIL_SUBJECT_PREFIX_FULL,
'user': user,
'place': place,
}
# TODO : send mail only if the user chose to receive this type
send_mail(
''.join(email_template_subject.render(email_context).splitlines()),
email_template_text.render(email_context),
settings.DEFAULT_FROM_EMAIL,
recipient_list=[user.email],
html_message=email_template_html.render(email_context),
fail_silently=False,
)
示例2: send_mail
# 需要导入模块: from django.conf import settings [as 别名]
# 或者: from django.conf.settings import ENVIRONMENT [as 别名]
def send_mail(self,
subject_template_name, email_template_name, context, *args,
html_email_template_name=None, **kwargs):
user_is_active = context['user'].is_active
html_email_template_name = html_email_template_name[user_is_active]
email_template_name = email_template_name[user_is_active]
if not user_is_active:
case_id = str(uuid4()).upper()
auth_log.warning(
(self.admin_inactive_user_notification + ", but the account is deactivated [{cid}].")
.format(u=context['user'], cid=case_id)
)
context['restore_request_id'] = case_id
args = [subject_template_name, email_template_name, context, *args]
kwargs.update(html_email_template_name=html_email_template_name)
context.update({'ENV': settings.ENVIRONMENT, 'subject_prefix': settings.EMAIL_SUBJECT_PREFIX_FULL})
super().send_mail(*args, **kwargs)
示例3: terms_of_service
# 需要导入模块: from django.conf import settings [as 别名]
# 或者: from django.conf.settings import ENVIRONMENT [as 别名]
def terms_of_service(request):
"""
Handles the terms of service page
"""
return render(
request,
"terms_of_service.html",
context={
"has_zendesk_widget": True,
"is_public": True,
"js_settings_json": json.dumps({
"release_version": settings.VERSION,
"environment": settings.ENVIRONMENT,
"sentry_dsn": settings.SENTRY_DSN,
"user": serialize_maybe_user(request.user),
}),
"ga_tracking_id": "",
}
)
示例4: get_context
# 需要导入模块: from django.conf import settings [as 别名]
# 或者: from django.conf.settings import ENVIRONMENT [as 别名]
def get_context(self, request, *args, **kwargs):
js_settings = {
"gaTrackingID": settings.GA_TRACKING_ID,
"host": webpack_dev_server_host(request),
"environment": settings.ENVIRONMENT,
"sentry_dsn": settings.SENTRY_DSN,
"release_version": settings.VERSION
}
username = get_social_username(request.user)
context = super().get_context(request)
context["is_public"] = True
context["has_zendesk_widget"] = True
context["google_maps_api"] = False
context["authenticated"] = not request.user.is_anonymous
context["is_staff"] = has_role(request.user, [Staff.ROLE_ID, Instructor.ROLE_ID])
context["username"] = username
context["js_settings_json"] = json.dumps(js_settings)
context["title"] = self.title
context["ga_tracking_id"] = ""
return context
示例5: post
# 需要导入模块: from django.conf import settings [as 别名]
# 或者: from django.conf.settings import ENVIRONMENT [as 别名]
def post(self, request, *args, **kwargs):
config = SiteConfiguration.get_solo()
email_to_verify = value_without_invalid_marker(request.user.email)
url, token = create_unique_url({
'action': 'email_update',
'v': True,
'pk': request.user.pk,
'email': email_to_verify,
})
context = {
'site_name': config.site_name,
'ENV': settings.ENVIRONMENT,
'subject_prefix': settings.EMAIL_SUBJECT_PREFIX_FULL,
'url': url,
'url_first': url[:url.rindex('/')+1],
'url_second': token,
'user': request.user,
}
email_template_subject = get_template('email/system-email_verify_subject.txt')
email_template_text = get_template('email/system-email_verify.txt')
email_template_html = get_template('email/system-email_verify.html')
send_mail(
''.join(email_template_subject.render(context).splitlines()), # no newlines allowed in subject.
email_template_text.render(context),
settings.DEFAULT_FROM_EMAIL,
recipient_list=[email_to_verify],
html_message=email_template_html.render(context),
fail_silently=False)
if request.is_ajax():
return JsonResponse({'success': 'verification-requested'})
else:
return TemplateResponse(request, self.template_name)
示例6: save
# 需要导入模块: from django.conf import settings [as 别名]
# 或者: from django.conf.settings import ENVIRONMENT [as 别名]
def save(self):
"""
Saves nothing but sends a warning email to old email address,
and sends a confirmation link to the new email address.
"""
config = SiteConfiguration.get_solo()
old_email = self.previous_email
new_email = self.cleaned_data['email']
if old_email == new_email:
return self.instance
url, token = create_unique_url({
'action': 'email_update',
'v': False,
'pk': self.instance.pk,
'email': new_email,
})
context = {
'site_name': config.site_name,
'ENV': settings.ENVIRONMENT,
'subject_prefix': settings.EMAIL_SUBJECT_PREFIX_FULL,
'url': url,
'url_first': url[:url.rindex('/')+1],
'url_second': token,
'user': self.instance,
'email': new_email,
}
for old_new in ['old', 'new']:
email_template_subject = get_template('email/{type}_email_subject.txt'.format(type=old_new))
email_template_text = get_template('email/{type}_email_update.txt'.format(type=old_new))
email_template_html = get_template('email/{type}_email_update.html'.format(type=old_new))
send_mail(
''.join(email_template_subject.render(context).splitlines()), # no newlines allowed in subject.
email_template_text.render(context),
settings.DEFAULT_FROM_EMAIL,
recipient_list=[{'old': old_email, 'new': new_email}[old_new]],
html_message=email_template_html.render(context),
fail_silently=False)
return self.instance
示例7: check_services_running
# 需要导入模块: from django.conf import settings [as 别名]
# 或者: from django.conf.settings import ENVIRONMENT [as 别名]
def check_services_running():
if settings.ENVIRONMENT != PRODUCTION:
return
post_data = {
"prompt": "We know that this is an important moment in the history of our country he said. We are proud to support the work of the American Civil Liberties Union and we will continue to fight for the rights of all Americans. The ACLU is currently suing the government over its surveillance programs. The ACLU said it had been monitoring the surveillance program since September 2011.",
"temperature": 1,
"api_key": settings.ML_SERVICE_ENDPOINT_API_KEY,
"length": 20,
"top_k": 30,
}
endpoints = [
settings.GPT2_MEDIUM_API_ENDPOINT,
# settings.GPT2_LARGE_API_ENDPOINT,
settings.GPT2_MEDIUM_HP_API_ENDPOINT,
# settings.GPT2_MEDIUM_LEGAL_API_ENDPOINT,
settings.GPT2_MEDIUM_RESEARCH_API_ENDPOINT,
settings.GPT2_MEDIUM_COMPANIES_API_ENDPOINT,
]
for url in endpoints:
response = requests.post(url, json=post_data)
data = response.json()
assert response.status_code == 200
# make sure it returns text_4
assert len(data["text_4"]) > 30
示例8: get_complete_url
# 需要导入模块: from django.conf import settings [as 别名]
# 或者: from django.conf.settings import ENVIRONMENT [as 别名]
def get_complete_url(self):
protocol = 'https'
if settings.ENVIRONMENT == 'dev':
protocol = 'http'
return "{}://{}{}".format(
protocol,
Site.objects.get_current().domain,
self.get_absolute_url(),
)
示例9: get_complete_settings_url
# 需要导入模块: from django.conf import settings [as 别名]
# 或者: from django.conf.settings import ENVIRONMENT [as 别名]
def get_complete_settings_url(self):
protocol = 'https'
if settings.ENVIRONMENT == 'dev':
protocol = 'http'
return "{}://{}{}".format(
protocol,
Site.objects.get_current().domain,
self.get_settings_url(),
)
示例10: selected_settings
# 需要导入模块: from django.conf import settings [as 别名]
# 或者: from django.conf.settings import ENVIRONMENT [as 别名]
def selected_settings(request):
return {
'ENVIRONMENT': settings.ENVIRONMENT,
}
示例11: standard_error_page
# 需要导入模块: from django.conf import settings [as 别名]
# 或者: from django.conf.settings import ENVIRONMENT [as 别名]
def standard_error_page(request, status_code, template_filename):
"""
Returns an error page with a given template filename and provides necessary context variables
"""
name = request.user.profile.preferred_name if not request.user.is_anonymous else ""
authenticated = not request.user.is_anonymous
username = get_social_username(request.user)
response = render(
request,
template_filename,
context={
"has_zendesk_widget": True,
"is_public": True,
"js_settings_json": json.dumps({
"release_version": settings.VERSION,
"environment": settings.ENVIRONMENT,
"sentry_dsn": settings.SENTRY_DSN,
"user": serialize_maybe_user(request.user),
}),
"authenticated": authenticated,
"name": name,
"username": username,
"is_staff": has_role(request.user, [Staff.ROLE_ID, Instructor.ROLE_ID]),
"support_email": settings.EMAIL_SUPPORT,
"sentry_dsn": settings.SENTRY_DSN,
}
)
response.status_code = status_code
return response
示例12: _get_buster
# 需要导入模块: from django.conf import settings [as 别名]
# 或者: from django.conf.settings import ENVIRONMENT [as 别名]
def _get_buster():
if settings.ENVIRONMENT == "development":
return int(time.time())
else:
ref = os.getenv("HEAD_COMMIT_ID")
if ref:
# Use the first 7 chars of SHA like git log pretty format
short_ref = ref[:7]
return str(short_ref)
else:
# Missing HEAD_COMMIT_ID environment variable
return "BAD_HEAD_COMMIT_ID"
示例13: get_head_cached
# 需要导入模块: from django.conf import settings [as 别名]
# 或者: from django.conf.settings import ENVIRONMENT [as 别名]
def get_head_cached():
if settings.ENVIRONMENT == "development" or not CacheBusterTag.head:
CacheBusterTag.head = CacheBusterTag._get_buster()
return CacheBusterTag.head
示例14: get_queryset
# 需要导入模块: from django.conf import settings [as 别名]
# 或者: from django.conf.settings import ENVIRONMENT [as 别名]
def get_queryset(self):
most_recent_moniker, most_recent = pgettext("value::plural", "MOST RECENT"), False
if self.query in (most_recent_moniker, most_recent_moniker.replace(" ", "_")):
most_recent = True
self.query = ''
qs = (
self.queryset
.select_related(None)
.defer('description', 'family_members_visibility')
.select_related('owner', 'owner__user')
.defer('owner__description', 'owner__email_visibility')
)
self.result = geocode(self.query)
if self.query and self.result.point:
if any([self.result.country and not self.result.country_code, self.result.state, self.result.city]):
return (qs
.annotate(distance=Distance('location', self.result.point))
.order_by('distance'))
elif self.result.country: # We assume it's a country
self.paginate_first_by = 50
self.paginate_orphans = 5
self.country_search = True
return (qs
.filter(country=self.result.country_code.upper())
.order_by('-owner__user__last_login', '-id'))
position = geocoder.ip(self.request.META['HTTP_X_REAL_IP']
if settings.ENVIRONMENT != 'DEV'
else "188.166.58.162")
position.point = Point(position.xy, srid=SRID) if position.xy else None
logging.getLogger('PasportaServo.geo').debug(
"User's position: %s, %s",
position.address if position.ok and position.address else "UNKNOWN",
position.xy if position.ok else position.error
)
if position.point and not most_recent:
# Results are sorted by distance from user's current location, but probably
# it is better not to creep users out by unexpectedly using their location.
qs = qs.annotate(internal_distance=Distance('location', position.point)).order_by('internal_distance')
else:
qs = qs.order_by('-owner__user__last_login', '-id')
return qs
示例15: get
# 需要导入模块: from django.conf import settings [as 别名]
# 或者: from django.conf.settings import ENVIRONMENT [as 别名]
def get(self, request, *args, **kwargs):
"""
Handle GET requests to templates using React
"""
user = request.user
roles = []
if not user.is_anonymous:
roles = [
{
'program': role.program.id,
'role': role.role,
'permissions': [perm for perm, value in available_perm_status(user).items() if value is True]
} for role in user.role_set.all()
]
js_settings = {
"gaTrackingID": settings.GA_TRACKING_ID,
"reactGaDebug": settings.REACT_GA_DEBUG,
"host": webpack_dev_server_host(request),
"edx_base_url": settings.EDXORG_BASE_URL,
"roles": roles,
"release_version": settings.VERSION,
"environment": settings.ENVIRONMENT,
"sentry_dsn": settings.SENTRY_DSN,
"search_url": reverse('search_api', kwargs={"elastic_url": ""}),
"support_email": settings.EMAIL_SUPPORT,
"user": serialize_maybe_user(request.user),
"es_page_size": settings.ELASTICSEARCH_DEFAULT_PAGE_SIZE,
"public_path": public_path(request),
"EXAMS_SSO_CLIENT_CODE": settings.EXAMS_SSO_CLIENT_CODE,
"EXAMS_SSO_URL": settings.EXAMS_SSO_URL,
"FEATURES": {
"PROGRAM_LEARNERS": settings.FEATURES.get('PROGRAM_LEARNERS_ENABLED', False),
"DISCUSSIONS_POST_UI": settings.FEATURES.get('OPEN_DISCUSSIONS_POST_UI', False),
"DISCUSSIONS_CREATE_CHANNEL_UI": settings.FEATURES.get('OPEN_DISCUSSIONS_CREATE_CHANNEL_UI', False),
"PROGRAM_RECORD_LINK": settings.FEATURES.get('PROGRAM_RECORD_LINK', False),
"ENABLE_PROGRAM_LETTER": settings.FEATURES.get('ENABLE_PROGRAM_LETTER', False)
},
"open_discussions_redirect_url": settings.OPEN_DISCUSSIONS_REDIRECT_URL,
}
return render(
request,
"dashboard.html",
context={
"has_zendesk_widget": True,
"is_public": False,
"google_maps_api": False,
"js_settings_json": json.dumps(js_settings),
"ga_tracking_id": "",
}
)