Python django.contrib.staticfiles.templatetags.staticfiles 模块,static() 实例源码

我们从Python开源项目中,提取了以下50个代码示例,用于说明如何使用django.contrib.staticfiles.templatetags.staticfiles.static()

项目:planet-b-saleor    作者:planet-b    | 项目源码 | 文件源码
def get_thumbnail(instance, size, method='crop'):
    size_name = '%s__%s' % (method, size)
    if instance:
        if (size_name not in AVAILABLE_SIZES and not
                settings.VERSATILEIMAGEFIELD_SETTINGS['create_images_on_demand']):
            msg = ('Thumbnail size %s is not defined in settings '
                   'and it won\'t be generated automatically' % size_name)
            warnings.warn(msg)
        try:
            if method == 'crop':
                thumbnail = instance.crop[size]
            else:
                thumbnail = instance.thumbnail[size]
        except:
            logger.exception('Thumbnail fetch failed',
                             extra={'instance': instance, 'size': size})
        else:
            return thumbnail.url
    return static(choose_placeholder(size))
项目:django-mako    作者:ahmedaljazzar    | 项目源码 | 文件源码
def render(self, context=None, request=None):
        """
        Render the template with a given context. Here we're adding
        some context variables that are required for all templates in
        the system like the statix url and the CSRF tokens, etc.

        :param context: It must be a dict if provided
        :param request: It must be a django.http.HttpRequest if provided
        :return: A rendered template
        """
        if context is None:
            context = {}

        if request is not None:
            # As Django doesn't have a global request object,
            # it's useful to put it in the context.
            context['request'] = request
            # Passing the CSRF token is mandatory.
            context['csrf_input'] = csrf_input_lazy(request)
            context['csrf_token'] = csrf_token_lazy(request)

            context['static'] = static
            context['url'] = reverse

        return self.template.render(**context)
项目:django-chartwerk    作者:DallasMorningNews    | 项目源码 | 文件源码
def get_context_data(self, **kwargs):
        context = super(ChartIconMixin, self).get_context_data(**kwargs)

        # Get all the template icons and them in a dict we can use as a
        # lookup
        icons = Template.objects.defer('data')
        icon_lookup = {i.title: i.icon for i in icons}

        default_icon = static('chartwerk/img/chartwerk_100.png')

        for chart in context[self.context_object_name]:
            tpl_title = chart.data['template']['title']

            # If the chart template isn't found or it's icon field is null,
            # use default
            if not icon_lookup.get(tpl_title):
                chart.icon = default_icon
            else:
                chart.icon = icon_lookup[tpl_title].url

        return context
项目:django-chartwerk    作者:DallasMorningNews    | 项目源码 | 文件源码
def render_static_string(url):
    """Render static strings.

    Opens dependency files and renders them into a string for injection
    or returns the url string.
    """
    try:
        return {
            'script': urlopen(url).read().decode('UTF-8'),
            'inject': True
        }
    except:
        return {
            'url': url,
            'inject': False
        }
项目:covart-web    作者:cyliang    | 项目源码 | 文件源码
def send_postponed(self, meeting, postponed_date, reason):
        text = "There will be *no* group meeting next week (%A, %b %d, %Y)"
        text = postponed_date.strftime(text) + ("%s.\n" % reason.lower())
        text += "The next group meeting has been postponed to "
        text += meeting.date.strftime("%A, %b %d, %Y. ")
        text += "Presenters will be %s." % get_text_list(
            map(unicode, meeting.presenters.all()), 'and'
        )

        attachments = [{
            "fallback": "Go %s for detail." % _url(meeting.get_absolute_url()),
            "actions": [{
                "type": "button",
                "text": "Detail",
                "url": _url(meeting.get_absolute_url()),
            }]
        }]

        return unicode(self("chat.postMessage",
            text=text,
            attachments=attachments,
            icon_url=_url(static('slack/presentation.png')),
            username='Meeting Bot',
        ))
