当前位置: 首页>>代码示例>>Python>>正文


Python staticfiles_storage.url函数代码示例

本文整理汇总了Python中staticfiles.storage.staticfiles_storage.url函数的典型用法代码示例。如果您正苦于以下问题:Python url函数的具体用法?Python url怎么用?Python url使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了url函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: replace_static_url

    def replace_static_url(original, prefix, quote, rest):
        """
        Replace a single matched url.
        """
        # Don't mess with things that end in '?raw'
        if rest.endswith('?raw'):
            return original

        # In debug mode, if we can find the url as is,
        if settings.DEBUG and finders.find(rest, True):
            return original
        # if we're running with a MongoBacked store course_namespace is not None, then use studio style urls
        elif (not static_asset_path) \
                and course_id \
                and modulestore().get_modulestore_type(course_id) != ModuleStoreEnum.Type.xml:
            # first look in the static file pipeline and see if we are trying to reference
            # a piece of static content which is in the edx-platform repo (e.g. JS associated with an xmodule)

            exists_in_staticfiles_storage = False
            try:
                exists_in_staticfiles_storage = staticfiles_storage.exists(rest)
            except Exception as err:
                log.warning("staticfiles_storage couldn't find path {0}: {1}".format(
                    rest, str(err)))

            if exists_in_staticfiles_storage:
                url = staticfiles_storage.url(rest)
            else:
                # if not, then assume it's courseware specific content and then look in the
                # Mongo-backed database
                url = StaticContent.convert_legacy_static_url_with_course_id(rest, course_id)

                if AssetLocator.CANONICAL_NAMESPACE in url:
                    url = url.replace('[email protected]', 'block/', 1)

        # Otherwise, look the file up in staticfiles_storage, and append the data directory if needed
        else:
            course_path = "/".join((static_asset_path or data_directory, rest))

            try:
                if staticfiles_storage.exists(rest):
                    url = staticfiles_storage.url(rest)
                else:
                    url = staticfiles_storage.url(course_path)
            # And if that fails, assume that it's course content, and add manually data directory
            except Exception as err:
                log.warning("staticfiles_storage couldn't find path {0}: {1}".format(
                    rest, str(err)))
                url = "".join([prefix, course_path])

        return "".join([quote, url, quote])
开发者ID:189140879,项目名称:edx-platform,代码行数:51,代码来源:__init__.py

示例2: replace_static_url

    def replace_static_url(match):
        original = match.group(0)
        prefix = match.group("prefix")
        quote = match.group("quote")
        rest = match.group("rest")

        # Don't mess with things that end in '?raw'
        if rest.endswith("?raw"):
            return original

        # In debug mode, if we can find the url as is,
        if settings.DEBUG and finders.find(rest, True):
            return original
        # if we're running with a MongoBacked store course_namespace is not None, then use studio style urls
        elif (
            (not static_asset_path)
            and course_id
            and modulestore().get_modulestore_type(course_id) != XML_MODULESTORE_TYPE
        ):
            # first look in the static file pipeline and see if we are trying to reference
            # a piece of static content which is in the edx-platform repo (e.g. JS associated with an xmodule)

            exists_in_staticfiles_storage = False
            try:
                exists_in_staticfiles_storage = staticfiles_storage.exists(rest)
            except Exception as err:
                log.warning("staticfiles_storage couldn't find path {0}: {1}".format(rest, str(err)))

            if exists_in_staticfiles_storage:
                url = staticfiles_storage.url(rest)
            else:
                # if not, then assume it's courseware specific content and then look in the
                # Mongo-backed database
                url = StaticContent.convert_legacy_static_url_with_course_id(rest, course_id)
        # Otherwise, look the file up in staticfiles_storage, and append the data directory if needed
        else:
            course_path = "/".join((static_asset_path or data_directory, rest))

            try:
                if staticfiles_storage.exists(rest):
                    url = staticfiles_storage.url(rest)
                else:
                    url = staticfiles_storage.url(course_path)
            # And if that fails, assume that it's course content, and add manually data directory
            except Exception as err:
                log.warning("staticfiles_storage couldn't find path {0}: {1}".format(rest, str(err)))
                url = "".join([prefix, course_path])

        return "".join([quote, url, quote])
开发者ID:XiaodunServerGroup,项目名称:medicalmooc,代码行数:49,代码来源:__init__.py

示例3: render_js

 def render_js(self, package, path):
     template_name = package.template_name or "pipeline/js.html"
     context = package.extra_context
     context.update({
         'url': staticfiles_storage.url(path)
     })
     return render_to_string(template_name, context)
开发者ID:trapeze,项目名称:django-pipeline,代码行数:7,代码来源:compressed.py

示例4: render_js

 def render_js(self, package, path):
     template_name = package.template_name or "pipeline/js.html"
     context = package.extra_context
     context.update({
         'type': guess_type(path, 'text/javascript'),
         'url': staticfiles_storage.url(path)
     })
     return render_to_string(template_name, context)
