django.conf.settings.STATIC_URL

Here are the examples of the python api django.conf.settings.STATIC_URL taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

157 Examples 7

Example 1

Project: django-sellmo Source File: links.py
def _get_context(**context):
    site = Site.objects.get_current()
    context.update({
        'settings': settings_manager,
        'request' : {
            'site' : site,
        },
        'url': 'http://{0}'.format(site.domain),
        'prefix': 'http://{0}'.format(site.domain),
        'STATIC_URL': 'http://{0}{1}'.format(site.domain, settings.STATIC_URL),
        'MEDIA_URL': 'http://{0}{1}'.format(site.domain, settings.MEDIA_URL),
    })

    return context

Example 2

Project: django-cms Source File: cms_admin.py
Function: admin_static_url
@register.simple_tag
def admin_static_url():
    """
    If set, returns the string contained in the setting ADMIN_MEDIA_PREFIX, otherwise returns STATIC_URL + 'admin/'.
    """
    return getattr(settings, 'ADMIN_MEDIA_PREFIX', None) or ''.join([settings.STATIC_URL, 'admin/'])

Example 3

Project: tendenci Source File: admin.py
Function: content_view
    def content_view(self, obj):
        link_icon = '%simages/icons/external_16x16.png' % settings.STATIC_URL
        link = '<a href="%s" title="%s"><img src="%s" alt="External 16x16" title="external 16x16" /></a>' % (
            obj.get_content_url(),
            obj,
            link_icon,
        )
        return link

Example 4

Project: colab Source File: openid_tags.py
Function: openid_icon
@register.simple_tag
def openid_icon(openid, user):
    oid = u"%s" % openid
    matches = [u.openid == oid for u in UserOpenidAssociation.objects.filter(user=user)]
    if any(matches):
        return mark_safe(u'<img src="%s" alt="%s" />' % (
            os.path.join(settings.STATIC_URL, "images", "openid-icon.png"),
            ugettext("Logged in with OpenID")
        ))
    else:
        return u""

Example 5

Project: transifex Source File: views.py
Function: server_error
def server_error(request, template_name='500.html'):
    """Always include STATIC_URL into the 500 error"""
    from django.http import HttpResponseServerError
    t = loader.get_template(template_name)
    return HttpResponseServerError(t.render(Context({
        'STATIC_URL': settings.STATIC_URL})))

Example 6

Project: mezzanine Source File: runserver.py
Function: get_response
    def get_response(self, request):
        response = super(MezzStaticFilesHandler, self).get_response(request)
        if response.status_code == 404:
            locations = (
                (settings.STATIC_URL, settings.STATIC_ROOT),
                (settings.MEDIA_URL, settings.MEDIA_ROOT),
            )
            for url, root in locations:
                if request.path.startswith(url):
                    path = request.path.replace(url, "", 1)
                    try:
                        return serve(request, path, docuement_root=root)
                    except Http404:
                        # Just return the original 404 response.
                        pass
        return response

Example 7

Project: django-nonrel Source File: widgets.py
Function: absolute_path
    def absolute_path(self, path, prefix=None):
        if path.startswith(u'http://') or path.startswith(u'https://') or path.startswith(u'/'):
            return path
        if prefix is None:
            if settings.STATIC_URL is None:
                 # backwards compatibility
                prefix = settings.MEDIA_URL
            else:
                prefix = settings.STATIC_URL
        return urljoin(prefix, path)

Example 8

Project: roundware-server Source File: forms.py
def get_formset_media_js():
    """
    """
    FORMSET_FULL = settings.STATIC_URL + 'js/jquery.formset.js'
    FORMSET_MINIFIED = settings.STATIC_URL + 'rw/js/jquery.formset.min.js'
    formset_js_path = FORMSET_FULL if settings.DEBUG else FORMSET_MINIFIED
    formset_media_js = (formset_js_path, )
    return formset_media_js

Example 9

