本文整理匯總了Python中django.conf.settings.BASE_URL屬性的典型用法代碼示例。如果您正苦於以下問題:Python settings.BASE_URL屬性的具體用法?Python settings.BASE_URL怎麽用?Python settings.BASE_URL使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在類django.conf.settings
的用法示例。
在下文中一共展示了settings.BASE_URL屬性的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: make_absolute_url
# 需要導入模塊: from django.conf import settings [as 別名]
# 或者: from django.conf.settings import BASE_URL [as 別名]
def make_absolute_url(path, site_name=None):
if re.match(r"^https?://", path):
return path
if site_name:
config = site_config.by_hostname(site_name)
if settings.BASE_URL:
url_base = settings.BASE_URL
path = add_params(path, {"_hostname": config.hostname})
else:
url_base = f"https://{config.hostname}"
else:
hostname = settings.SERVER_DOMAIN
scheme = "http" if hostname.startswith("localhost") else "https"
url_base = f"{scheme}://{hostname}"
return parse.urljoin(url_base, path)
示例2: post
# 需要導入模塊: from django.conf import settings [as 別名]
# 或者: from django.conf.settings import BASE_URL [as 別名]
def post(self, request, *args, **kwargs):
if request.is_ajax():
group = self.get_object()
user = UserProfile.objects.get(user__pk=self.request.POST.get('user')).user
if user not in group.join_requests.all():
return HttpResponseForbidden()
group.join_requests.remove(user)
push_notification([user], 'group_join_request_rejected',
{
'group_name': group.name,
'url': settings.BASE_URL + reverse('group_detail', args=(group.pk,)),
})
return self.render_json_response({
'member': user.pk,
})
# Only AJAX allowed
return HttpResponseForbidden()
示例3: imagerevision_post_save
# 需要導入模塊: from django.conf import settings [as 別名]
# 或者: from django.conf.settings import BASE_URL [as 別名]
def imagerevision_post_save(sender, instance, created, **kwargs):
if created and not instance.image.is_wip and not instance.skip_notifications:
followers = [x.user for x in ToggleProperty.objects.filter(
property_type="follow",
content_type=ContentType.objects.get_for_model(User),
object_id=instance.image.user.pk)]
push_notification(followers, 'new_image_revision',
{
'object_url': settings.BASE_URL + instance.get_absolute_url(),
'originator': instance.image.user.userprofile.get_display_name(),
})
add_story(instance.image.user,
verb='VERB_UPLOADED_REVISION',
action_object=instance,
target=instance.image)
示例4: solution_post_save
# 需要導入模塊: from django.conf import settings [as 別名]
# 或者: from django.conf.settings import BASE_URL [as 別名]
def solution_post_save(sender, instance, created, **kwargs):
ct = instance.content_type
try:
target = ct.get_object_for_this_type(pk=instance.object_id)
except ct.model_class().DoesNotExist:
return
if ct.model == 'image':
user = target.user
elif ct.model == 'imagerevision':
user = target.image.user
else:
return
if instance.status == Solver.FAILED:
notification = 'image_not_solved'
elif instance.status == Solver.SUCCESS:
notification = 'image_solved'
else:
return
push_notification([user], notification,
{'object_url': settings.BASE_URL + target.get_absolute_url()})
示例5: forum_topic_pre_save
# 需要導入模塊: from django.conf import settings [as 別名]
# 或者: from django.conf.settings import BASE_URL [as 別名]
def forum_topic_pre_save(sender, instance, **kwargs):
if not hasattr(instance.forum, 'group'):
return
try:
topic = sender.objects.get(pk=instance.pk)
except sender.DoesNotExist:
pass
else:
if topic.on_moderation == True and instance.on_moderation == False:
# This topic is being approved
group = instance.forum.group
push_notification(
[x for x in group.members.all() if x != instance.user],
'new_topic_in_group',
{
'user': instance.user.userprofile.get_display_name(),
'url': settings.BASE_URL + instance.get_absolute_url(),
'group_url': reverse_url('group_detail', kwargs={'pk': group.pk}),
'group_name': group.name,
'topic_title': instance.name,
},
)
示例6: forum_topic_post_save
# 需要導入模塊: from django.conf import settings [as 別名]
# 或者: from django.conf.settings import BASE_URL [as 別名]
def forum_topic_post_save(sender, instance, created, **kwargs):
if created and hasattr(instance.forum, 'group'):
group = instance.forum.group
if instance.on_moderation:
recipients = group.moderators.all()
else:
recipients = group.members.all()
recipients = [x for x in recipients if x != instance.user]
push_notification(
recipients,
'new_topic_in_group',
{
'user': instance.user.userprofile.get_display_name(),
'url': settings.BASE_URL + instance.get_absolute_url(),
'group_url': settings.BASE_URL + reverse_url('group_detail', kwargs={'pk': group.pk}),
'group_name': group.name,
'topic_title': instance.name,
},
)
示例7: approve
# 需要導入模塊: from django.conf import settings [as 別名]
# 或者: from django.conf.settings import BASE_URL [as 別名]
def approve(self):
app, created = App.objects.get_or_create(
registrar=self.registrar, name=self.name,
description=self.description)
self.approved = True
self.save()
if created:
push_notification(
[self.registrar], 'api_key_request_approved',
{'api_docs_url': settings.BASE_URL + '/help/api/',
'api_keys_url': settings.BASE_URL + '/users/%s/apikeys/' % self.registrar.username,
'key': app.key,
'secret': app.secret})
else:
app.active = True
app.save()
示例8: send_email
# 需要導入模塊: from django.conf import settings [as 別名]
# 或者: from django.conf.settings import BASE_URL [as 別名]
def send_email(self, email_type):
from django.core.mail import send_mail
from django.template.loader import render_to_string
from django.conf import settings
email_content = render_to_string(
"billing/invoice_%s.txt" % email_type,
context={
"username":self.customer.user.username,
"amount":self.amount_string(),
"due_date":datetime.datetime.fromtimestamp(
self.customer.expiry_timestamp
).strftime('%B %-d'),
"invoice_id":self.pk,
"base_url":settings.BASE_URL
}
)
result = send_mail(
'Your Acacia Invoice',
email_content,
'noreply@tradeacacia.com',
[self.customer.user.email],
fail_silently=True
)
return result == 1
示例9: generate_download_script
# 需要導入模塊: from django.conf import settings [as 別名]
# 或者: from django.conf.settings import BASE_URL [as 別名]
def generate_download_script(dataset):
access_token_url = urljoin(settings.BASE_URL, reverse('get_access_token'))
dataset_url = urljoin(settings.BASE_URL, reverse('dataset-sounds',
kwargs={"short_name": dataset.short_name}))
tvars = {
'access_token_url': access_token_url,
'dataset_url': dataset_url,
'get_code_url': settings.FS_CLIENT_ID
}
return render_to_string('datasets/download_script.py', tvars)
示例10: generate_notifications_for_incident
# 需要導入模塊: from django.conf import settings [as 別名]
# 或者: from django.conf.settings import BASE_URL [as 別名]
def generate_notifications_for_incident(incident):
now = timezone.make_aware(datetime.now(), timezone.get_current_timezone())
duty_officers = get_escalation_for_service(incident.service_key)
current_time = now
notifications = []
for officer_index, duty_officer in enumerate(duty_officers):
escalation_time = incident.service_key.escalate_after * (officer_index + 1)
escalate_at = current_time + timedelta(minutes=escalation_time)
methods = duty_officer.notification_methods.order_by('position').all()
method_index = 0
for method in methods:
notification_time = incident.service_key.retry * method_index + incident.service_key.escalate_after * officer_index
notify_at = current_time + timedelta(minutes=notification_time)
if notify_at < escalate_at:
notification = ScheduledNotification()
notification.incident = incident
notification.user_to_notify = duty_officer
notification.notifier = method.method
notification.send_at = notify_at
uri = settings.BASE_URL + "/incidents/details/" + str(incident.id)
notification.message = "A Service is experiencing a problem: " + incident.incident_key + " " + incident.description + ". Handle at: " + uri + " Details: " + incident.details
notifications.append(notification)
print "Notify %s at %s with method: %s" % (duty_officer.username, notify_at, notification.notifier)
else:
break
method_index += 1
# todo: error handling
return notifications
示例11: generate_notifications_for_user
# 需要導入模塊: from django.conf import settings [as 別名]
# 或者: from django.conf.settings import BASE_URL [as 別名]
def generate_notifications_for_user(incident, user, delay=None, preparedmsg = None):
now = timezone.make_aware(datetime.now(), timezone.get_current_timezone())
current_time = now
notifications = []
methods = user.notification_methods.order_by('position').all()
method_index = 0
for method in methods:
if delay is None:
notification_time = incident.service_key.retry * method_index + incident.service_key.escalate_after
else:
notification_time = method_index * delay
notify_at = current_time + timedelta(minutes=notification_time)
notification = ScheduledNotification()
notification.incident = incident
notification.user_to_notify = user
notification.notifier = method.method
notification.send_at = notify_at
if preparedmsg is None:
uri = settings.BASE_URL + "/incidents/details/" + str(incident.id)
notification.message = "A Service is experiencing a problem: " + incident.incident_key + " " + incident.description + ". Handle at: " + uri
else:
notification.message = preparedmsg
notifications.append(notification)
print "Notify %s at %s with method: %s" % (user.username, notify_at, notification.notifier)
method_index += 1
# todo: error handling
return notifications
示例12: daily_mail
# 需要導入模塊: from django.conf import settings [as 別名]
# 或者: from django.conf.settings import BASE_URL [as 別名]
def daily_mail(force=False):
if date.today() in holidays.France() and not force:
return
for caisse in Caisse.objects.filter(active=True):
mrsrequests = caisse.mrsrequest_set.all().status('new').order_by(
'creation_datetime')
if not len(mrsrequests):
continue
context = dict(
object_list=mrsrequests,
BASE_URL=settings.BASE_URL,
ADMIN_ROOT=crudlfap.site.views['home'].url,
)
Caller(
callback='djcall.django.email_send',
kwargs=dict(
subject=template.loader.get_template(
'caisse/liquidation_daily_mail_title.txt',
).render(context).strip(),
body=template.loader.get_template(
'caisse/liquidation_daily_mail_body.html',
).render(context).strip(),
to=[caisse.liquidation_email],
reply_to=[settings.DEFAULT_FROM_EMAIL],
content_subtype='html'
)
).spool('mail')
示例13: password_reset
# 需要導入模塊: from django.conf import settings [as 別名]
# 或者: from django.conf.settings import BASE_URL [as 別名]
def password_reset(self, caisse):
created = not self.password
password = secrets.token_urlsafe(16)
self.set_password(password)
self.save()
password_email_template = template.loader.get_template(
'mrsuser/user_password_email.txt',
)
# In case of super admins not linked to any caisse, reply_to heads
# to settings.TEAM_EMAIL
email = caisse.habilitation_email if caisse else None
if email:
reply_to = email
else:
reply_to = settings.TEAM_EMAIL
Caller(
callback='djcall.django.email_send',
kwargs=dict(
subject=(
'[MRS] Votre mot de passe'
if created else
'[MRS] Votre nouveau mot de passe'
),
body=password_email_template.render(dict(
created=created,
user=self,
password=password,
BASE_URL=settings.BASE_URL,
)),
to=[self.email],
reply_to=[reply_to],
)
).spool('mail')
示例14: post
# 需要導入模塊: from django.conf import settings [as 別名]
# 或者: from django.conf.settings import BASE_URL [as 別名]
def post(self, request, *args, **kwargs):
if self.object.status != self.object.STATUS_NEW:
return http.HttpResponseBadRequest()
self.object.status = self.object.STATUS_CANCELED
self.object.status_datetime = datetime.now()
self.object.save()
self.object.logentries.create(
action=MRSRequest.STATUS_CANCELED,
comment='Annulation',
)
body = template.loader.get_template(
'mrsrequest/cancelation_email.txt'
).render(dict(object=self.object, base_url=settings.BASE_URL)).strip()
Caller(
callback='djcall.django.email_send',
kwargs=dict(
subject=f'MRS: Annulation demande {self.object.display_id}',
body=body.strip(),
to=[self.object.insured.email],
reply_to=[self.object.caisse.liquidation_email],
)
).spool('mail')
return generic.TemplateView.get(self, request, *args, **kwargs)
示例15: __init__
# 需要導入模塊: from django.conf import settings [as 別名]
# 或者: from django.conf.settings import BASE_URL [as 別名]
def __init__(self, obj, index):
has_canonical = hasattr(obj, 'canonical_name') and obj.canonical_name
self.name = obj.canonical_name if has_canonical else obj.name
self.url = settings.BASE_URL + url_mapping[obj.__class__] + obj.str_id
self.index = index