Changeset View
Changeset View
Standalone View
Standalone View
swh/web/common/urlsindex.py
# Copyright (C) 2017-2019 The Software Heritage developers | # Copyright (C) 2017-2019 The Software Heritage developers | ||||
# See the AUTHORS file at the top-level directory of this distribution | # See the AUTHORS file at the top-level directory of this distribution | ||||
# License: GNU Affero General Public License version 3, or any later version | # License: GNU Affero General Public License version 3, or any later version | ||||
# See top-level LICENSE file for more information | # See top-level LICENSE file for more information | ||||
from typing import Dict, List | |||||
import django.urls | |||||
from django.conf.urls import url | from django.conf.urls import url | ||||
from django.shortcuts import redirect | from django.shortcuts import redirect | ||||
class UrlsIndex(object): | class UrlsIndex(object): | ||||
""" | """ | ||||
Simple helper class for centralizing url patterns of a Django | Simple helper class for centralizing url patterns of a Django | ||||
web application. | web application. | ||||
Derived classes should override the 'scope' class attribute otherwise | Derived classes should override the 'scope' class attribute otherwise | ||||
all declared patterns will be grouped under the default one. | all declared patterns will be grouped under the default one. | ||||
""" | """ | ||||
_urlpatterns = {} | _urlpatterns = {} # type: Dict[str, List[django.urls.URLPattern]] | ||||
scope = 'default' | scope = 'default' | ||||
@classmethod | @classmethod | ||||
def add_url_pattern(cls, url_pattern, view, view_name=None): | def add_url_pattern(cls, url_pattern, view, view_name=None): | ||||
""" | """ | ||||
Class method that adds an url pattern to the current scope. | Class method that adds an url pattern to the current scope. | ||||
Args: | Args: | ||||
▲ Show 20 Lines • Show All 49 Lines • Show Last 20 Lines |