Project: django-fluent-blogs Source File: abstractbase.py
    @classmethod
    def get_status_column(cls, entry):
        # Create a status column, is also reused by templatetags/fluent_blogs_admin_tags.py
        status = entry.status
        title = next(rec[1] for rec in AbstractEntryBase.STATUSES if rec[0] == status)
        icon  = next(rec[1] for rec in cls.STATUS_ICONS if rec[0] == status)
        return u'<img src="{static_url}{icon}" alt="{title}" title="{title}" />'.format(
            static_url=settings.STATIC_URL, icon=icon, title=title)

Example 10

Project: Django--an-app-at-a-time Source File: context_processors.py
Function: static
def static(request):
    """
    Adds static-related context variables to the context.

    """
    return {'STATIC_URL': settings.STATIC_URL}

Example 11

Project: btb Source File: favorites.py
Function: favorites
@register.simple_tag(takes_context=True)
def favorites(context, model, user=None):
    user = user or context['user']
    has_favorited = user.is_authenticated() and \
            model.favorite_set.filter(user=user).exists()
    return render_to_string("comments/_favorites.html", {
        'thing': model,
        'STATIC_URL': settings.STATIC_URL,
        'num_favorites': model.favorite_set.count(),
        'has_favorited': has_favorited,
        'user': user,
    })

Example 12

Project: vegphilly.com Source File: vegancity_template_tags.py
def graphical_rating(rating):
    rating_icons = ('<img class="rating" src="' +
                    settings.STATIC_URL +
                    'images/rating-solid.png">') * rating
    rating_icons += ('<img class="rating" src="' +
                     settings.STATIC_URL +
                     'images/rating-faded.png">') * (4 - rating)
    return rating_icons

Example 13

Project: madewithwagtail Source File: wagtail_hooks.py
Function: editor_css
@hooks.register('insert_editor_css')
def editor_css():
    """
    Add extra CSS files to the admin
    """
    css_files = [
        'wagtailadmin/css/admin.css',
    ]

    css_includes = format_html_join(
        '\n', '<link rel="stylesheet" href="{0}{1}">', ((settings.STATIC_URL, filename) for filename in css_files))

    return css_includes

Example 14

Project: cdr-stats Source File: icons.py
Function: listicon
def listicon(icon_name):
    """Tag is used to pass icon style in link

    >>> listicon('eye')
    'style="text-decoration:none;list-style-image:url(/static/cdr-stats/icons/test.png);"'
    """
    return 'style="text-decoration:none;list-style-image:url(%scdr-stats/icons/%s.png);"'\
           % (settings.STATIC_URL, icon_name)

Example 15

Project: django-thumbor Source File: __init__.py
def _prepend_static_url(url):
    if conf.THUMBOR_STATIC_ENABLED and url.startswith(settings.STATIC_URL):
        url = _remove_prefix(url, settings.STATIC_URL)
        url.lstrip('/')
        return '%s/%s' % (conf.THUMBOR_STATIC_URL, url)
    return url

Example 16

Project: wagtail-cookiecutter-foundation Source File: wagtail_hooks.py
Function: editor_js
@hooks.register('insert_editor_js')
def editor_js():
    # Add extra JS files to the admin
    js_files = [
        'js/hallo-custom.js',
    ]
    js_includes = format_html_join(
        '\n', '<script src="{0}{1}"></script>',
        ((settings.STATIC_URL, filename) for filename in js_files)
    )

    return js_includes + format_html(
        """
        <script>
            registerHalloPlugin('blockquotebutton');
            registerHalloPlugin('blockquotebuttonwithclass');
        </script>
        """
    )

Example 17

Project: djangocodemirror Source File: djangocodemirror_tags.py
    def render_asset_html(self, path, tag_template):
        """
        Render HTML tag for a given path.

        Arguments:
            path (string): Relative path from static directory.
            tag_template (string): Template string for HTML tag.

        Returns:
            string: HTML tag with url from given path.
        """
        url = os.path.join(settings.STATIC_URL, path)

        return tag_template.format(url=url)

Example 18