开发者ID:Nivl,项目名称:django-pipeline,代码行数:8,代码来源:compressed.py

示例5: replace_static_url

    def replace_static_url(match):
        original = match.group(0)
        prefix = match.group('prefix')
        quote = match.group('quote')
        rest = match.group('rest')

        # Don't mess with things that end in '?raw'
        if rest.endswith('?raw'):
            return original

        # In debug mode, if we can find the url as is,
        if settings.DEBUG and finders.find(rest, True):
            return original
        # if we're running with a MongoBacked store course_namespace is not
        # None, then use studio style urls
        elif course_namespace is not None and not isinstance(modulestore(), XMLModuleStore):
            # first look in the static file pipeline and see if we are trying to reference
            # a piece of static content which is in the mitx repo (e.g. JS
            # associated with an xmodule)
            if staticfiles_storage.exists(rest):
                url = staticfiles_storage.url(rest)
            else:
                # if not, then assume it's courseware specific content and then look in the
                # Mongo-backed database
                url = StaticContent.convert_legacy_static_url(
                    rest, course_namespace)
        # Otherwise, look the file up in staticfiles_storage, and append the
        # data directory if needed
        else:
            course_path = "/".join((data_directory, rest))

            try:
                if staticfiles_storage.exists(rest):
                    url = staticfiles_storage.url(rest)
                else:
                    url = staticfiles_storage.url(course_path)
            # And if that fails, assume that it's course content, and add
            # manually data directory
            except Exception as err:
                log.warning("staticfiles_storage couldn't find path {0}: {1}".format(
                    rest, str(err)))
                url = "".join([prefix, course_path])

        return "".join([quote, url, quote])
开发者ID:hughdbrown,项目名称:edx-platform,代码行数:44,代码来源:__init__.py

示例6: get

    def get(self, request, course_id, usage_id):
        """Display the view for face photo submission.

        Args:
            request(HttpRequest): HttpRequest object
            course_id(str): A string of course id
            usage_id(str): Location of Reverification XBlock in courseware

        Returns:
            HttpResponse
        """
        # Check that in-course re-verification is enabled or not
        incourse_reverify_enabled = InCourseReverificationConfiguration.current().enabled

        if not incourse_reverify_enabled:
            log.error(
                u"In-course reverification is not enabled.  "
                u"You can enable it in Django admin by setting "
                u"InCourseReverificationConfiguration to enabled."
            )
            raise Http404

        user = request.user
        course_key = CourseKey.from_string(course_id)
        course = modulestore().get_course(course_key)
        if course is None:
            log.error(u"Could not find course '%s' for in-course reverification.", course_key)
            raise Http404

        checkpoint = VerificationCheckpoint.get_verification_checkpoint(course_key, usage_id)
        if checkpoint is None:
            log.error(
                u"No verification checkpoint exists for the "
                u"course '%s' and checkpoint location '%s'.",
                course_key, usage_id
            )
            raise Http404

        initial_verification = SoftwareSecurePhotoVerification.get_initial_verification(user)
        if not initial_verification:
            return self._redirect_no_initial_verification(user, course_key)

        # emit the reverification event
        self._track_reverification_events(
            EVENT_NAME_USER_ENTERED_INCOURSE_REVERIFY_VIEW, user.id, course_id, checkpoint.checkpoint_name
        )

        context = {
            'course_key': unicode(course_key),
            'course_name': course.display_name_with_default,
            'checkpoint_name': checkpoint.checkpoint_name,
            'platform_name': settings.PLATFORM_NAME,
            'usage_id': usage_id,
            'capture_sound': staticfiles_storage.url("audio/camera_capture.wav"),
        }
        return render_to_response("verify_student/incourse_reverify.html", context)
开发者ID:inares,项目名称:edx-platform,代码行数:56,代码来源:views.py

示例7: get_xmodule_urls

def get_xmodule_urls():
    """
    Returns a list of the URLs to hit to grab all the XModule JS
    """
    if settings.DEBUG:
        paths = [path.replace(".coffee", ".js") for path in
                 settings.PIPELINE_JS['module-js']['source_filenames']]
    else:
        paths = [settings.PIPELINE_JS['module-js']['output_filename']]
    return [staticfiles_storage.url(path) for path in paths]
开发者ID:CEIT-UQ,项目名称:edx-platform,代码行数:10,代码来源:views.py

示例8: static_url

def static_url(path):
    """
    Take a static file path and return the correct URL.

    Simple wrapper around staticfiles.storage.staticfiles_storage.
    """
    try:
        return staticfiles_storage.url(path)
    except ValueError:
        # URL couldn't be found.  Let's just return the path.
        return path
开发者ID:BetterAlamance,项目名称:localwiki,代码行数:11,代码来源:utils.py

