示例#1
0
def url(regex, view, kwargs=None, name=None, prefix=''):
    from django.conf.urls import url as baseurl

    end_dollar = True
    if isinstance(view, tuple) and len(view) == 3:
        end_dollar = False

    return baseurl(MacroUrlPattern(regex, end_dollar=end_dollar), view, kwargs=kwargs, name=name, prefix=prefix)
示例#2
0
def url(regex, view, kwargs=None, name=None, prefix=''):
    from django.conf.urls import url as baseurl

    # Handle include()'s in views.
    end_dollar = True
    if isinstance(view, tuple) and len(view) == 3:
        end_dollar = False

    # Auto-calling as_view on CBVs objects. Now you can omit as_view() in your views by default.
    if isinstance(view, type):
        if hasattr(view, 'as_view') and hasattr(view.as_view, '__call__'):
            view = view.as_view()

    return baseurl(MacroUrlPattern(regex, end_dollar=end_dollar), view, kwargs=kwargs, name=name, prefix=prefix)
def url(regex, view, kwargs=None, name=None, prefix=''):
    from django.conf.urls import url as baseurl
    global DJANGO_VERSION

    if DJANGO_VERSION is None:
        from django import get_version

        DJANGO_VERSION = get_version()

    # Handle include()'s in views.
    end_dollar = True
    if isinstance(view, tuple) and len(view) == 3:
        end_dollar = False

    # Auto-calling as_view on CBVs objects. Now you can omit as_view() in your views by default.
    if isinstance(view, type):
        if hasattr(view, 'as_view') and hasattr(view.as_view, '__call__'):
            view = view.as_view()

    if prefix:
        warnings.warn(
            'Support for prefix in macrosurl.url() is deprecated and '
            'will be removed in version 0.4 (support for prefix was removed in Django 1.10). '
            'Please update your source code.'
            'In old Django versions prefix was used like "if prefix:view = prefix + \'.\' + view".'
        )

        view = prefix + '.' + view

    if DJANGO_VERSION >= StrictVersion('1.10') and not callable(
            view) and not isinstance(view, (list, tuple)):
        warnings.warn(
            'View "%s" must be a callable in case of Django 1.10. '
            'Macrosurl will try to load the view automatically (this behavior will be removed in version 0.4), but '
            'please update your source code.' % view)

        from django.utils.module_loading import import_string

        view = import_string(view)

    return baseurl(MacroUrlPattern(regex, end_dollar=end_dollar),
                   view,
                   kwargs=kwargs,
                   name=name)
示例#4
0
def url(regex, view, kwargs=None, name=None, prefix=''):
    return baseurl(MacroUrlPattern(regex), view, kwargs=kwargs, name=name, prefix=prefix)
示例#5
0
def url(regex, view, kwargs=None, name=None, prefix=''):
    return baseurl(MacroUrlPattern(regex),
                   view,
                   kwargs=kwargs,
                   name=name,
                   prefix=prefix)