Python django.conf.settings 模块,SITE_URL 实例源码

我们从Python开源项目中,提取了以下33个代码示例,用于说明如何使用django.conf.settings.SITE_URL

项目:buildinfo.debian.net    作者:lamby    | 项目源码 | 文件源码
def checksums(request, sha1):
    buildinfo = Buildinfo.objects.filter(
        checksums__checksum_sha1=sha1,
    ).select_related(
        'source',
        'architecture',
    ).order_by()

    return JsonResponse({'buildinfos': [{
        'uri': '{}{}'.format(
            settings.SITE_URL,
            x.get_absolute_url(),
        ),
        'raw-uri': '{}{}'.format(
            settings.SITE_URL,
            x.get_absolute_raw_url(),
        ),
        'source': x.source.name,
        'version': x.version,
        'architecture': x.architecture.name,
    } for x in buildinfo]})
项目:teamreporter    作者:agilentia    | 项目源码 | 文件源码
def send_summary(report_pk):
    report = Report.objects.get(pk=report_pk)
    daily = report.get_daily()
    messages = []
    questions = daily.report.question_set.active()
    surveys = daily.survey_set.all()
    for user in report.stakeholders:
        context = Context({'user': user,
                           'daily': daily,
                           'surveys': surveys,
                           'questions': questions})
        context['SITE_URL'] = settings.SITE_URL
        subject = render_to_string('email/summary_subject.txt', context)

        text = get_template('email/summary.txt')
        html = get_template('email/summary.html')
        text_content = text.render(context)
        html_content = html.render(context)
        messages.append([subject, text_content, html_content, settings.DEFAULT_FROM_EMAIL, [user.email]])

    send_mass_html_mail(messages)
    daily.summary_submitted = now()
    daily.save()
项目:url-shortener    作者:modihere    | 项目源码 | 文件源码
def shorten_url(request):
    url = request.POST.get("url", '')
    valid_url,url=validate_url(url)
    if valid_url:
        if url in record:
            short_id = record.get(url)
            response_data = {}
            response_data['url'] = settings.SITE_URL + "/" + short_id
            return HttpResponse(json.dumps(response_data),  content_type="application/json")
        else:
            # check whether input is already short 
            if is_already_short(url):
                response_data = {}
                return HttpResponse(json.dumps({"already_short": True}), content_type="application/json")
            else:
                short_id = get_short_code()
                record.update({url:short_id})
                b = urls(httpurl=url, short_id=short_id)
                b.save()
                response_data = {}
                response_data['url'] = settings.SITE_URL + "/" + short_id
                return HttpResponse(json.dumps(response_data),  content_type="application/json")
    return HttpResponse(json.dumps({"error": "error occurs", "valid_url":valid_url,'url':url}), content_type="application/json")
项目:url-shortener    作者:modihere    | 项目源码 | 文件源码
def is_already_short(url):
    popular_shortening_urls = [
        'bit.ly/',
        'goo.gl/',
        'ow.ly/',
        'is.gd/',
        'buff.ly/',
        'adf.ly/',
        'tinyurl.com/',
        'bit.do/',
        'mcaf.ee/',
        't.co/',
        'tiny.cc/',
        'shorte.st/',
        'idek.net/',
        'po.st/',
        'yep.it/',
        'tr.im/',
        settings.SITE_URL,
    ]
    for shortening_url in popular_shortening_urls:
        if shortening_url in url:
            return True
    return False
项目:vaultier    作者:Movile    | 项目源码 | 文件源码
def _build_url(self):
        """
        Generate frontend url to granted object

        :return: str
        """
        u = urlparse.urljoin(settings.SITE_URL, '/#/')

        m = self.object.__class__.__name__

        if m == 'Workspace':
            return urlparse.urljoin(
                u, 'workspaces/w/{}'.format(self.object.slug)
            )
        elif m == 'Vault':
            return urlparse.urljoin(
                u, 'workspaces/w/{}/vaults/v/{}'.format(
                    self.object.workspace.slug, self.object.slug))
        elif m == 'Card':
            return urlparse.urljoin(
                u, '/workspaces/w/{}/vaults/v/{}/cards/c/{}'.format(
                    self.object.vault.workspace.slug, self.object.vault.slug,
                    self.object.slug))

        return None
项目:knowledge-base    作者:Axiacore    | 项目源码 | 文件源码
def form_valid(self, form):
        email = form.cleaned_data['email']
        user = User.objects.get(username=email)
        safe = URLSafeTimedSerializer(settings.SECRET_KEY)
        url = '{site}{path}?key={key}'.format(
            site=settings.SITE_URL,
            path=reverse('login'),
            key=safe.dumps(user.id),
        )

        send_mail(
            _('Link to login into the Knowledge Base'),
            url,
            settings.DEFAULT_FROM_EMAIL,
            [email],
            fail_silently=False,
            html_message=render_to_string(
                'login_email.html', {'url': url}
            ),
        )

        return redirect('home')