Project: tapiriik Source File: email.py
def generate_message_from_template(template, context):
	context["STATIC_URL"] = settings.STATIC_URL
	# Mandrill is set up to inline the CSS and generate a plaintext copy.
	html_message = get_template(template).render(Context(context)).strip()
	context["plaintext"] = True
	plaintext_message = get_template(template).render(Context(context)).strip()
	return html_message, plaintext_message

Example 19

Project: django-object-tools Source File: options.py
Function: media
    def media(self, form):
        """
        Collects admin and form media.
        """
        js = ['admin/js/core.js', 'admin/js/admin/RelatedObjectLookups.js',
              'admin/js/jquery.min.js', 'admin/js/jquery.init.js']

        media = forms.Media(
            js=['%s%s' % (settings.STATIC_URL, u) for u in js],
        )

        if form:
            for name, field in form.fields.iteritems():
                media = media + field.widget.media

        return media

Example 20

Project: django-cumulus Source File: context_processors.py
def static_cdn_url(request):
    """
    A context processor that exposes the full static CDN URL
    as static URL in templates.
    """
    cdn_url, ssl_url = _get_container_urls(CumulusStaticStorage())
    static_url = settings.STATIC_URL

    return {
        "STATIC_URL": cdn_url + static_url,
        "STATIC_SSL_URL": ssl_url + static_url,
        "LOCAL_STATIC_URL": static_url,
    }

Example 21

Project: wagtail-blog-app Source File: wagtail_hooks.py
Function: editor_css
@hooks.register('insert_editor_css')
def editor_css():
    css_files = [
        'global/font-awesome/css/font-awesome.css',
        'global/css/wagtail-admin.css',
    ]

    css_includes = format_html_join(
        '\n',
        '<link rel="stylesheet" href="{0}{1}">',
        ((settings.STATIC_URL, filename) for filename in css_files)
    )

    return css_includes

Example 22

Project: transifex Source File: models.py
Function: get_logo_url
    def get_logo_url(self):
        """
        Returns the image containing the mugshot for the user.

        The mugshot can be a uploaded image or a Gravatar.

        :return:
            ``None`` when no default image is supplied by ``PROJECT_LOGO_DEFAULT``.
        """
        # First check for a uploaded logo image and if any return that.
        if self.logo:
            return self.logo.url
        # Check for a default image.
        elif getattr(settings, 'PROJECT_LOGO_DEFAULT', None):
            return os.path.join(settings.STATIC_URL, settings.PROJECT_LOGO_DEFAULT)
        else:
            return None

Example 23

Project: PyClassLessons Source File: widgets.py
Function: absolute_path
    def absolute_path(self, path, prefix=None):
        if path.startswith(('http://', 'https://', '/')):
            return path
        if prefix is None:
            if settings.STATIC_URL is None:
                # backwards compatibility
                prefix = settings.MEDIA_URL
            else:
                prefix = settings.STATIC_URL
        return urljoin(prefix, path)

Example 24

Project: ProjectNarwhal Source File: tables.py
Function: init
    def __init__(self, *args, **kwargs):
        image = kwargs.pop('image')
        if not image: raise ImproperlyConfigured
        super(ImageHeadColumn, self).__init__(*args, **kwargs)
        self.header = mark_safe('<img src="%s" alt="%s">'
                        %(settings.STATIC_URL+image, self.header))

Example 25

Project: django-systemjs Source File: test_templatetags.py
    @override_settings(SYSTEMJS_ENABLED=True, SYSTEMJS_OUTPUT_DIR='SJ')
    def test_script_tag_attributes(self):
        template = """{% load system_tags %}{% systemjs_import 'myapp/main' async foo="bar" %}"""
        template = django_engine.from_string(template)
        rendered = template.render(self.context)
        expected_url = urljoin(settings.STATIC_URL, 'SJ/myapp/main.js')
        self.assertHTMLEqual(
            rendered,
            """<script async foo="bar" type="text/javascript" src="{0}"></script>""".format(expected_url)
        )

Example 26