项目:omb-eregs    作者:18F    | 项目源码 | 文件源码
def rawlayout_pdf(request, pdf):
    doc = to_doc(as_path(pdf))

    script_params = {
        'pdfPath': reverse('raw_pdf', kwargs={'pdf': pdf}),
        'workerSrc': static('ombpdf/js/pdf.worker.bundle.js'),
    }

    html, ctx = rawlayout.to_html(doc)

    return render(request, 'ombpdf/rawlayout.html', {
        'doc': doc,
        'html': SafeString(html),
        'script_params': SafeString(json.dumps(script_params)),
        **ctx,
    })
项目:TeleGiphy    作者:JessicaNgo    | 项目源码 | 文件源码
def gameplay_context(game, token):
    if game.current_round > 1:
        # gif from last player
        received_gif = game.gameround_set.get(round_number=game.current_round - 1).giphy_url
    else:
        # if roundnumber of game is 1 (first turn)
        received_gif = ""
    try:
        game_round = game.gameround_set.get(round_number=game.current_round)
        gif = game_round.giphy_url
        phrase = game_round.user_text
    # no phrase has been entered by the player yet
    except:
        gif = static('img/giphy_static.gif')
        phrase = ""

    context = {
        'token': token,
        'game': game,
        'gif': gif,
        'phrase': phrase,
        'received_gif': received_gif
    }
    return context


# Creates context for multiplayer games
项目:ecs_sclm    作者:meaningful    | 项目源码 | 文件源码
def icons(self):
        r = {}
        if getattr(self, '_icon', False):
            for size in FILER_ADMIN_ICON_SIZES:
                try:
                    r[size] = static("filer/icons/%s_%sx%s.png" % (
                        self._icon, size, size))
                except ValueError:
                    # Do not raise an exception while trying to call static()
                    # on non-existent icon file. This avoids the issue with
                    # rendering parts of the template as empty blocks that
                    # happens on an attempt to access object 'icons' attribute
                    # in template.
                    pass
        return r
项目:CodingDojo    作者:ComputerSocietyUNB    | 项目源码 | 文件源码
def static(path):
    global _static
    if _static is None:
        if apps.is_installed('django.contrib.staticfiles'):
            from django.contrib.staticfiles.templatetags.staticfiles import static as _static
        else:
            from django.templatetags.static import static as _static
    return _static(path)
项目:planet-b-saleor    作者:planet-b    | 项目源码 | 文件源码
def test_get_thumbnail_no_instance(monkeypatch):
    """When no instance, function should return placeholder"""
    monkeypatch.setattr(
        'saleor.product.templatetags.product_images.choose_placeholder',
        lambda x: 'placeholder')
    output = get_thumbnail(instance=None, size='10x10', method='crop')
    assert output == static('placeholder')
项目:dream_blog    作者:fanlion    | 项目源码 | 文件源码
def xstatic(*tags):
    from .vendors import vendors
    node = vendors

    fs = []
    lang = get_language()

    cls_str = str if six.PY3 else basestring
    for tag in tags:
        try:
            for p in tag.split('.'):
                node = node[p]
        except Exception as e:
            if tag.startswith('xadmin'):
                file_type = tag.split('.')[-1]
                if file_type in ('css', 'js'):
                    node = "xadmin/%s/%s" % (file_type, tag)
                else:
                    raise e
            else:
                raise e

        if isinstance(node, cls_str):
            files = node
        else:
            mode = 'dev'
            if not settings.DEBUG:
                mode = getattr(settings, 'STATIC_USE_CDN',
                               False) and 'cdn' or 'production'

            if mode == 'cdn' and mode not in node:
                mode = 'production'
            if mode == 'production' and mode not in node:
                mode = 'dev'
            files = node[mode]

        files = type(files) in (list, tuple) and files or [files, ]
        fs.extend([f % {'lang': lang.replace('_', '-')} for f in files])

    return [f.startswith('http://') and f or static(f) for f in fs]
