Coverage for urls.py: 93%

1 from typing import TYPE_CHECKING

2

3 from django.conf import settings

4 from django.urls import path

5 from django.utils.text import get_valid_filename, slugify

6

7 if TYPE_CHECKING:

8 from .views import AdminBaseView

9

10

11 urlpatterns = []

12

13

14 def add_view_to_conf(view: "AdminBaseView"):

15 global urlpatterns # pylint: disable=global-statement

16

17 if not view.app_label:

18 view.app_label = settings.CUSTOM_ADMIN_DEFAULT_APP_LABEL

19 if not view.route_path:

20 view.route_path = slugify(view.view_name).lower()

21

22 if not view.route_name:

23 view.route_name = get_valid_filename(view.view_name).lower()

24

25 urlpatterns += [

26 path(

27 f"{view.app_label}/{view.route_path}",

28 view.as_view(),

29 name=view.route_name,

30 )

31 ]