Project: nodewatcher Source File: storage.py
Function: init
    def __init__(self):
        self.fontname = 'nodewatcher'
        self.cssprefix = 'nw'
        self.cssname = 'icons.css'

        self.fontpath = 'frontend/fonts'
        self.csspath = 'frontend/css'
        self.fonturl = settings.STATIC_URL + 'frontend/fonts/'

Example 27

Project: vegphilly.com Source File: template_tags.py
    def test_graphical_rating(self):
        rating = 3
        img_class_src = '<img class="rating" src="' + settings.STATIC_URL
        result_markup = ''.join((
            img_class_src + 'images/rating-solid.png">',
            img_class_src + 'images/rating-solid.png">',
            img_class_src + 'images/rating-solid.png">',
            img_class_src + 'images/rating-faded.png">'
            ))

        self.assertEqual(graphical_rating(rating), result_markup)

Example 28

Project: splunk-webframework Source File: basehttp.py
    def __init__(self, *args, **kwargs):
        from django.conf import settings
        self.admin_static_prefix = urljoin(settings.STATIC_URL, 'admin/')
        # We set self.path to avoid crashes in log_message() on unsupported
        # requests (like "OPTIONS").
        self.path = ''
        self.style = color_style()
        super(WSGIRequestHandler, self).__init__(*args, **kwargs)

Example 29

Project: django-dockit Source File: inlines.py
    def _media(self):
        from django.conf import settings
        js = ['js/jquery.min.js', 'js/jquery.init.js', 'js/inlines.min.js']
        if self.prepopulated_fields:
            js.append('js/urlify.js')
            js.append('js/prepopulate.min.js')
        if self.filter_vertical or self.filter_horizontal:
            js.extend(['js/SelectBox.js' , 'js/SelectFilter2.js'])
        media = forms.Media(js=['%s%s' % (getattr(settings, 'ADMIN_MEDIA_PREFIX', 'admin'), url) for url in js])
        media.add_js(['%sadmin/js/primitivelist.js' % settings.STATIC_URL])
        media.add_css({'all': ['%sadmin/css/primitivelist.css' % settings.STATIC_URL]})
        return media

Example 30

Project: django-enhanced-cbv Source File: utils.py
Function: fetch_resources
def fetch_resources(uri, rel):
    """
    Callback to allow pisa/reportlab to retrieve Images,Stylesheets, etc.
    `uri` is the href attribute from the html link element.
    `rel` gives a relative path, but it's not used here.
    """
    if settings.STATIC_URL in uri:
        path = os.path.join(settings.STATIC_ROOT, uri.replace(settings.STATIC_URL, ""))
    else:
        path = os.path.join(settings.MEDIA_ROOT, uri.replace(settings.MEDIA_URL, ""))
    return path

Example 31

Project: cdr-stats Source File: icons.py
Function: icon
def icon(icon_name):
    """Tag is used to create icon link

    >>> icon('test')
    'class="icon" style="text-decoration:none;background-image:url(/static/cdr-stats/icons/test.png);"'
    """
    return 'class="icon" style="text-decoration:none;background-image:url(%scdr-stats/icons/%s.png);"'\
        % (settings.STATIC_URL, icon_name)

Example 32