项目:tg-utils    作者:thorgate    | 项目源码 | 文件源码
def check_production_settings(app_configs, **kwargs):
    issues = []

    if settings.DEBUG:
        return issues

    if not settings.EMAIL_HOST_PASSWORD or 'TODO' in settings.EMAIL_HOST_PASSWORD:
        issues.append(
            Warning(
                "EMAIL_HOST_PASSWORD setting is not set to proper value",
                id='tg_utils.W001',
            )
        )

    if 'TODO' in settings.SITE_URL:
        issues.append(
            Warning(
                "SITE_URL setting is not set to proper value",
                id='tg_utils.W002',
            )
        )

    return issues
项目:MetaCI    作者:SalesforceFoundation    | 项目源码 | 文件源码
def get_external_url(self):
        url = '{}{}'.format(settings.SITE_URL, self.get_absolute_url())
        return url
项目:zing    作者:evernote    | 项目源码 | 文件源码
def _sign(self, q, a, expires):
        plain = [getattr(settings, 'SITE_URL', ''), settings.SECRET_KEY,
                 q, a, expires]
        plain = "".join([str(p) for p in plain])
        return sha1(plain).hexdigest()
项目:portailva    作者:BdEINSALyon    | 项目源码 | 文件源码
def app_settings(request):
    """
    A context processor with all APP settings.
    """
    return {
        'app': settings.PORTAILVA_APP,
        'site_url': settings.SITE_URL
    }
项目:buildinfo.debian.net    作者:lamby    | 项目源码 | 文件源码
def submit(request):
    try:
        submission, created = parse_submission(request)
    except InvalidSubmission as exc:
        return HttpResponseBadRequest("Rejecting submission: {}\n".format(exc))

    return HttpResponse('{}{}\n'.format(
        settings.SITE_URL,
        submission.buildinfo.get_absolute_url(),
    ), status=201 if created else 200)
项目:teamreporter    作者:agilentia    | 项目源码 | 文件源码
def send_survey(survey_pk):
    survey = Survey.objects.get(pk=survey_pk)

    context = Context({'survey': survey,
                       'questions': survey.report.question_set.active()})
    context['SITE_URL'] = settings.SITE_URL
    subject = render_to_string('email/survey_subject.txt', context)

    text = get_template('email/survey.txt')
    html = get_template('email/survey.html')
    text_content = text.render(context)
    html_content = html.render(context)

    survey.user.email_user(subject, text_content, settings.DEFAULT_FROM_EMAIL, html_message=html_content)
项目:pretalx    作者:pretalx    | 项目源码 | 文件源码
def env(event):
    settings.SITE_URL = 'http://example.com'
    settings.SITE_NETLOC = urlparse(settings.SITE_URL).netloc
项目:pretalx    作者:pretalx    | 项目源码 | 文件源码
def get(self, request, event, **kwargs):
        talk = self.get_object().slots.get(schedule=self.request.event.current_schedule)
        netloc = urlparse(settings.SITE_URL).netloc

        cal = vobject.iCalendar()
        cal.add('prodid').value = '-//pretalx//{}//{}'.format(netloc, talk.submission.code)
        talk.build_ical(cal)

        resp = HttpResponse(cal.serialize(), content_type='text/calendar')
        resp['Content-Disposition'] = f'attachment; filename="{request.event.slug}-{talk.submission.code}.ics"'
        return resp
项目:no-design-slack-clone    作者:metsavaht    | 项目源码 | 文件源码
def send_password_reset(user, uid, token):
    try:
        email_subject = _('No Design Slack Clone password reset')
        confirm_reset_url = "%s%s" % (settings.SITE_URL,
                                      reverse('password_reset_confirm', kwargs={'uidb64': uid, 'token': token}))

        return send_email(user.email, email_subject, 'emails/password_reset.html', {
            'user': user,
            'confirm_reset_url': confirm_reset_url,
        })
    except Exception:
        logger.exception("Couldn't send password reset to %s (%d)", user.email, user.id)
项目:vaultier    作者:Movile    | 项目源码 | 文件源码
def _build_url(self):
        """
        Generate frontend url to lost key page

        :return:
        """
        return urlparse.urljoin(
            settings.SITE_URL,
            '#/lostkey/{}/{}/'.format(self.object.id, self.object.hash)
        )