项目:MxOnline    作者:myTeemo    | 项目源码 | 文件源码
def xstatic(*tags):
    from vendors import vendors
    node = vendors

    fs = []
    lang = get_language()

    for tag in tags:
        try:
            for p in tag.split('.'):
                node = node[p]
        except Exception, e:
            if tag.startswith('xadmin'):
                file_type = tag.split('.')[-1]
                if file_type in ('css', 'js'):
                    node = "xadmin/%s/%s" % (file_type, tag)
                else:
                    raise e
            else:
                raise e

        if type(node) in (str, unicode):
            files = node
        else:
            mode = 'dev'
            if not settings.DEBUG:
                mode = getattr(settings, 'STATIC_USE_CDN',
                               False) and 'cdn' or 'production'

            if mode == 'cdn' and mode not in node:
                mode = 'production'
            if mode == 'production' and mode not in node:
                mode = 'dev'
            files = node[mode]

        files = type(files) in (list, tuple) and files or [files, ]
        fs.extend([f % {'lang': lang.replace('_', '-')} for f in files])

    return [f.startswith('http://') and f or static(f) for f in fs]
项目:micromasters    作者:mitodl    | 项目源码 | 文件源码
def public_path(request):
    """
    Return the correct public_path for Webpack to use
    """
    if settings.USE_WEBPACK_DEV_SERVER:
        return ensure_trailing_slash(webpack_dev_server_url(request))
    else:
        return ensure_trailing_slash(static("bundles/"))
项目:djangoblog    作者:liuhuipy    | 项目源码 | 文件源码
def xstatic(*tags):
    from .vendors import vendors
    node = vendors

    fs = []
    lang = get_language()

    cls_str = str if six.PY3 else basestring
    for tag in tags:
        try:
            for p in tag.split('.'):
                node = node[p]
        except Exception as e:
            if tag.startswith('xadmin'):
                file_type = tag.split('.')[-1]
                if file_type in ('css', 'js'):
                    node = "xadmin/%s/%s" % (file_type, tag)
                else:
                    raise e
            else:
                raise e

        if isinstance(node, cls_str):
            files = node
        else:
            mode = 'dev'
            if not settings.DEBUG:
                mode = getattr(settings, 'STATIC_USE_CDN',
                               False) and 'cdn' or 'production'

            if mode == 'cdn' and mode not in node:
                mode = 'production'
            if mode == 'production' and mode not in node:
                mode = 'dev'
            files = node[mode]

        files = type(files) in (list, tuple) and files or [files, ]
        fs.extend([f % {'lang': lang.replace('_', '-')} for f in files])

    return [f.startswith('http://') and f or static(f) for f in fs]
项目:pyconapac-2016    作者:pythonkr    | 项目源码 | 文件源码
def get_image_url(self):
        if self.image:
            return self.image.url

        return static('image/anonymous.png')
项目:wagtailcloudinary    作者:dteskera    | 项目源码 | 文件源码
def global_admin_css():
    return format_html('<link rel="stylesheet" href="{}">', static('wagtailcloudinary/css/main.css'))
项目:wagtailcloudinary    作者:dteskera    | 项目源码 | 文件源码
def global_admin_js():
    html = []
    scripts = [
        static('wagtailcloudinary/js/csrf-token.js'),
        static('js/jquery.ui.widget.js'),
        static('js/jquery.iframe-transport.js'),
        static('js/jquery.fileupload.js'),
    ]
    for item in scripts:
        html.append('<script src="{}"></script>'.format(item))
    return format_html(''.join(html))
项目:sdining    作者:Lurance    | 项目源码 | 文件源码
def xstatic(*tags):
    from .vendors import vendors
    node = vendors

    fs = []
    lang = get_language()

    cls_str = str if six.PY3 else basestring
    for tag in tags:
        try:
            for p in tag.split('.'):
                node = node[p]
        except Exception as e:
            if tag.startswith('xadmin'):
                file_type = tag.split('.')[-1]
                if file_type in ('css', 'js'):
                    node = "xadmin/%s/%s" % (file_type, tag)
                else:
                    raise e
            else:
                raise e

        if isinstance(node, cls_str):
            files = node
        else:
            mode = 'dev'
            if not settings.DEBUG:
                mode = getattr(settings, 'STATIC_USE_CDN',
                               False) and 'cdn' or 'production'

            if mode == 'cdn' and mode not in node:
                mode = 'production'
            if mode == 'production' and mode not in node:
                mode = 'dev'
            files = node[mode]

        files = type(files) in (list, tuple) and files or [files, ]
        fs.extend([f % {'lang': lang.replace('_', '-')} for f in files])

    return [f.startswith('http://') and f or static(f) for f in fs]