Project: madewithwagtail Source File: wagtail_hooks.py
Function: editor_js
@hooks.register('insert_editor_js')
def editor_js():
    """
    Add extra JS files to the admin
    """
    js_files = [
        'wagtailadmin/js/vendor/jquery.htmlClean.min.js',
        'wagtailadmin/js/vendor/rangy-selectionsaverestore.js',
    ]
    js_includes = format_html_join(
        '\n', '<script src="{0}{1}"></script>', ((settings.STATIC_URL, filename) for filename in js_files))

    return js_includes + """<script type="text/javascript">

Example 33

Project: cgstudiomap Source File: utils.py
Function: check_settings
def check_settings(base_url=None):
    """
    Checks if the staticfiles settings have sane values.
    """
    if base_url is None:
        base_url = settings.STATIC_URL
    if not base_url:
        raise ImproperlyConfigured(
            "You're using the staticfiles app "
            "without having set the required STATIC_URL setting.")
    if settings.MEDIA_URL == base_url:
        raise ImproperlyConfigured("The MEDIA_URL and STATIC_URL "
                                   "settings must have different values")
    if ((settings.MEDIA_ROOT and settings.STATIC_ROOT) and
            (settings.MEDIA_ROOT == settings.STATIC_ROOT)):
        raise ImproperlyConfigured("The MEDIA_ROOT and STATIC_ROOT "
                                   "settings must have different values")

Example 34

Project: GAE-Bulk-Mailer Source File: widgets.py
Function: absolute_path
    def absolute_path(self, path, prefix=None):
        if path.startswith(('http://', 'https://', '/')):
            return path
        if prefix is None:
            if settings.STATIC_URL is None:
                 # backwards compatibility
                prefix = settings.MEDIA_URL
            else:
                prefix = settings.STATIC_URL
        return urljoin(prefix, path)

Example 35

Project: django-sellmo Source File: links.py
Function: get_context
def _get_context(**context):
    site = Site.objects.get_current()
    context.update({
        'settings': settings_manager
        'request' : {
            'site' : site,
        },
        'url': 'http://{0}'.format(site.domain),
        'prefix': 'http://{0}'.format(site.domain),
        'STATIC_URL': 'http://{0}{1}'.format(site.domain, settings.STATIC_URL),
        'MEDIA_URL': 'http://{0}{1}'.format(site.domain, settings.MEDIA_URL),
    })

    return context

Example 36

Project: brigitte Source File: views.py
Function: server_error
def server_error(request, template_name='500.html'):
    """ needed for rendering 500 pages with style. """
    t = loader.get_template(template_name)
    return http.HttpResponseServerError(t.render(Context({
        'request': request,
        'STATIC_URL': settings.STATIC_URL,
    })))

Example 37

Project: wagtail-cookiecutter-foundation Source File: wagtail_hooks.py
Function: editor_css
@hooks.register('insert_editor_css')
def editor_css():
    # Add extra CSS files to the admin like font-awesome
    css_files = [
        'libs/font-awesome/css/font-awesome.min.css'
    ]

    css_includes = format_html_join(
        '\n', '<link rel="stylesheet" href="{0}{1}">',
        ((settings.STATIC_URL, filename) for filename in css_files)
    )

    return css_includes

Example 38

Project: django-pdfy Source File: views.py
Function: render_to_response
    def render_to_response(self, context, **response_kwargs):
        context.update(response_kwargs)
        context.update({
            "STATIC_URL": settings.STATIC_URL,
            "MEDIA_URL": settings.MEDIA_URL,
        })
        logger.debug(context)
        return HttpResponse(self.render_to_pdf(context), mimetype='application/pdf')

Example 39

Project: Adlibre-DMS Source File: feedback_tags.py
Function: feedback
@register.inclusion_tag("feedback_form/form.html")
def feedback():
    """
    Sets context variable field given as a parameter to tag.
    """
    form = forms.FeedbackForm()
    return {
        'feedback_form': form,
        'STATIC_URL': settings.STATIC_URL
    }

Example 40

Project: tendenci Source File: admin.py
    def rendered_view(self, obj):
        link_icon = '%simages/icons/external_16x16.png' % settings.STATIC_URL
        link = '<a href="%s" title="%s"><img src="%s" alt="External 16x16" title="external 16x16" /></a>' % (
            obj.get_absolute_url(),
            obj,
            link_icon,
        )
        return link

Example 41

Project: django-crocodile Source File: crocodile.py
    def _get_local_file(self, filename):

        stripped_filename = filename.replace(settings.STATIC_URL, "").replace(settings.MEDIA_URL, "")

        r = FileSystemFinder().find(stripped_filename)

        if not r:
            r = AppDirectoriesFinder().find(stripped_filename)

        if not r:
            logging.warn("[django-crocodile] File not found: %s" % filename)
            return ""

        return open(r).read().decode("utf-8", "replace") + "\n"

Example 42

Project: GAE-Bulk-Mailer Source File: urls.py
Function: staticfiles_urlpatterns
def staticfiles_urlpatterns(prefix=None):
    """
    Helper function to return a URL pattern for serving static files.
    """
    if prefix is None:
        prefix = settings.STATIC_URL
    return static(prefix, view='django.contrib.staticfiles.views.serve')

Example 43

Project: django-cumulus Source File: context_processors.py
def cdn_url(request):
    """
    A context processor that exposes the full CDN URL in templates.
    """
    cdn_url, ssl_url = _get_container_urls(CumulusStorage())
    static_url = settings.STATIC_URL

    return {
        "CDN_URL": cdn_url + static_url,
        "CDN_SSL_URL": ssl_url + static_url,
    }

Example 44

Project: tendenci Source File: admin.py
Function: view_on_site
    def view_on_site(self, obj):
        link_icon = '%simages/icons/external_16x16.png' % settings.STATIC_URL
        link = '<a href="%s" title="%s"><img src="%s" alt="%s" title="%s" /></a>' % (
            reverse('page', args=[obj.slug]),
            obj.title,
            link_icon,
            obj.title,
            obj.title
        )
        return link

Example 45

Project: Django--an-app-at-a-time Source File: urls.py
Function: staticfiles_urlpatterns
def staticfiles_urlpatterns(prefix=None):
    """
    Helper function to return a URL pattern for serving static files.
    """
    if prefix is None:
        prefix = settings.STATIC_URL
    return static(prefix, view=serve)

Example 46

Project: pinax-ratings Source File: pinax_ratings_tags.py
@register.inclusion_tag("pinax/ratings/_script.html")
def user_rating_js(user, obj, category=None):
    post_url = rating_post_url(user, obj)
    rating = user_rating_value(user, obj, category)

    return {
        "obj": obj,
        "post_url": post_url,
        "category": category,
        "the_user_rating": rating,
        "STATIC_URL": settings.STATIC_URL,
    }

Example 47

Project: GAE-Bulk-Mailer Source File: utils.py
Function: check_settings
def check_settings(base_url=None):
    """
    Checks if the staticfiles settings have sane values.

    """
    if base_url is None:
        base_url = settings.STATIC_URL
    if not base_url:
        raise ImproperlyConfigured(
            "You're using the staticfiles app "
            "without having set the required STATIC_URL setting.")
    if settings.MEDIA_URL == base_url:
        raise ImproperlyConfigured("The MEDIA_URL and STATIC_URL "
                                   "settings must have different values")
    if ((settings.MEDIA_ROOT and settings.STATIC_ROOT) and
            (settings.MEDIA_ROOT == settings.STATIC_ROOT)):
        raise ImproperlyConfigured("The MEDIA_ROOT and STATIC_ROOT "
                                   "settings must have different values")

Example 48

Project: django-uni-form Source File: uni_form_filters.py
@register.inclusion_tag("uni_form/includes.html", takes_context=True)
def uni_form_setup(context):
    """
    Creates the `<style>` and `<script>` tags needed to initialize uni-form.

    You can create a local uni-form/includes.html template if you want to customize how
    these files are loaded.
    
    Only works with Django 1.3+
    """
    if 'STATIC_URL' not in context:
        context['STATIC_URL'] = settings.STATIC_URL
    return (context)

Example 49

Project: shuup Source File: plugins.py
def add_resources(context, content):
    view_class = getattr(context["view"], "__class__", None) if context.get("view") else None
    if not view_class:
        return
    view_name = getattr(view_class, "__name__", "")
    if view_name == "ProductDetailView":
        add_resource(context, "body_end", "%sshuup/recently_viewed_products/lib.js" % settings.STATIC_URL)

Example 50

Project: kubernetes_django_postgres_redis Source File: views.py
Function: index
def index(request):
    """ Updates the visited count and provides the static URL to build the main
     landing page.
    """
    logging.info("in the index view")
    visited = __update_visited()
    context = {
                 "STATIC_URL": settings.STATIC_URL,
                 "visited": visited
               }
    return render(request, 'index.html', context)
See More Examples - Go to Next Page
Page 1 Selected Page 2 Page 3 Page 4