Python django.conf.settings.DOMAIN Examples

The following are 30 code examples of django.conf.settings.DOMAIN(). 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 Project: donation-tracker   Author: GamesDoneQuick   File: send_volunteer_registration_emails.py    License: Apache License 2.0 6 votes vote down vote up
def handle(self, *args, **options):
        super(Command, self).handle(*args, **options)
        self.message(str(options), 3)
        self.verbosity = options['verbosity']

        dryRun = options['dry_run']
        template = options['template']
        volunteersFile = options['volunteers_list']
        sender = options['sender']
        event = options['event']

        volunteers = volunteer.parse_volunteer_info_file(volunteersFile)

        volunteer.send_volunteer_mail(
            settings.DOMAIN,
            event,
            volunteers,
            template,
            sender,
            verbosity=self.verbosity,
            dry_run=dryRun,
        ) 
Example #2
Source Project: cookiecutter-django-vue   Author: vchaptsev   File: schema.py    License: BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
def mutate(self, info, email):
        try:
            user = User.objects.get(email=email)
        except User.DoesNotExist:
            errors = ['emailDoesNotExists']
            return ResetPassword(success=False, errors=errors)

        params = {
            'user': user,
            'DOMAIN': settings.DOMAIN,
        }
        send_mail(
            subject='Password reset',
            message=render_to_string('mail/password_reset.txt', params),
            from_email=settings.DEFAULT_FROM_EMAIL,
            recipient_list=[email],
        )
        return ResetPassword(success=True) 
Example #3
Source Project: canvas   Author: canvasnetworks   File: util.py    License: BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
def make_absolute_url(relative_url, protocol=None):
    """
    Takes a relative url and makes it absolute by prepending the Canvas absolute domain.

    This refers not to relative as in "foo" resolving to "/bar/foo" when you're already on "/bar", but to an
    absolute path sans the host portion of the URL.

    `protocol` should be the name without the "://", e.g. "http" or "https"
    """
    # Is it already absolute?
    if relative_url.split('//')[-1].startswith(settings.DOMAIN) and relative_url.startswith(protocol or '//'):
        return relative_url

    if protocol:
        protocol = protocol + '://'
    else:
        protocol = '//'

    base = protocol + settings.DOMAIN
    return urljoin(base, relative_url) 
Example #4
Source Project: canvas   Author: canvasnetworks   File: test_bgwork.py    License: BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
def test_full_stack(self):
        path = Config['test_bgwork_path']
        if os.path.isfile(path):
            os.remove(path)

        # Post a fact.
        resp = urllib2.urlopen('http://{}/api/testing/test_bgwork'.format(settings.DOMAIN))

        # Look for the fact.
        TIMEOUT = 10 # s
        t = time.time()
        while True:
            time.sleep(.3)
            if os.path.isfile(Config['test_bgwork_path']):
                break
            if time.time() - t > TIMEOUT:
                raise Exception("test_bgwork flag file wasn't written.") 
Example #5
Source Project: donation-tracker   Author: GamesDoneQuick   File: prize.py    License: Apache License 2.0 5 votes vote down vote up
def make_winner_url(self, domain=settings.DOMAIN):
        return (
            domain
            + reverse('tracker:prize_winner', args=[self.pk])
            + '?auth_code={0}'.format(self.auth_code)
        ) 
Example #6
Source Project: donation-tracker   Author: GamesDoneQuick   File: prizemail.py    License: Apache License 2.0 5 votes vote down vote up
def automail_inactive_prize_handlers(
    event,
    inactiveUsers,
    mailTemplate,
    sender=None,
    replyTo=None,
    domain=settings.DOMAIN,
    verbosity=0,
    dry_run=False,
):
    sender, replyTo = event_sender_replyto_defaults(event, sender, replyTo)
    for inactiveUser in inactiveUsers:
        eventPrizes = list(
            Prize.objects.filter(handler=inactiveUser, event=event, state='ACCEPTED')
        )
        formatContext = {
            'event': event,
            'handler': inactiveUser,
            'register_url': domain + reverse('tracker:register'),
            'prize_set': eventPrizes,
            'prize_count': len(eventPrizes),
            'reply_address': replyTo,
        }
        if not dry_run:
            post_office.mail.send(
                recipients=[inactiveUser.email],
                sender=sender,
                template=mailTemplate,
                context=formatContext,
                headers={'Reply-to': replyTo},
            )
        message = 'Mailed prize handler {0} (#{1}) for account activation'.format(
            inactiveUser, inactiveUser.id
        )
        if verbosity > 0:
            print(message)
        if not dry_run:
            viewutil.tracker_log('prize', message, event) 
Example #7
Source Project: bennedetto   Author: arecker   File: utils.py    License: GNU General Public License v3.0 5 votes vote down vote up
def expand_url_path(path, domain=None):
    domain = domain or settings.DOMAIN
    url = urljoin('//{}'.format(domain), path)
    return url[2:] 
