swh.web.common.urlsindex module

class swh.web.common.urlsindex.UrlsIndex[source]

Bases: 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.

scope = 'default'
classmethod add_url_pattern(url_pattern, view, view_name=None)[source]

Class method that adds an url pattern to the current scope.

Parameters
  • url_pattern – regex describing a Django url

  • view – function implementing the Django view

  • view_name – name of the view used to reverse the url

classmethod add_redirect_for_checksum_args(view_name, url_patterns, checksum_args)[source]

Class method that redirects to view with lowercase checksums when upper/mixed case checksums are passed as url arguments.

Parameters
  • view_name (str) – name of the view to redirect requests

  • url_patterns (List[str]) – regexps describing the view urls

  • checksum_args (List[str]) – url argument names corresponding to checksum values

classmethod get_url_patterns()[source]

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