示例9: try_staticfiles_lookup

def try_staticfiles_lookup(path):
    """
    Try to lookup a path in staticfiles_storage.  If it fails, return
    a dead link instead of raising an exception.
    """
    try:
        url = staticfiles_storage.url(path)
    except Exception as err:
        log.warning("staticfiles_storage couldn't find path {0}: {1}".format(path, str(err)))
        # Just return the original path; don't kill everything.
        url = path
    return url
开发者ID:GeertHa,项目名称:edx-platform,代码行数:12,代码来源:__init__.py

示例10: _absolute_url_staticfile

def _absolute_url_staticfile(is_secure, name):
    """Construct an absolute URL back to a static resource on the site.

    Arguments:
        is_secure (bool): If true, use HTTPS as the protocol.
        name (unicode): The name of the static resource to retrieve.

    Returns:
        unicode

    """
    url_path = staticfiles_storage.url(name)
    return _absolute_url(is_secure, url_path)
开发者ID:ISCLC,项目名称:edx-platform-for-isc,代码行数:13,代码来源:api.py

示例11: get_logo_url

def get_logo_url():
    """
    Return the url for the branded logo image to be used
    """

    # if the MicrositeConfiguration has a value for the logo_image_url
    # let's use that
    image_url = microsite.get_value('logo_image_url')
    if image_url:
        return '{static_url}{image_url}'.format(
            static_url=settings.STATIC_URL,
            image_url=image_url
        )

    # otherwise, use the legacy means to configure this
    university = microsite.get_value('university')

    if university is None and settings.FEATURES.get('IS_EDX_DOMAIN', False):
        return staticfiles_storage.url('images/edx-theme/edx-logo-77x36.png')
    elif university:
        return staticfiles_storage.url('images/{uni}-on-edx-logo.png'.format(uni=university))
    else:
        return staticfiles_storage.url('images/logo.png')
开发者ID:4eek,项目名称:edx-platform,代码行数:23,代码来源:__init__.py

示例12: render

    def render(self, path):
        """Render the HTML tag."""
        if not self.package.template_name:
            template_name = {"js": "pipeline/js.jinja", "css": "pipeline/css.jinja"}[self.package_type]
        else:
            template_name = self.package.template_name

        mimetype = {"js": "text/javascript", "css": "text/css"}[self.package_type]

        context = self.package.extra_context
        context.update({"type": guess_type(path, mimetype), "url": staticfiles_storage.url(path)})

        env = Environment(loader=self.loader)
        tpl = env.get_template(template_name)
        return tpl.render(**context)
开发者ID:hyperoslo,项目名称:django-pipeline,代码行数:15,代码来源:ext.py

示例13: render_url

def render_url(context, file):
    __M_caller = context.caller_stack._push_frame()
    try:
        __M_writer = context.writer()
        # SOURCE LINE 6

        try:
            url = staticfiles_storage.url(file)
        except:
            url = file

        # SOURCE LINE 11
        __M_writer(filters.decode.utf8(url))
        return ""
    finally:
        context.caller_stack._pop_frame()
开发者ID:EduPepperPDTesting,项目名称:pepper2013-testing,代码行数:16,代码来源:static_content.html.py

示例14: get

    def get(self, request):
        """
        Render the reverification flow.

        Most of the work is done client-side by composing the same
        Backbone views used in the initial verification flow.
        """
        status, _ = SoftwareSecurePhotoVerification.user_status(request.user)
        if status in ["must_reverify", "expired"]:
            context = {
                "user_full_name": request.user.profile.name,
                "platform_name": microsite.get_value("platform_name", settings.PLATFORM_NAME),
                "capture_sound": staticfiles_storage.url("audio/camera_capture.wav"),
            }
            return render_to_response("verify_student/reverify.html", context)
        else:
            context = {"status": status}
            return render_to_response("verify_student/reverify_not_allowed.html", context)
开发者ID:Velody,项目名称:edunext-platform,代码行数:18,代码来源:views.py

示例15: _absolute_url_staticfile

def _absolute_url_staticfile(is_secure, name):
    """Construct an absolute URL to a static resource on the site.

    Arguments:
        is_secure (bool): If true, use HTTPS as the protocol.
        name (unicode): The name of the static resource to retrieve.

    Returns:
        unicode

    """
    url_path = staticfiles_storage.url(name)

    # In production, the static files URL will be an absolute
    # URL pointing to a CDN.  If this happens, we can just
    # return the URL.
    if urlparse.urlparse(url_path).netloc:
        return url_path

    # For local development, the returned URL will be relative,
    # so we need to make it absolute.
    return _absolute_url(is_secure, url_path)
开发者ID:rhndg,项目名称:openedx,代码行数:22,代码来源:api.py


注:本文中的staticfiles.storage.staticfiles_storage.url函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。