项目:bbgo    作者:genonfire    | 项目源码 | 文件源码
def toggle_bookmark(request):
    """API toggle_bookmark"""
    if request.method == 'POST':
        app = request.POST['app']
        id = request.POST['id']
        app_id = app + '-' + id
        profile = request.user.profile
        bookmarks = profile.bookmarks.split(',')

        if app_id not in bookmarks:
            if len(bookmarks) > settings.MAX_BOOKMARKS:
                return JsonResponse({'status': 'false'}, status=400)

            if profile.bookmarks != '':
                profile.bookmarks += ","
            profile.bookmarks += app_id
            data = static('icons/stared28.png')
        else:
            regstr = re.escape(app_id) + r"\b(,|)"
            profile.bookmarks = re.sub(regstr, '', profile.bookmarks)
            if profile.bookmarks and profile.bookmarks[-1] == ',':
                profile.bookmarks = profile.bookmarks[:-1]
            data = static('icons/star28.png')

        request.user.profile.save()
        return JsonResponse([data], safe=False, status=201)

    return error_page(request)
项目:wagtailblocks_cards    作者:alexgleason    | 项目源码 | 文件源码
def media(self):
        parent_media = super(CardsBlock, self).media
        cards_css = {
            'screen': (static('wagtailblocks_cards/css/wagtailblocks_cards.css'),)
        }
        cards_media = forms.Media(css=cards_css)
        return parent_media + cards_media
项目:djangocms-association    作者:python-spain    | 项目源码 | 文件源码
def icon_path(self):
        return static('cms_contact/src/img/{}.png'.format(self.type.lower()))
项目:LannistersPy    作者:dorukgezici    | 项目源码 | 文件源码
def get_image_url(self):
        if not self.image:
            return static("img/itugnu.png")
        else:
            return self.image.url
项目:LannistersPy    作者:dorukgezici    | 项目源码 | 文件源码
def get_image_url(self):
        if not self.image:
            return static("img/itugnu.png")
        else:
            return self.image.url
项目:DjangoBlog    作者:0daybug    | 项目源码 | 文件源码
def static(path):
    global _static
    if _static is None:
        if apps.is_installed('django.contrib.staticfiles'):
            from django.contrib.staticfiles.templatetags.staticfiles import static as _static
        else:
            from django.templatetags.static import static as _static
    return _static(path)
项目:RealEstate    作者:Mich0232    | 项目源码 | 文件源码
def get_advert_thumbnail(advert):
    """
        Takes Advert object and returns thumbnail image, if no thumbnail - returns first image
        if no image at all returns 'no-photo.jpg'
    """
    photos = advert.images.all()
    if photos:
        for photo in photos:
            if photo.thumbnail:
                return photo.image.url
        return photos[0].image.url
    return static('img/no-photo.jpg')
项目:xadmin-markdown-editor    作者:bluenknight    | 项目源码 | 文件源码
def xstatic(*tags):
    from vendors import vendors
    node = vendors

    fs = []
    lang = get_language()

    for tag in tags:
        try:
            for p in tag.split('.'):
                node = node[p]
        except Exception, e:
            if tag.startswith('xadmin'):
                file_type = tag.split('.')[-1]
                if file_type in ('css', 'js'):
                    node = "xadmin/%s/%s" % (file_type, tag)
                else:
                    raise e
            else:
                raise e

        if type(node) in (str, unicode):
            files = node
        else:
            mode = 'dev'
            if not settings.DEBUG:
                mode = getattr(settings, 'STATIC_USE_CDN',
                               False) and 'cdn' or 'production'

            if mode == 'cdn' and mode not in node:
                mode = 'production'
            if mode == 'production' and mode not in node:
                mode = 'dev'
            files = node[mode]

        files = type(files) in (list, tuple) and files or [files, ]
        fs.extend([f % {'lang': lang.replace('_', '-')} for f in files])

    return [f.startswith('http://') and f or static(f) for f in fs]
项目:heltour    作者:cyanfish    | 项目源码 | 文件源码
def valid(self, obj):
        if obj.validation_warning == True:
            return '<img src="%s">' % static('admin/img/icon-alert.svg')
        elif obj.validation_ok == True:
            return '<img src="%s">' % static('admin/img/icon-yes.svg')
        elif obj.validation_ok == False:
            return '<img src="%s">' % static('admin/img/icon-no.svg')
        return ''
