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.

200 Examples 7

Example 1

Project: pinax-ratings
Source File: pinax_ratings_tags.py
View license
@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 2

Project: GAE-Bulk-Mailer
Source File: urls.py
View license
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 3

Project: GAE-Bulk-Mailer
Source File: utils.py
View license
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 4

Project: GAE-Bulk-Mailer
Source File: widgets.py
View license
    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 5

Project: django-object-tools
Source File: options.py
View license
    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 6

Project: PyClassLessons
Source File: urls.py
View license
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 7

Project: PyClassLessons
Source File: utils.py
View license
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 8

Project: PyClassLessons
Source File: widgets.py
View license
    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 9

Project: django-uni-form
Source File: uni_form_filters.py
View license
@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 10

Project: django-enhanced-cbv
Source File: utils.py
View license
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 11

Project: django-thumbor
Source File: __init__.py
View license
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 12

Project: django-pdfy
Source File: views.py
View license
    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 13

Project: roundware-server
Source File: forms.py
View license
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 14

Project: Django--an-app-at-a-time
Source File: urls.py
View license
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 15

Project: Django--an-app-at-a-time
Source File: utils.py
View license
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 16

View license
def static(request):
    """
    Adds static-related context variables to the context.

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

Example 17

View license
    @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 18

Project: shuup
Source File: plugins.py
View license
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 19

View license
def static(request):
    """
    Adds static-related context variables to the context.

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

Example 20

Project: splunk-webframework
Source File: basehttp.py
View license
    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 21

Project: splunk-webframework
Source File: widgets.py
View license
    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 22

Project: madewithwagtail
Source File: wagtail_hooks.py
View license
@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 23

Project: madewithwagtail
Source File: wagtail_hooks.py
View license
@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 24

Project: mezzanine
Source File: runserver.py
View license
    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, document_root=root)
                    except Http404:
                        # Just return the original 404 response.
                        pass
        return response

Example 25

Project: brigitte
Source File: views.py
View license
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 26

View license
    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 27

Project: tendenci
Source File: admin.py
View license
    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 28

Project: tendenci
Source File: admin.py
View license
    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 29

Project: tendenci
Source File: admin.py
View license
    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 30

Project: wagtail-blog-app
Source File: wagtail_hooks.py
View license
@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 31

Project: transifex
Source File: models.py
View license
    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 32

Project: transifex
Source File: views.py
View license
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 33

Project: ProjectNarwhal
Source File: tables.py
View license
    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 34

View license
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 35

Project: vegphilly.com
Source File: template_tags.py
View license
    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 36

View license
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)

Example 37

Project: nodewatcher
Source File: storage.py
View license
    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 38

Project: btb
Source File: favorites.py
View license
@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 39

Project: django-dockit
Source File: inlines.py
View license
    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 40

Project: colab
Source File: openid_tags.py
View license
@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 41

Project: cdr-stats
Source File: icons.py
View license
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 42

Project: cdr-stats
Source File: icons.py
View license
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 43

Project: cgstudiomap
Source File: urls.py
View license
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 44

Project: cgstudiomap
Source File: utils.py
View license
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 45

Project: cgstudiomap
Source File: widgets.py
View license
    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 46

Project: django-sellmo
Source File: links.py
View license
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 47

Project: django-sellmo
Source File: links.py
View license
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 48

View license
@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 49

View license
@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 50

Project: django-nonrel
Source File: context_processors.py
View license
def static(request):
    """
    Adds static-related context variables to the context.

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