Example #8
Source Project: bennedetto   Author: arecker   File: processors.py    License: GNU General Public License v3.0 5 votes vote down vote up
def constants(request):
    '''
    injects certain constants form settings module
    into template context
    '''
    return {'DEBUG': settings.DEBUG,
            'DOMAIN': settings.DOMAIN,
            'API_URL': settings.API_URL,
            'STATIC_URL': settings.STATIC_URL,
            'VERSION': settings.VERSION} 
Example #9
Source Project: autoAdmin   Author: rfjer   File: serializers.py    License: GNU Lesser General Public License v3.0 5 votes vote down vote up
def create(self, validated_data):
        validated_data["is_active"] = False
        instance = super(UserRegSerializer, self).create(validated_data=validated_data)
        instance.email = "{}{}".format(instance.username, settings.DOMAIN)

        instance.set_password(validated_data["password"])
        instance.id_rsa_key, instance.id_rsa_pub = self.get_sshkey(instance.email)
        instance.save()
        return instance 
Example #10
Source Project: Disfactory   Author: Disfactory   File: tasks.py    License: MIT License 5 votes vote down vote up
def _upload_image_to_imgur(image_buffer, client_id):
    tmp_path = os.path.join(settings.MEDIA_ROOT, f'{uuid4()}.jpg')
    with open(tmp_path, 'wb') as fw:
        fw.write(image_buffer)
    headers = {'Authorization': f'Client-ID {client_id}'}
    data = {'image': image_buffer}
    resp = requests.post(
        'https://api.imgur.com/3/upload',
        data=data,
        headers=headers,
    )
    try:
        resp_data = resp.json()
        if 'errors' in resp_data:
            credit_resp = requests.get(
                'https://api.imgur.com/3/credits',
                headers=headers,
            )
            LOGGER.error(f'Error upload to imgur. The credits remaining: {credit_resp.json()}')
            path = urljoin(urljoin(settings.DOMAIN, settings.MEDIA_URL), os.path.basename(tmp_path))
        else:
            path = resp_data['data']['link']
    except Exception as e:
        LOGGER.error(f'Error parsing imgur response data: {resp_data}')
        path = urljoin(urljoin(settings.DOMAIN, settings.MEDIA_URL), os.path.basename(tmp_path))
    return path 
Example #11
Source Project: cookiecutter-django-vue   Author: vchaptsev   File: views.py    License: BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def password_reset(self, request, format=None):
        if User.objects.filter(email=request.data['email']).exists():
            user = User.objects.get(email=request.data['email'])
            params = {'user': user, 'DOMAIN': settings.DOMAIN}
            send_mail(
                subject='Password reset',
                message=render_to_string('mail/password_reset.txt', params),
                from_email=settings.DEFAULT_FROM_EMAIL,
                recipient_list=[request.data['email']],
            )
            return Response(status=status.HTTP_200_OK)
        else:
            return Response(status=status.HTTP_404_NOT_FOUND) 
Example #12
Source Project: Cinema   Author: ArnaudLevaufre   File: models.py    License: MIT License 5 votes vote down vote up
def item_description(self, item):
        if item.poster:
            return "<div><img src=\"{}\" style=\"width: 200px;\"/><p>{}</p></div>".format(urllib.parse.urljoin(settings.DOMAIN, item.poster.url), item.plot)
        return item.plot 
Example #13
Source Project: Cinema   Author: ArnaudLevaufre   File: models.py    License: MIT License 5 votes vote down vote up
def item_link(self, item):
        return urllib.parse.urljoin(settings.DOMAIN, reverse('watch', kwargs={'mid': item.id})) 
Example #14
Source Project: open-humans   Author: OpenHumans   File: utils.py    License: MIT License 5 votes vote down vote up
def full_url(url_fragment):
    """
    Given a fragment, return that fragment joined to the full Open Humans URL.
    """
    if url_fragment and not url_fragment.startswith("/"):
        return url_fragment

    return urllib.parse.urljoin(
        settings.DEFAULT_HTTP_PROTOCOL + "://" + settings.DOMAIN, str(url_fragment)
    ) 
Example #15
Source Project: canvas   Author: canvasnetworks   File: email_channel.py    License: BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def inline_the_styles(self):
        self.body_html = premailer.transform(self.raw_body_html, base_url="http://" + settings.DOMAIN + "/") 
Example #16
Source Project: canvas   Author: canvasnetworks   File: email_channel.py    License: BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def make_action_unsubscribe_link(self, action, recipient):
        if settings.PROJECT == 'drawquest':
            #TODO individual action unsubscriptions: action instead of 'ALL'
            return '{}/unsubscribe?action={}&token={}&email={}'.format("http://" + settings.DOMAIN, 'ALL', util.token(recipient.email), recipient.email)
        else:
            return string.Template("$absolute_path/unsubscribe?action=$action&token=$token&user_id=$user_id").substitute(
                dict(absolute_path="http://" + settings.DOMAIN,
                     action=action,
                     user_id=recipient.id,
                     token=util.token(recipient.id)),
            ) 