项目:vaultier    作者:Movile    | 项目源码 | 文件源码
def _build_context(self, **kwargs):
        """
        Adds extra variables to template Context

        :param kwargs: dict
        :return: Context
        """
        kwargs.update({
            'SITE_URL': settings.SITE_URL,
            'url': self._build_url()
        })
        return super(InvitationMailer, self)._build_context(**kwargs)
项目:vaultier    作者:Movile    | 项目源码 | 文件源码
def _build_url(self):
        """
        Generate frontend url to granted object

        :return: str
        """
        return urlparse.urljoin(
            settings.SITE_URL, '#/invitations/use/{}/{}/'.format(
                self.object.id, self.object.invitation_hash
            )
        )
项目:vaultier    作者:Movile    | 项目源码 | 文件源码
def _build_url(self):
        """
        Generate frontend url to granted object

        :return: str
        """
        return urlparse.urljoin(settings.SITE_URL, '#/workspaces/w/{}/'.format(
            self.object.workspace.slug))
项目:vaultier    作者:Movile    | 项目源码 | 文件源码
def _build_context(self, **kwargs):
        """
        Must return an instance of django.template.context.Context
        with the template variables set for each implementation
        :return: None
        """
        # adding full url to logo
        kwargs.update({
            'logo_url': "{}vaultier/images/logo-email.png".format(
                urljoin(settings.SITE_URL, settings.STATIC_URL))
        })
        return Context(kwargs)
项目:confrontiv    作者:correctiv    | 项目源码 | 文件源码
def make_context(self, ir, template, data):
        context = dict(template.form)
        context.update({
            'url': settings.SITE_URL + ir.get_absolute_url(),
        })
        context.update(data)
        return context
项目:django-project-template    作者:thorgate    | 项目源码 | 文件源码
def send_password_reset(user, uid, token):
    try:
        email_subject = _('{{cookiecutter.project_title}} password reset')
        confirm_reset_url = "%s%s" % (settings.SITE_URL,
                                      reverse('password_reset_confirm', kwargs={'uidb64': uid, 'token': token}))

        return send_email(user.email, email_subject, 'emails/password_reset.html', {
            'user': user,
            'confirm_reset_url': confirm_reset_url,
        })
    except Exception:
        logger.exception("Couldn't send password reset to %s (%d)", user.email, user.id)
项目:knowledge-base    作者:Axiacore    | 项目源码 | 文件源码
def post(self, request, *args, **kwargs):
        """ Sends the feedback email to admin.
        """
        obj = self.get_object()
        form = FeedbackForm(request.POST)
        if not form.is_valid():
            return render(request, 'app/article_detail.html', {
                'feedback_form': form,
                'object': obj,
                'already_voted': False,
                'display_form': True,
            })

        email = form.cleaned_data['email']
        email_message = EmailMessage(
            subject=_('New feedback from article {0}'.format(obj.name)),
            body=render_to_string('feedback_email.html', {
                'feedback_message': form.cleaned_data['description'],
                'feedback_email': email,
                'article': obj,
                'base_url': settings.SITE_URL,
            }),
            to=[settings.SUPPORT_EMAIL],
            reply_to=[email],
        )
        email_message.content_subtype = 'html'
        email_message.send()

        messages.success(
            request,
            _('Thank you for sending your feedback!')
        )
        return redirect(obj)
项目:tg-utils    作者:thorgate    | 项目源码 | 文件源码
def send_email(rcpt_email, email_subject, template_name, template_vars, from_email=None, html=True):
    logger.info("Sending %s to %s", template_name, rcpt_email)

    template_vars.update({
        'SITE_URL': settings.SITE_URL,
    })
    email_content = render_to_string(template_name, template_vars)

    # Send HTML-only email. Mandrill will automatically add the text variant.
    msg = EmailMessage(email_subject, email_content, from_email, [rcpt_email])

    if html:
        msg.content_subtype = "html"

    msg.send()
项目:telemetry-analysis-service    作者:mozilla    | 项目源码 | 文件源码
def add_site(apps, schema_editor):
    Site = apps.get_model('sites', 'Site')
    db_alias = schema_editor.connection.alias
    domain = urlparse(settings.SITE_URL)
    Site.objects.using(db_alias).get_or_create(
        id=settings.SITE_ID,
        defaults={'domain': domain.netloc, 'name': domain.netloc}
    )
项目:telemetry-analysis-service    作者:mozilla    | 项目源码 | 文件源码
def full_url(url):
    """
    A Django template filter to prepend the given URL path with the full
    site URL.
    """
    return urljoin(settings.SITE_URL, url)
项目:DjangoBlog    作者:liangliangyy    | 项目源码 | 文件源码
def load_breadcrumb(article):
    """
    ???????
    :param article:
    :return:
    """
    names = article.get_category_tree()

    names.append((settings.SITE_NAME, settings.SITE_URL))
    names = names[::-1]

    return {
        'names': names,
        'title': article.title
    }
