
from django import template
from django.core import urlresolvers

from ..utils import get_app_instance


register = template.Library()


@register.simple_tag(takes_context=True)
def namespace_url(context, view_name, *args, **kwargs):
    """
    Returns an absolute URL matching given view with its parameters.
    """

    namespace, config = get_app_instance(context['request'])
    if not 'current_app' in kwargs:
        kwargs['current_app'] = namespace

    return urlresolvers.reverse('%s:%s' % (config.namespace, view_name),
                                args=args,
                                kwargs=kwargs)


from django import template
from django.core import urlresolvers

from ..utils import get_app_instance


register = template.Library()


@register.simple_tag(takes_context=True)
def namespace_url(context, view_name, *args, **kwargs):
    """
    Returns an absolute URL matching given view with its parameters.
    """

    namespace, config = get_app_instance(context['request'])
    if not 'current_app' in kwargs:
        kwargs['current_app'] = namespace

    return urlresolvers.reverse(
        '{0:s}:{1:s}'.format(config.namespace, view_name),
        args=args,
        kwargs=kwargs)

Use string.format for performance reasons
Use string.format for performance reasons

  
  from django import template
  from django.core import urlresolvers
  
  from ..utils import get_app_instance
  
  
  register = template.Library()
  
  
  @register.simple_tag(takes_context=True)
  def namespace_url(context, view_name, *args, **kwargs):
      """
      Returns an absolute URL matching given view with its parameters.
      """
  
      namespace, config = get_app_instance(context['request'])
      if not 'current_app' in kwargs:
          kwargs['current_app'] = namespace
  
-     return urlresolvers.reverse('%s:%s' % (config.namespace, view_name),
-                                 args=args,
-                                 kwargs=kwargs)
+     return urlresolvers.reverse(
+         '{0:s}:{1:s}'.format(config.namespace, view_name),
+         args=args,
+         kwargs=kwargs)
  
Use string.format for performance reasons
## Code Before:

from django import template
from django.core import urlresolvers

from ..utils import get_app_instance


register = template.Library()


@register.simple_tag(takes_context=True)
def namespace_url(context, view_name, *args, **kwargs):
    """
    Returns an absolute URL matching given view with its parameters.
    """

    namespace, config = get_app_instance(context['request'])
    if not 'current_app' in kwargs:
        kwargs['current_app'] = namespace

    return urlresolvers.reverse('%s:%s' % (config.namespace, view_name),
                                args=args,
                                kwargs=kwargs)

## Instruction:
Use string.format for performance reasons
## Code After:

from django import template
from django.core import urlresolvers

from ..utils import get_app_instance


register = template.Library()


@register.simple_tag(takes_context=True)
def namespace_url(context, view_name, *args, **kwargs):
    """
    Returns an absolute URL matching given view with its parameters.
    """

    namespace, config = get_app_instance(context['request'])
    if not 'current_app' in kwargs:
        kwargs['current_app'] = namespace

    return urlresolvers.reverse(
        '{0:s}:{1:s}'.format(config.namespace, view_name),
        args=args,
        kwargs=kwargs)