项目:wanblog    作者:wanzifa    | 项目源码 | 文件源码
def static(path):
    global _static
    if _static is None:
        if apps.is_installed('django.contrib.staticfiles'):
            from django.contrib.staticfiles.templatetags.staticfiles import static as _static
        else:
            from django.templatetags.static import static as _static
    return _static(path)
项目:tabmaster    作者:NicolasMinghetti    | 项目源码 | 文件源码
def static(path):
    global _static
    if _static is None:
        if apps.is_installed('django.contrib.staticfiles'):
            from django.contrib.staticfiles.templatetags.staticfiles import static as _static
        else:
            from django.templatetags.static import static as _static
    return _static(path)
项目:trydjango18    作者:lucifer-yqh    | 项目源码 | 文件源码
def static(path):
    global _static
    if _static is None:
        if apps.is_installed('django.contrib.staticfiles'):
            from django.contrib.staticfiles.templatetags.staticfiles import static as _static
        else:
            from django.templatetags.static import static as _static
    return _static(path)
项目:wagtailblocks_tabs    作者:alexgleason    | 项目源码 | 文件源码
def media(self):
        return forms.Media(
            js=[
                static('wagtailadmin/js/blocks/sequence.js'), static('wagtailadmin/js/blocks/list.js'),
                static('wagtailblocks_tabs/js/tabs.js')
            ]
        )
项目:trydjango18    作者:wei0104    | 项目源码 | 文件源码
def static(path):
    global _static
    if _static is None:
        if apps.is_installed('django.contrib.staticfiles'):
            from django.contrib.staticfiles.templatetags.staticfiles import static as _static
        else:
            from django.templatetags.static import static as _static
    return _static(path)
项目:django-chartwerk    作者:DallasMorningNews    | 项目源码 | 文件源码
def render_local_static(static_file):
    """Render local static file to string to inject into template."""
    return urlopen(
        os.path.join(
            app_settings.DOMAIN,
            static(static_file)[1:]
        )
    ).read().decode('UTF-8')
项目:odl-video-service    作者:mitodl    | 项目源码 | 文件源码
def public_path(request):
    """
    Return the correct public_path for Webpack to use
    """
    if settings.USE_WEBPACK_DEV_SERVER:
        return ensure_trailing_slash(webpack_dev_server_url(request))
    return ensure_trailing_slash(static("bundles/"))
项目:covart-web    作者:cyliang    | 项目源码 | 文件源码
def get_picture_url(self):
        if self.picture:
            return self.picture.url
        return static('website/unknown-person.png')
项目:django-monkeys    作者:andrew-gardner    | 项目源码 | 文件源码
def dieInstructionsView(request, dieName):
    """
    A view that simply displays the instructions image and instruction text
    for the given Die.
    """
    dieObject = Die.objects.filter(name=dieName)[0]
    instructions = dieObject.instructions

    # Find all the instances of images in our special markup [[[IMAGE_NAME (WIDTH HEIGHT)]]]
    m = re.finditer(r'\[\[\[(.*?)\]\]\]', instructions)
    for foundMatch in m:
        noBrackets = foundMatch.group(0).replace("[", "").replace("]", "")
        splitData = noBrackets.split()
        imageName = splitData[0]
        if len(splitData) > 1:
            imageWidth = int(splitData[1])
            imageHeight = int(splitData[2])
        imageObject = dieObject.instructionsimage_set.filter(Q(name=imageName))
        imageUrl = staticfiles.static(imageObject[0].image.url)
        if len(splitData) > 1:
            refText = """<img src="%s" width=%d height=%d>""" % (imageUrl, imageWidth, imageHeight)
        else:
            refText = """<img src="%s">""" % (imageUrl)
        instructions = instructions.replace(foundMatch.group(0), refText)

    # Copy the instructions back to a local die object (no database write)
    dieObject.instructions = instructions
    context = {
                  'die' : dieObject
              }
    return render(request, 'typer/instructions.html', context)
