swh.web.utils.url_path_converters module#

class swh.web.utils.url_path_converters.SWHIDConverter[source]#

Bases: object

Simple SWHID django url path converter to simplify view URLs registration.

When parsing URL, this simply wraps the SWHID regexp and pass the matched string as django view parameter, it is up to the view to verify the SWHID validity and returns a 400 status code if it is not.

When reversing to an URL, only SWHID objects and str are allowed.

regex = '(swh|SWH):[0-9]+:[A-Za-z]+:[0-9A-Fa-f]+(;.*)?'#
to_python(value)[source]#
to_url(value)[source]#
swh.web.utils.url_path_converters.register_url_path_converters() None[source]#

Adds SWHIDConverter to django’s url path converters.

This method is called by the root URLconf but also in every app’s URLconf that needs it to ease testing, that’s why we need to check if it is already registered before adding it.