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


Python urlresolvers.get_script_prefix方法代码示例

本文整理汇总了Python中django.core.urlresolvers.get_script_prefix方法的典型用法代码示例。如果您正苦于以下问题:Python urlresolvers.get_script_prefix方法的具体用法?Python urlresolvers.get_script_prefix怎么用?Python urlresolvers.get_script_prefix使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在django.core.urlresolvers的用法示例。


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

示例1: to_internal_value

# 需要导入模块: from django.core import urlresolvers [as 别名]
# 或者: from django.core.urlresolvers import get_script_prefix [as 别名]
def to_internal_value(self, data):
        try:
            http_prefix = data.startswith(('http:', 'https:'))
        except AttributeError:
            self.fail('incorrect_type', data_type=type(data).__name__)

        if http_prefix:
            # If needed convert absolute URLs to relative path
            data = urlparse(data).path
            prefix = get_script_prefix()
            if data.startswith(prefix):
                data = '/' + data[len(prefix):]

        try:
            match = resolve(data)
        except Resolver404:
            self.fail('no_match')

        try:
            lookup_value = match.kwargs[self.lookup_url_kwarg]
            lookup_kwargs = {self.lookup_field: lookup_value}
            model = match.func.cls.model
            return model.objects.get(**lookup_kwargs)
        except (ObjectDoesNotExist, TypeError, ValueError):
            self.fail('does_not_exist') 
开发者ID:OpenAgricultureFoundation,项目名称:gro-api,代码行数:27,代码来源:serializers.py

示例2: get_canonical_path

# 需要导入模块: from django.core import urlresolvers [as 别名]
# 或者: from django.core.urlresolvers import get_script_prefix [as 别名]
def get_canonical_path(resource_key, pk=None):
        """
        Return canonical resource path.

        Arguments:
            resource_key - Canonical resource key
                           i.e. Serializer.get_resource_key().
            pk - (Optional) Object's primary key for a single-resource URL.
        Returns: Absolute URL as string.
        """

        if resource_key not in resource_map:
            # Note: Maybe raise?
            return None

        base_path = get_script_prefix() + resource_map[resource_key]['path']
        if pk:
            return '%s/%s/' % (base_path, pk)
        else:
            return base_path 
开发者ID:AltSchool,项目名称:dynamic-rest,代码行数:22,代码来源:routers.py

示例3: add_preserved_filters

# 需要导入模块: from django.core import urlresolvers [as 别名]
# 或者: from django.core.urlresolvers import get_script_prefix [as 别名]
def add_preserved_filters(context, url, popup=False, to_field=None):
    opts = context.get('opts')
    preserved_filters = context.get('preserved_filters')

    parsed_url = list(urlparse(url))
    parsed_qs = dict(parse_qsl(parsed_url[4]))
    merged_qs = dict()

    if opts and preserved_filters:
        preserved_filters = dict(parse_qsl(preserved_filters))

        match_url = '/%s' % url.partition(get_script_prefix())[2]
        try:
            match = resolve(match_url)
        except Resolver404:
            pass
        else:
            current_url = '%s:%s' % (match.app_name, match.url_name)
            changelist_url = 'admin:%s_%s_changelist' % (opts.app_label, opts.model_name)
            if changelist_url == current_url and '_changelist_filters' in preserved_filters:
                preserved_filters = dict(parse_qsl(preserved_filters['_changelist_filters']))

        merged_qs.update(preserved_filters)

    if popup:
        from django.contrib.admin.options import IS_POPUP_VAR
        merged_qs[IS_POPUP_VAR] = 1
    if to_field:
        from django.contrib.admin.options import TO_FIELD_VAR
        merged_qs[TO_FIELD_VAR] = to_field

    merged_qs.update(parsed_qs)

    parsed_url[4] = urlencode(merged_qs)
    return urlunparse(parsed_url) 
开发者ID:lanbing510,项目名称:GTDWeb,代码行数:37,代码来源:admin_urls.py

示例4: get_absolute_url

# 需要导入模块: from django.core import urlresolvers [as 别名]
# 或者: from django.core.urlresolvers import get_script_prefix [as 别名]
def get_absolute_url(self):
        # Handle script prefix manually because we bypass reverse()
        return iri_to_uri(get_script_prefix().rstrip('/') + self.url) 
开发者ID:lanbing510,项目名称:GTDWeb,代码行数:5,代码来源:models.py

示例5: __init__

# 需要导入模块: from django.core import urlresolvers [as 别名]
# 或者: from django.core.urlresolvers import get_script_prefix [as 别名]
def __init__(self, prefix):
        self.prefix = prefix
        self.old_prefix = get_script_prefix() 
开发者ID:drexly,项目名称:openhgsenti,代码行数:5,代码来源:utils.py

示例6: from_native

# 需要导入模块: from django.core import urlresolvers [as 别名]
# 或者: from django.core.urlresolvers import get_script_prefix [as 别名]
def from_native(self, value):
        # Convert URL -> model instance pk
        # TODO: Use values_list
        queryset = self.queryset
        if queryset is None:
            raise Exception('Writable related fields must include a `queryset` argument')

        try:
            http_prefix = value.startswith(('http:', 'https:'))
        except AttributeError:
            msg = self.error_messages['incorrect_type']
            raise ValidationError(msg % type(value).__name__)

        if http_prefix:
            # If needed convert absolute URLs to relative path
            value = urlparse.urlparse(value).path
            prefix = get_script_prefix()
            if value.startswith(prefix):
                value = '/' + value[len(prefix):]

        try:
            match = resolve(value)
        except Exception:
            raise ValidationError(self.error_messages['no_match'])

        if match.view_name != self.view_name:
            raise ValidationError(self.error_messages['incorrect_match'])

        try:
            return self.get_object(queryset, match.view_name,
                                   match.args, match.kwargs)
        except (ObjectDoesNotExist, TypeError, ValueError):
            raise ValidationError(self.error_messages['does_not_exist']) 
开发者ID:erigones,项目名称:esdc-ce,代码行数:35,代码来源:relations.py


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