
from django.conf.urls import url


class UrlsIndex(object):
    """
    Simple helper class for centralizing url patterns of a Django
    web application.

    Derived classes should override the 'scope' class attribute otherwise
    all declared patterns will be grouped under the default one.
    """

    urlpatterns = {}
    scope = 'default'

    @classmethod
    def add_url_pattern(cls, url_pattern, view, view_name):
        """
        Class method that adds an url pattern to the current scope.

        Args:
            url_pattern: regex describing a Django url
            view: function implementing the Django view
            view_name: name of the view used to reverse the url
        """
        if cls.scope not in cls.urlpatterns:
            cls.urlpatterns[cls.scope] = []
        cls.urlpatterns[cls.scope].append(url(url_pattern, view,
                                              name=view_name))

    @classmethod
    def get_url_patterns(cls):
        """
        Class method that returns the list of url pattern associated to
        the current scope.

        Returns:
            The list of url patterns associated to the current scope
        """
        return cls.urlpatterns[cls.scope]


from django.conf.urls import url


class UrlsIndex(object):
    """
    Simple helper class for centralizing url patterns of a Django
    web application.

    Derived classes should override the 'scope' class attribute otherwise
    all declared patterns will be grouped under the default one.
    """

    urlpatterns = {}
    scope = 'default'

    @classmethod
    def add_url_pattern(cls, url_pattern, view, view_name):
        """
        Class method that adds an url pattern to the current scope.

        Args:
            url_pattern: regex describing a Django url
            view: function implementing the Django view
            view_name: name of the view used to reverse the url
        """
        if cls.scope not in cls.urlpatterns:
            cls.urlpatterns[cls.scope] = []
        if view_name:
            cls.urlpatterns[cls.scope].append(url(url_pattern, view,
                                                  name=view_name))
        else:
            cls.urlpatterns[cls.scope].append(url(url_pattern, view))

    @classmethod
    def get_url_patterns(cls):
        """
        Class method that returns the list of url pattern associated to
        the current scope.

        Returns:
            The list of url patterns associated to the current scope
        """
        return cls.urlpatterns[cls.scope]

Allow to register unnamed django views
common: Allow to register unnamed django views

  
  from django.conf.urls import url
  
  
  class UrlsIndex(object):
      """
      Simple helper class for centralizing url patterns of a Django
      web application.
  
      Derived classes should override the 'scope' class attribute otherwise
      all declared patterns will be grouped under the default one.
      """
  
      urlpatterns = {}
      scope = 'default'
  
      @classmethod
      def add_url_pattern(cls, url_pattern, view, view_name):
          """
          Class method that adds an url pattern to the current scope.
  
          Args:
              url_pattern: regex describing a Django url
              view: function implementing the Django view
              view_name: name of the view used to reverse the url
          """
          if cls.scope not in cls.urlpatterns:
              cls.urlpatterns[cls.scope] = []
+         if view_name:
-         cls.urlpatterns[cls.scope].append(url(url_pattern, view,
+             cls.urlpatterns[cls.scope].append(url(url_pattern, view,
-                                               name=view_name))
+                                                   name=view_name))
+         else:
+             cls.urlpatterns[cls.scope].append(url(url_pattern, view))
  
      @classmethod
      def get_url_patterns(cls):
          """
          Class method that returns the list of url pattern associated to
          the current scope.
  
          Returns:
              The list of url patterns associated to the current scope
          """
          return cls.urlpatterns[cls.scope]
  
Allow to register unnamed django views
## Code Before:

from django.conf.urls import url


class UrlsIndex(object):
    """
    Simple helper class for centralizing url patterns of a Django
    web application.

    Derived classes should override the 'scope' class attribute otherwise
    all declared patterns will be grouped under the default one.
    """

    urlpatterns = {}
    scope = 'default'

    @classmethod
    def add_url_pattern(cls, url_pattern, view, view_name):
        """
        Class method that adds an url pattern to the current scope.

        Args:
            url_pattern: regex describing a Django url
            view: function implementing the Django view
            view_name: name of the view used to reverse the url
        """
        if cls.scope not in cls.urlpatterns:
            cls.urlpatterns[cls.scope] = []
        cls.urlpatterns[cls.scope].append(url(url_pattern, view,
                                              name=view_name))

    @classmethod
    def get_url_patterns(cls):
        """
        Class method that returns the list of url pattern associated to
        the current scope.

        Returns:
            The list of url patterns associated to the current scope
        """
        return cls.urlpatterns[cls.scope]

## Instruction:
Allow to register unnamed django views
## Code After:

from django.conf.urls import url


class UrlsIndex(object):
    """
    Simple helper class for centralizing url patterns of a Django
    web application.

    Derived classes should override the 'scope' class attribute otherwise
    all declared patterns will be grouped under the default one.
    """

    urlpatterns = {}
    scope = 'default'

    @classmethod
    def add_url_pattern(cls, url_pattern, view, view_name):
        """
        Class method that adds an url pattern to the current scope.

        Args:
            url_pattern: regex describing a Django url
            view: function implementing the Django view
            view_name: name of the view used to reverse the url
        """
        if cls.scope not in cls.urlpatterns:
            cls.urlpatterns[cls.scope] = []
        if view_name:
            cls.urlpatterns[cls.scope].append(url(url_pattern, view,
                                                  name=view_name))
        else:
            cls.urlpatterns[cls.scope].append(url(url_pattern, view))

    @classmethod
    def get_url_patterns(cls):
        """
        Class method that returns the list of url pattern associated to
        the current scope.

        Returns:
            The list of url patterns associated to the current scope
        """
        return cls.urlpatterns[cls.scope]
