Python django.conf.settings.BASE_URL Examples
The following are 30
code examples of django.conf.settings.BASE_URL().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
django.conf.settings
, or try the search function
.
Example #1
Source File: utils.py From cornerwise with MIT License | 6 votes |
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)
Example #2
Source File: group_reject_join_request.py From astrobin with GNU Affero General Public License v3.0 | 6 votes |
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()
Example #3
Source File: signals.py From astrobin with GNU Affero General Public License v3.0 | 6 votes |
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)
Example #4
Source File: signals.py From astrobin with GNU Affero General Public License v3.0 | 6 votes |
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()})
Example #5
Source File: signals.py From astrobin with GNU Affero General Public License v3.0 | 6 votes |
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, }, )
Example #6
Source File: signals.py From astrobin with GNU Affero General Public License v3.0 | 6 votes |
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, }, )
Example #7
Source File: api.py From astrobin with GNU Affero General Public License v3.0 | 5 votes |
def dehydrate_url_hd(self, bundle): return '%s/%s/%s/rawthumb/hd/' % (settings.BASE_URL, bundle.obj.image.get_id(), bundle.obj.label)
Example #8
Source File: group_join.py From astrobin with GNU Affero General Public License v3.0 | 5 votes |
def post(self, request, *args, **kwargs): group = self.get_object() def doAdd(user, group): group.members.add(user) group.invited_users.remove(user) group.join_requests.remove(user) messages.success(request, _("You have joined the group")) if request.user in group.members.all(): messages.error(request, _("You already were a member of this group")) return redirect(self.get_success_url()) if group.public: if group.moderated and request.user != group.owner: group.join_requests.add(request.user) messages.warning(request, _("This is a moderated group, and your join request will be reviewed by a moderator")) push_notification(group.moderators.all(), 'new_group_join_request', { 'requester': request.user.userprofile.get_display_name(), 'group_name': group.name, 'url': settings.BASE_URL + reverse('group_moderate_join_requests', args=(group.pk,)), }) return redirect(self.get_success_url()) else: doAdd(request.user, group) return redirect(self.get_success_url()) else: if request.user in group.invited_users.all() or request.user == group.owner: doAdd(request.user, group) return redirect(self.get_success_url()) return HttpResponseForbidden()
Example #9
Source File: models.py From astrobin with GNU Affero General Public License v3.0 | 5 votes |
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()
Example #10
Source File: send_missing_data_source_notifications.py From astrobin with GNU Affero General Public License v3.0 | 5 votes |
def handle(self, *args, **kwargs): # To avoid sending too many emails, only get the users that joined on the same day of the month as today. By # running this script daily, you get to spread all these emails over a period of 30 days, and each user doesn't # get it more often than once a month. for user in User.objects.filter(date_joined__day = date.today().day): images = Image.objects.filter(user=user, data_source="UNSET") if images.count() > 0: push_notification([user], 'missing_data_source', { 'BASE_URL': settings.BASE_URL, 'images': images })
Example #11
Source File: api.py From astrobin with GNU Affero General Public License v3.0 | 5 votes |
def dehydrate_url_thumb(self, bundle): return '%s/%s/%s/rawthumb/thumb/' % (settings.BASE_URL, bundle.obj.image.get_id(), bundle.obj.label)
Example #12
Source File: api.py From astrobin with GNU Affero General Public License v3.0 | 5 votes |
def dehydrate_url_gallery(self, bundle): return '%s/%s/%s/rawthumb/gallery/' % (settings.BASE_URL, bundle.obj.image.get_id(), bundle.obj.label)
Example #13
Source File: api.py From astrobin with GNU Affero General Public License v3.0 | 5 votes |
def dehydrate_url_regular(self, bundle): return '%s/%s/%s/rawthumb/regular/' % (settings.BASE_URL, bundle.obj.image.get_id(), bundle.obj.label)
Example #14
Source File: api.py From astrobin with GNU Affero General Public License v3.0 | 5 votes |
def dehydrate_url_regular_sharpened(self, bundle): return '%s/%s/%s/rawthumb/regular_sharpened/' % (settings.BASE_URL, bundle.obj.image.get_id(), bundle.obj.label)
Example #15
Source File: group_invite.py From astrobin with GNU Affero General Public License v3.0 | 5 votes |
def post(self, request, *args, **kwargs): group = self.get_object() for pk in request.POST.getlist('users[]'): try: user = UserProfile.objects.get(user__pk=pk).user except UserProfile.DoesNotExist: continue group.invited_users.add(user) push_notification([user], 'new_group_invitation', { 'inviter': request.user.userprofile.get_display_name(), 'inviter_page': reverse('user_page', args=(request.user.username,)), 'group_name': group.name, 'group_page': settings.BASE_URL + reverse('group_detail', args=(group.pk,)), }) if request.is_ajax(): return self.render_json_response({ 'invited_users': [{ 'id': x.id, 'username': x.username, 'display_name': x.userprofile.get_display_name(), 'url': reverse('user_page', args=(x.username,)), 'revoke_url': reverse('group_revoke_invitation', args=(group.pk,)), } for x in group.invited_users.all()] }) return redirect(self.get_success_url())
Example #16
Source File: api.py From astrobin with GNU Affero General Public License v3.0 | 5 votes |
def dehydrate_url_real(self, bundle): return '%s/%s/%s/rawthumb/real/' % (settings.BASE_URL, bundle.obj.image.get_id(), bundle.obj.label)
Example #17
Source File: api.py From astrobin with GNU Affero General Public License v3.0 | 5 votes |
def dehydrate_url_duckduckgo(self, bundle): return '%s/%s/%s/rawthumb/duckduckgo/' % (settings.BASE_URL, bundle.obj.image.get_id(), bundle.obj.label)
Example #18
Source File: api.py From astrobin with GNU Affero General Public License v3.0 | 5 votes |
def dehydrate_url_duckduckgo_small(self, bundle): return '%s/%s/%s/rawthumb/duckduckgo_small/' % (settings.BASE_URL, bundle.obj.image.get_id(), bundle.obj.label)
Example #19
Source File: api.py From astrobin with GNU Affero General Public License v3.0 | 5 votes |
def dehydrate_url_thumb(self, bundle): return '%s/%s/0/rawthumb/thumb/' % (settings.BASE_URL, bundle.obj.get_id())
Example #20
Source File: api.py From astrobin with GNU Affero General Public License v3.0 | 5 votes |
def dehydrate_url_gallery(self, bundle): return '%s/%s/0/rawthumb/gallery/' % (settings.BASE_URL, bundle.obj.get_id())
Example #21
Source File: api.py From astrobin with GNU Affero General Public License v3.0 | 5 votes |
def dehydrate_url_hd(self, bundle): return '%s/%s/0/rawthumb/hd/' % (settings.BASE_URL, bundle.obj.get_id())
Example #22
Source File: api.py From astrobin with GNU Affero General Public License v3.0 | 5 votes |
def dehydrate_url_real(self, bundle): return '%s/%s/0/rawthumb/real/' % (settings.BASE_URL, bundle.obj.get_id())
Example #23
Source File: api.py From astrobin with GNU Affero General Public License v3.0 | 5 votes |
def dehydrate_url_duckduckgo(self, bundle): return '%s/%s/0/rawthumb/duckduckgo/' % (settings.BASE_URL, bundle.obj.get_id())
Example #24
Source File: api.py From astrobin with GNU Affero General Public License v3.0 | 5 votes |
def dehydrate_url_duckduckgo_small(self, bundle): return '%s/%s/0/rawthumb/duckduckgo_small/' % (settings.BASE_URL, bundle.obj.get_id())
Example #25
Source File: solution.py From astrobin with GNU Affero General Public License v3.0 | 5 votes |
def post(self, request, *args, **kwargs): username = request.POST.get('userName') password = request.POST.get('userPassword') if username != settings.PIXINSIGHT_USERNAME or password != settings.PIXINSIGHT_PASSWORD: return HttpResponseForbidden() task = PlateSolvingAdvancedTask.objects.filter(active=True).order_by('-created').first() if task is None: return HttpResponse('') task.active = False task.save() response = \ 'OK\n' \ 'serialNumber=%s\n' \ 'taskType=%s\n' \ 'taskParams=%s\n' \ 'requestUser=%s\n' \ 'requestUTC=%s\n' \ 'callbackURL=%s\n' % ( task.serial_number, 'ASTROBIN_SVG_OVERLAY', task.task_params, username, task.created, settings.BASE_URL + reverse('astrobin_apps_platesolving.pixinsight_webhook') ) log.debug("PixInsight next-task: sending response\n%s" % response) return HttpResponse(response)
Example #26
Source File: send_expiration_notifications.py From astrobin with GNU Affero General Public License v3.0 | 5 votes |
def handle(self, *args, **kwargs): user_subscriptions = UserSubscription.objects.filter( subscription__group__name__in = ['astrobin_lite', 'astrobin_premium'], subscription__recurrence_unit = None, expires = datetime.now() - timedelta(days = 1)) for user_subscription in user_subscriptions: push_notification([user_subscription.user], 'expired_subscription', { 'user_subscription': user_subscription, 'url': settings.BASE_URL + reverse('subscription_detail', kwargs = { 'object_id': user_subscription.subscription.pk }) })
Example #27
Source File: send_renewal_notifications.py From astrobin with GNU Affero General Public License v3.0 | 5 votes |
def handle(self, *args, **kwargs): user_subscriptions = UserSubscription.objects\ .filter( subscription__group__name__in = ['astrobin_lite', 'astrobin_premium'], expires = datetime.now() + timedelta(days = 7))\ .exclude(subscription__recurrence_unit = None) for user_subscription in user_subscriptions: push_notification([user_subscription.user], 'expiring_subscription_autorenew', { 'user_subscription': user_subscription, 'url': settings.BASE_URL + reverse('subscription_detail', kwargs = { 'object_id': user_subscription.subscription.pk }) })
Example #28
Source File: models.py From django-examples with MIT License | 5 votes |
def get_absolute_url(self): path = reverse('post', kwargs={'pk': self.id}) return urljoin(settings.BASE_URL, path)
Example #29
Source File: helper.py From openduty with MIT License | 5 votes |
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
Example #30
Source File: views.py From mrs with GNU Affero General Public License v3.0 | 5 votes |
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)