Example #17
Source Project: canvas   Author: canvasnetworks   File: email_channel.py    License: BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def make_thread_unsubscribe_link(self, comment, recipient):
        return string.Template("$absolute_path/unsubscribe?post=$post&token=$token&user_id=$user_id").substitute(
            dict(absolute_path="http://" + settings.DOMAIN,
                 post=comment.thread.op.id,
                 user_id=recipient.id,
                 token=util.token(recipient.id)),
        ) 
Example #18
Source Project: canvas   Author: canvasnetworks   File: middleware.py    License: BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def process_request(self, request):
        def redirect_https():
            return HttpResponseRedirect('https://' + settings.DOMAIN + request.get_full_path())

        if not request.is_secure():
            # Check for a secure_only cookie
            secure_only_cookie = request.COOKIES.get('secure_only', 'false').strip().lower() == 'true'
            # Check the user KV for the Force HTTPS setting.
            secure_only_kv = request.user.is_authenticated() and request.user.kv.secure_only.get()

            if secure_only_cookie or secure_only_kv:
                return redirect_https() 
Example #19
Source Project: canvas   Author: canvasnetworks   File: view_guards.py    License: BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def require_secure(request):
    if not settings.HTTPS_ENABLED:
        return

    if request.META.get('HTTP_X_FORWARDED_PROTO') != 'https':
        return HttpResponseRedirect('https://' + settings.DOMAIN + request.get_full_path()) 
Example #20
Source Project: canvas   Author: canvasnetworks   File: test_util.py    License: BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def setUp(self):
        super(TestAbsoluteUrls, self).setUp()
        self._domain, settings.DOMAIN = settings.DOMAIN, 'foo.com' 
Example #21
Source Project: canvas   Author: canvasnetworks   File: test_util.py    License: BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def tearDown(self):
        settings.DOMAIN = self._domain
        super(TestAbsoluteUrls, self).tearDown() 
Example #22
Source Project: canvas   Author: canvasnetworks   File: sitemaps.py    License: BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def get_urls(self, page=1, site=None):
        """ A hack so that we don't have to use django.sites
        """
        urls = super(BaseSitemap, self).get_urls(page, site)
        if site.domain != settings.DOMAIN:
            for url in urls:
                url['location'] = url['location'].replace("http://"+site.domain, "", 1)
        return urls 
Example #23
Source Project: canvas   Author: canvasnetworks   File: models.py    License: BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def absolute_url(self):
        return 'http://' + settings.DOMAIN + self.url 
Example #24
Source Project: canvas   Author: canvasnetworks   File: models.py    License: BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def generate_homepage():
    threads = spotlighted_threads()
    ctx = {
        'threads': threads,
        'DOMAIN': settings.DOMAIN,
    }
    return render_jinja_to_string('logged_out_homepage/homepage.html', ctx) 
Example #25
Source Project: canvas   Author: canvasnetworks   File: tests.py    License: BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def check_comment(self, expected, json):
        self.assertEqual(short_id(expected.id), json['id'])
        self.assertEqual(expected.title, json['title'])
        self.assertEqual(expected.category, json['category'])
        self.assertEqual(expected.reply_text, json['caption'])
        self.assertEqual(expected.author_name, json['author_name'])
        self.assertEqual(expected.parent_comment, json['parent_comment'])
        self.assertEqual(expected.parent_url, json['parent_url'])
        self.assertEqual(short_id(expected.thread_op_comment_id), json['thread_op_id'])
        self.assertEqual("https://{0}".format(settings.DOMAIN) + expected.share_page_url, json['share_page_url'])
        self.assertEqual(expected.replied_comment, json['reply_to'])
        self.assertEqual(expected.top_sticker(), json['top_sticker'])
        self.assertEqual(int(expected.timestamp), json['timestamp'])
        self.assertEqual("https://{0}".format(settings.DOMAIN) + expected.url, json['url']) 
Example #26
Source Project: canvas   Author: canvasnetworks   File: models.py    License: BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def url(self):
        return "https://{0}/x/{1}".format(settings.DOMAIN, self.group) 
Example #27
Source Project: canvas   Author: canvasnetworks   File: models.py    License: BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def api_url(self):
        return "https://{0}/public/users/{1}".format(settings.DOMAIN, self.user) 
Example #28
Source Project: canvas   Author: canvasnetworks   File: models.py    License: BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def api_url(self):
        return "https://{0}/public_api/posts/{1}".format(settings.DOMAIN, self.post_id()) 
Example #29
Source Project: canvas   Author: canvasnetworks   File: models.py    License: BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def absolute_url(self):
        return "https://{0}{1}".format(settings.DOMAIN, self.url) 
Example #30
Source Project: canvas   Author: canvasnetworks   File: models.py    License: BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def absolute_parent_url(self):
        if not self.parent_url:
            return None
        return "https://{0}{1}".format(settings.DOMAIN, self.parent_url)