项目:eduDjango    作者:yuzhou6    | 项目源码 | 文件源码
def xstatic(*tags):
    from vendors import vendors
    node = vendors

    fs = []
    lang = get_language()

    for tag in tags:
        try:
            for p in tag.split('.'):
                node = node[p]
        except Exception, e:
            if tag.startswith('xadmin'):
                file_type = tag.split('.')[-1]
                if file_type in ('css', 'js'):
                    node = "xadmin/%s/%s" % (file_type, tag)
                else:
                    raise e
            else:
                raise e

        if type(node) in (str, unicode):
            files = node
        else:
            mode = 'dev'
            if not settings.DEBUG:
                mode = getattr(settings, 'STATIC_USE_CDN',
                               False) and 'cdn' or 'production'

            if mode == 'cdn' and mode not in node:
                mode = 'production'
            if mode == 'production' and mode not in node:
                mode = 'dev'
            files = node[mode]

        files = type(files) in (list, tuple) and files or [files, ]
        fs.extend([f % {'lang': lang.replace('_', '-')} for f in files])

    return [f.startswith('http://') and f or static(f) for f in fs]
项目:srvup-comments    作者:srvup    | 项目源码 | 文件源码
def get_image(self, obj):
        img_  = static("comments/img/user.png")
        # if obj.user.profile.image:
            # img_ = obj.user.profile.image
        return img_
项目:srvup-comments    作者:srvup    | 项目源码 | 文件源码
def get_image(self, obj):
        img_  = static("comments/img/user.png")
        # if obj.user.profile.image:
            # img_ = obj.user.profile.image
        return img_
项目:Django-IMOOC-Shop    作者:LBruse    | 项目源码 | 文件源码
def xstatic(*tags):
    from vendors import vendors
    node = vendors

    fs = []
    lang = get_language()

    for tag in tags:
        try:
            for p in tag.split('.'):
                node = node[p]
        except Exception, e:
            if tag.startswith('xadmin'):
                file_type = tag.split('.')[-1]
                if file_type in ('css', 'js'):
                    node = "xadmin/%s/%s" % (file_type, tag)
                else:
                    raise e
            else:
                raise e

        if type(node) in (str, unicode):
            files = node
        else:
            mode = 'dev'
            if not settings.DEBUG:
                mode = getattr(settings, 'STATIC_USE_CDN',
                               False) and 'cdn' or 'production'

            if mode == 'cdn' and mode not in node:
                mode = 'production'
            if mode == 'production' and mode not in node:
                mode = 'dev'
            files = node[mode]

        files = type(files) in (list, tuple) and files or [files, ]
        fs.extend([f % {'lang': lang.replace('_', '-')} for f in files])

    return [f.startswith('http://') and f or static(f) for f in fs]
项目:StudyOnline    作者:yipwinghong    | 项目源码 | 文件源码
def xstatic(*tags):
    from vendors import vendors
    node = vendors

    fs = []
    lang = get_language()

    for tag in tags:
        try:
            for p in tag.split('.'):
                node = node[p]
        except Exception, e:
            if tag.startswith('xadmin'):
                file_type = tag.split('.')[-1]
                if file_type in ('css', 'js'):
                    node = "xadmin/%s/%s" % (file_type, tag)
                else:
                    raise e
            else:
                raise e

        if type(node) in (str, unicode):
            files = node
        else:
            mode = 'dev'
            if not settings.DEBUG:
                mode = getattr(settings, 'STATIC_USE_CDN',
                               False) and 'cdn' or 'production'

            if mode == 'cdn' and mode not in node:
                mode = 'production'
            if mode == 'production' and mode not in node:
                mode = 'dev'
            files = node[mode]

        files = type(files) in (list, tuple) and files or [files, ]
        fs.extend([f % {'lang': lang.replace('_', '-')} for f in files])

    return [f.startswith('http://') and f or static(f) for f in fs]
项目:gougo    作者:amaozhao    | 项目源码 | 文件源码
def icons(self):
        r = {}
        if getattr(self, '_icon', False):
            for size in FILER_ADMIN_ICON_SIZES:
                try:
                    r[size] = static("filer/icons/%s_%sx%s.png" % (
                        self._icon, size, size))
                except ValueError:
                    # Do not raise an exception while trying to call static()
                    # on non-existent icon file. This avoids the issue with
                    # rendering parts of the template as empty blocks that
                    # happens on an attempt to access object 'icons' attribute
                    # in template.
                    pass
        return r