项目:harnas    作者:harnasproject    | 项目源码 | 文件源码
def save_submit(request, contest_id):
    contest = Contest.objects.get(pk=contest_id)
    if request.method == 'POST':
        submit_form = SubmitForm(request.POST, request.FILES, contest=contest)
        print(str(request.FILES))
        if submit_form.is_valid():
            webhook_secret = _generate_webhook_secret()

            submit = Submit()
            submit.submitter = request.user
            submit.task = submit_form.cleaned_data['task']
            submit.solution = bytes(request.FILES['solution'].read())
            submit.webhook_secret = webhook_secret
            submit.save()

            template_id = submit.task.test_environment.template_name
            template = heraclient.Template(template_id)
            sandbox = heraclient.Sandbox(submit.id)
            webhook_url = 'http://' if settings.DEBUG else 'https://'
            host = request.get_host() if settings.DEBUG else settings.SITE_URL
            webhook_url += host
            webhook_url += reverse('checker_check', args=[submit.pk])

            sandbox.create(10,
                           template,
                           memory=512,
                           whole_node=False if settings.DEBUG else True,
                           async=True,
                           webhook_url=webhook_url,
                           webhook_secret=webhook_secret,
                           priority=None,
                           priority_growth=None)

            return HttpResponseRedirect(reverse('submit_details',
                                                args=[submit.pk]))
    return render(request, 'contest/contest_submit.html', {
        'submit_form': submit_form,
        'contest_id': contest_id,
    })
项目:djangocms-onepage-example    作者:thorgate    | 项目源码 | 文件源码
def send_password_reset(user, uid, token):
    try:
        email_subject = 'onepager password reset'
        confirm_reset_url = "%s%s" % (settings.SITE_URL,
                                      reverse('password_reset_confirm', kwargs={'uidb64': uid, 'token': token}))

        return send_email(user.email, email_subject, 'emails/password_reset.html', {
            'user': user,
            'confirm_reset_url': confirm_reset_url,
        })
    except:
        logger.exception("Couldn't send password reset to %s (%d)", user.email, user.id)
项目:zimfarm    作者:ZimboPy    | 项目源码 | 文件源码
def activate_user_email(self):
        activation_url = "%s%s" %(settings.SITE_URL, reverse("activation_view", args=[self.activation_key]))
        context = {"activation_key": self.activation_key, "activation_url": activation_url, "user": self.user.username}
        message = render_to_string("accounts/activation_message.txt", context)
        subject = "Activate your email"
        self.email_user(subject, message, settings.DEFAULT_FROM_EMAIL)
项目:money-to-prisoners-send-money    作者:ministryofjustice    | 项目源码 | 文件源码
def site_url(path):
    return urljoin(settings.SITE_URL, path)
项目:MagiCircles    作者:MagiCircles    | 项目源码 | 文件源码
def get_full_item_url(collection_name, instance):
    return u'{}{}/{}/{}/'.format(django_settings.SITE_URL, collection_name, instance.pk, tourldash(unicode(instance)))
项目:buildinfo.debian.net    作者:lamby    | 项目源码 | 文件源码
def api_source_version_architecture(request, name, version, architecture):
    source = get_object_or_404(Source, name=name)

    if not source.buildinfos.filter(version=version).exists():
        raise Http404()

    qs = Submission.objects.filter(
        buildinfo__version=version,
        buildinfo__source_id=source,
        buildinfo__architecture__name=architecture,
    ).select_related(
        'key',
        'buildinfo',
        'buildinfo__architecture',
        'buildinfo__source',
    ).only(
        'slug',
        'buildinfo__sha1',
        'buildinfo__version',
        'buildinfo__source__name',
        'buildinfo__architecture__name',
        'key__name',
        'key__uid',
        'created',
    ).order_by()

    if 'key__uid' in request.GET:
        qs = qs.filter(key__uid__in=request.GET.getlist('key__uid'))

    grouped = groupby(
        sorted(qs, key=lambda x: (x.buildinfo.sha1, x.created)),
        lambda x: x.buildinfo.sha1,
        lambda x: x.created,
    )

    by_sha1 = [
        {
            'uri': '{}{}'.format(
                settings.SITE_URL,
                xs[0].get_absolute_url(),
            ),
            'sha1': sha1,
            'submissions': [{
                'key': {
                    'uid': x.key.uid,
                    'name': x.key.name,
                },
                'created': x.created,
            } for x in xs],
        }
        for sha1, xs in grouped
    ]

    return JsonResponse({'by_sha1': by_sha1})