项目:deb-python-django-compressor    作者:openstack    | 项目源码 | 文件源码
def url_for(mod, filename):
    """
    Incomplete emulation of Flask's url_for.
    """
    from django.contrib.staticfiles.templatetags import staticfiles

    if mod == "static":
        return staticfiles.static(filename)

    return ""
项目:xadmin_python3    作者:mahongquan    | 项目源码 | 文件源码
def xstatic(*tags):
    from .vendors import vendors
    node = vendors

    fs = []
    lang = get_language()

    for tag in tags:
        try:
            for p in tag.split('.'):
                node = node[p]
        except Exception as e:
            if tag.startswith('xadmin'):
                file_type = tag.split('.')[-1]
                if file_type in ('css', 'js'):
                    node = "xadmin/%s/%s" % (file_type, tag)
                else:
                    raise e
            else:
                raise e

        if type(node) in (str, str):
            files = node
        else:
            mode = 'dev'
            if not settings.DEBUG:
                mode = getattr(settings, 'STATIC_USE_CDN',
                               False) and 'cdn' or 'production'

            if mode == 'cdn' and mode not in node:
                mode = 'production'
            if mode == 'production' and mode not in node:
                mode = 'dev'
            files = node[mode]

        files = type(files) in (list, tuple) and files or [files, ]
        fs.extend([f % {'lang': lang.replace('_', '-')} for f in files])

    return [f.startswith('http://') and f or static(f) for f in fs]
项目:logo-gen    作者:jellene4eva    | 项目源码 | 文件源码
def static(path):
    global _static
    if _static is None:
        if apps.is_installed('django.contrib.staticfiles'):
            from django.contrib.staticfiles.templatetags.staticfiles import static as _static
        else:
            from django.templatetags.static import static as _static
    return _static(path)
项目:gmail_scanner    作者:brandonhub    | 项目源码 | 文件源码
def static(path):
    global _static
    if _static is None:
        if apps.is_installed('django.contrib.staticfiles'):
            from django.contrib.staticfiles.templatetags.staticfiles import static as _static
        else:
            from django.templatetags.static import static as _static
    return _static(path)
项目:djanoDoc    作者:JustinChavez    | 项目源码 | 文件源码
def static(path):
    global _static
    if _static is None:
        if apps.is_installed('django.contrib.staticfiles'):
            from django.contrib.staticfiles.templatetags.staticfiles import static as _static
        else:
            from django.templatetags.static import static as _static
    return _static(path)
项目:Django-shop    作者:poetries    | 项目源码 | 文件源码
def xstatic(*tags):
    from .vendors import vendors
    node = vendors

    fs = []
    lang = get_language()

    cls_str = str if six.PY3 else basestring
    for tag in tags:
        try:
            for p in tag.split('.'):
                node = node[p]
        except Exception as e:
            if tag.startswith('xadmin'):
                file_type = tag.split('.')[-1]
                if file_type in ('css', 'js'):
                    node = "xadmin/%s/%s" % (file_type, tag)
                else:
                    raise e
            else:
                raise e

        if isinstance(node, cls_str):
            files = node
        else:
            mode = 'dev'
            if not settings.DEBUG:
                mode = getattr(settings, 'STATIC_USE_CDN',
                               False) and 'cdn' or 'production'

            if mode == 'cdn' and mode not in node:
                mode = 'production'
            if mode == 'production' and mode not in node:
                mode = 'dev'
            files = node[mode]

        files = type(files) in (list, tuple) and files or [files, ]
        fs.extend([f % {'lang': lang.replace('_', '-')} for f in files])

    return [f.startswith('http://') and f or static(f) for f in fs]
项目:pyconkr-2017    作者:pythonkr    | 项目源码 | 文件源码
def get_image_url(self):
        if self.image:
            return self.image.url

        return static('image/anonymous.png')
项目:wagtailtrans    作者:LUKKIEN    | 项目源码 | 文件源码
def global_admin_js():
        return format_html(
            '<script type="text/javascript" src="{path}"></script>'.format(
                path=static('wagtailtrans/js/site_languages_editor.js'))
        )